/// <summary>Generate code for the target machine from a module</summary> /// <param name="module"><see cref="NativeModule"/> to generate the code from</param> /// <param name="path">Path to the output file</param> /// <param name="fileType">Type of file to emit</param> public void EmitToFile(NativeModule module, string path, CodeGenFileType fileType) { if (module == null) { throw new ArgumentNullException(nameof(module)); } if (string.IsNullOrWhiteSpace(path)) { throw new ArgumentException("Null or empty paths are not valid", nameof(path)); } if (module.TargetTriple != null && Triple != module.TargetTriple) { throw new ArgumentException("Triple specified for the module doesn't match target machine", nameof(module)); } var status = NativeMethods.TargetMachineEmitToFile(TargetMachineHandle , module.ModuleHandle , path , ( LLVMCodeGenFileType )fileType , out string errTxt ); if (status.Failed) { throw new InternalCodeGeneratorException(errTxt); } }
public MemoryBuffer EmitToBuffer(NativeModule module, CodeGenFileType fileType) { if (module == null) { throw new ArgumentNullException(nameof(module)); } if (module.TargetTriple != null && Triple != module.TargetTriple) { throw new ArgumentException("Triple specified for the module doesn't match target machine", nameof(module)); } var status = NativeMethods.TargetMachineEmitToMemoryBuffer(TargetMachineHandle , module.ModuleHandle , ( LLVMCodeGenFileType )fileType , out string errTxt , out LLVMMemoryBufferRef bufferHandle ); if (status.Failed) { throw new InternalCodeGeneratorException(errTxt); } return(new MemoryBuffer(bufferHandle)); }
internal NativeModule GetModuleFor(LLVMModuleRef moduleRef) { if (moduleRef.Pointer == IntPtr.Zero) { throw new ArgumentNullException(nameof(moduleRef)); } var hModuleContext = NativeMethods.GetModuleContext(moduleRef); if (hModuleContext.Pointer != ContextHandle.Pointer) { throw new ArgumentException("Incorrect context for module"); } if (!ModuleCache.TryGetValue(moduleRef.Pointer, out NativeModule retVal)) { retVal = new NativeModule(moduleRef); } return(retVal); }
internal void RemoveModule(NativeModule module) { ModuleCache.Remove(module.ModuleHandle.Pointer); }
internal void AddModule(NativeModule module) { ModuleCache.Add(module.ModuleHandle.Pointer, module); }
internal Comdat(NativeModule module, LLVMComdatRef comdatRef) { Module = module; ComdatHandle = comdatRef; }
internal ComdatCollection(NativeModule module) { Module = module; NativeMethods.ModuleEnumerateComdats(Module.ModuleHandle, AddComdat); }