public void Generate() { LLVM.InitializeNativeTarget(); LLVM.InitializeNativeAsmPrinter(); LLVM.InitializeNativeAsmParser(); Assembly assembly = _tree; _module = LLVM.ModuleCreateWithName(assembly.Name); LLVMModuleProviderRef provider = LLVM.CreateModuleProviderForExistingModule(_module); LLVMPassManagerRef fpm = LLVM.CreateFunctionPassManager(provider); LLVM.AddPromoteMemoryToRegisterPass(fpm); LLVM.AddInstructionCombiningPass(fpm); LLVM.AddReassociatePass(fpm); LLVM.AddGVNPass(fpm); LLVM.AddCFGSimplificationPass(fpm); LLVM.InitializeFunctionPassManager(fpm); GenerateAssembly(assembly, fpm); //LLVM.DumpModule(_module); IntPtr message; if (LLVM.VerifyModule(_module, LLVMVerifierFailureAction.LLVMPrintMessageAction, out message)) { string errMessage = Marshal.PtrToStringAnsi(message); throw new Exception(string.Format("Failed to verify module: \'{0}\'", errMessage)); } LLVM.DisposeMessage(message); LLVM.WriteBitcodeToFile(_module, _outFile); }
public void Initiate() { ClassSkeletons = new Dictionary<string, LLVMTypeRef>(); Context = LLVM.ContextCreate(); Module = LLVM.ModuleCreateWithNameInContext("ADefaultModuleId", Context); Builder = LLVM.CreateBuilderInContext(Context); }
public ModCompiler(DetailLogger log, SymbolTableWalker walker, LLVMContextRef context, LLVMModuleRef module, LLVMBuilderRef builder) { this.log = log; this.walker = walker; this.context = context; this.module = module; this.builder = builder; }
public static extern IntPtr PrintModuleToString(LLVMModuleRef @M);
public static extern LLVMBool LinkModules(LLVMModuleRef @Dest, LLVMModuleRef @Src, uint @Unused, out IntPtr @OutMessage);
public static extern LLVMBool ParseIRInContext(LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage);
public void AddModule(LLVMModuleRef @M) { LLVM.AddModule(this.instance, @M); }
public static extern string GetTarget(LLVMModuleRef @M);
public static extern LLVMBool TargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef @T, LLVMModuleRef @M, LLVMCodeGenFileType @codegen, out IntPtr @ErrorMessage, out LLVMMemoryBufferRef @OutMemBuf);
public static extern int WriteBitcodeToFileHandle(LLVMModuleRef @M, int @Handle);
public static string GetTarget(LLVMModuleRef M) => Marshal.PtrToStringAnsi(GetTargetAsPtr(M));
internal Module(LLVMModuleRef module) { this.instance = LLVM.CloneModule(module); }
public static string GetDataLayout(LLVMModuleRef M) => Marshal.PtrToStringAnsi(GetDataLayoutAsPtr(M));
public static extern IntPtr GetTargetAsPtr(LLVMModuleRef M);
public static extern IntPtr GetDataLayoutAsPtr(LLVMModuleRef M);
public void AddModule(LLVMModuleRef M) => LLVM.AddModule(this, M);
public bool RemoveModule(LLVMModuleRef @M, out LLVMModuleRef @OutMod, out IntPtr @OutError) { return(LLVM.RemoveModule(this.instance, @M, out @OutMod, out @OutError)); }
public static extern LLVMBool RunPassManager(LLVMPassManagerRef @PM, LLVMModuleRef @M);
public bool ParseIRInContext(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage) { return LLVM.ParseIRInContext(this, @MemBuf, out @OutM, out @OutMessage); }
public static extern void SetTarget(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Triple);
public bool LinkModules(LLVMModuleRef @Src, LLVMLinkerMode @Unused, out IntPtr @OutMessage) { return(LLVM.LinkModules(this.instance, @Src, @Unused, out @OutMessage)); }
public static extern int WriteBitcodeToFD(LLVMModuleRef @M, int @FD, int @ShouldClose, int @Unbuffered);
public static extern uint GetNamedMetadataNumOperands(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @name);
public bool Run(LLVMModuleRef M) => LLVM.RunPassManager(this, M) != 0;
public Module(string moduleId) { this.instance = LLVM.ModuleCreateWithName(moduleId); }
public bool RemoveModule(LLVMModuleRef @M, out LLVMModuleRef @OutMod, out IntPtr @OutError) { return LLVM.RemoveModule(this.instance, @M, out @OutMod, out @OutError); }
public static extern IntPtr PrintModuleToString(LLVMModuleRef M);
public static extern LLVMValueRef GetNamedGlobal(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Name);
public static extern LLVMBool TargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, IntPtr Filename, LLVMCodeGenFileType codegen, out IntPtr ErrorMessage);
public static extern void GetNamedMetadataOperands(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @name, out LLVMValueRef @Dest);
public static extern void AddNamedMetadataOperand2(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @name, LLVMMetadataRef @Val);
public static extern LLVMTypeRef GetTypeByName(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Name);
public static extern LLVMDIBuilderRef NewDIBuilder(LLVMModuleRef @m);
public static extern LLVMBool ParseBitcode(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutModule, out IntPtr @OutMessage);
public PassManager(LLVMModuleRef module) { this.instance = LLVM.CreateFunctionPassManagerForModule(module); }
public static extern LLVMBool PrintModuleToFile(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Filename, out IntPtr @ErrorMessage);
public bool RunPassManager(LLVMModuleRef @M) { return(LLVM.RunPassManager(this.instance, @M)); }
public static extern LLVMBool RemoveModuleProvider(LLVMExecutionEngineRef @EE, LLVMModuleProviderRef @MP, out LLVMModuleRef @OutMod, out IntPtr @OutError);
public bool GetBitcodeModuleInContext(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage) { return(LLVM.GetBitcodeModuleInContext(this, @MemBuf, out @OutM, out @OutMessage)); }
public static extern void SetModuleInlineAsm(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Asm);
public bool ParseIRInContext(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage) { return(LLVM.ParseIRInContext(this, @MemBuf, out @OutM, out @OutMessage)); }
public static extern LLVMBool TargetMachineEmitToFile(LLVMTargetMachineRef @T, LLVMModuleRef @M, IntPtr @Filename, LLVMCodeGenFileType @codegen, out IntPtr @ErrorMessage);
public static LLVMBool GetBitcodeModuleInContext(LLVMContextRef ContextRef, LLVMMemoryBufferRef MemBuf, out LLVMModuleRef OutM, out string OutMessage) { var retVal = GetBitcodeModuleInContext(ContextRef, MemBuf, out OutM, out IntPtr message); OutMessage = message != IntPtr.Zero && retVal.Value != 0 ? Marshal.PtrToStringAnsi(message) : null; DisposeMessage(message); return(retVal); }
public static extern LLVMBool VerifyModule(LLVMModuleRef @M, LLVMVerifierFailureAction @Action, out IntPtr @OutMessage);
public static LLVMBool TargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef T, LLVMModuleRef M, LLVMCodeGenFileType codegen, out string ErrorMessage, out LLVMMemoryBufferRef OutMemBuf) { var retVal = TargetMachineEmitToMemoryBuffer(T, M, codegen, out IntPtr message, out OutMemBuf); ErrorMessage = message != IntPtr.Zero && retVal.Value != 0 ? Marshal.PtrToStringAnsi(message) : null; DisposeMessage(message); return(retVal); }
public static extern int WriteBitcodeToFile(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Path);
public static LLVMBool CreateJITCompilerForModule(out LLVMExecutionEngineRef OutJIT, LLVMModuleRef M, uint OptLevel, out string OutError) { var retVal = CreateJITCompilerForModule(out OutJIT, M, OptLevel, out IntPtr message); OutError = message != IntPtr.Zero && retVal.Value != 0 ? Marshal.PtrToStringAnsi(message) : null; DisposeMessage(message); return(retVal); }
public static extern LLVMMemoryBufferRef WriteBitcodeToMemoryBuffer(LLVMModuleRef @M);
public static LLVMBool CreateMCJITCompilerForModule(out LLVMExecutionEngineRef OutJIT, LLVMModuleRef M, LLVMMCJITCompilerOptions Options, out string OutError) { LLVMBool retVal; IntPtr message; unsafe { retVal = CreateMCJITCompilerForModule(out OutJIT, M, &Options, sizeof(LLVMMCJITCompilerOptions), out message); } OutError = message != IntPtr.Zero && retVal.Value != 0 ? Marshal.PtrToStringAnsi(message) : null; DisposeMessage(message); return(retVal); }
public static LLVMValueRef[] GetNamedMetadataOperands(LLVMModuleRef M, string name) { uint count = GetNamedMetadataNumOperands(M, name); var buffer = new LLVMValueRef[count]; if (count > 0) { GetNamedMetadataOperands(M, name, out buffer[0]); } return buffer; }
public static LLVMBool RemoveModule(LLVMExecutionEngineRef EE, LLVMModuleRef M, out LLVMModuleRef OutMod, out string OutError) { var retVal = RemoveModule(EE, M, out OutMod, out IntPtr message); OutError = message != IntPtr.Zero && retVal.Value != 0 ? Marshal.PtrToStringAnsi(message) : null; DisposeMessage(message); return(retVal); }
public bool GetBitcodeModuleInContext(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage) { return LLVM.GetBitcodeModuleInContext(this, @MemBuf, out @OutM, out @OutMessage); }
public static extern LLVMContextRef GetModuleContext(LLVMModuleRef @M);
public void AddModule(LLVMModuleRef @M) { LLVM.AddModule(this.instance, @M); }
public Module(string moduleId, LLVMContextRef context) { this.instance = LLVM.ModuleCreateWithNameInContext(moduleId, context); }