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);
        }
Beispiel #2
0
 public void Initiate()
 {
     ClassSkeletons = new Dictionary<string, LLVMTypeRef>();
     Context = LLVM.ContextCreate();
     Module = LLVM.ModuleCreateWithNameInContext("ADefaultModuleId", Context);
     Builder = LLVM.CreateBuilderInContext(Context);
 }
Beispiel #3
0
 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;
 }
Beispiel #4
0
 public static extern IntPtr PrintModuleToString(LLVMModuleRef @M);
Beispiel #5
0
 public static extern LLVMBool LinkModules(LLVMModuleRef @Dest, LLVMModuleRef @Src, uint @Unused, out IntPtr @OutMessage);
Beispiel #6
0
 public static extern LLVMBool ParseIRInContext(LLVMContextRef @ContextRef, LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage);
Beispiel #7
0
 public void AddModule(LLVMModuleRef @M)
 {
     LLVM.AddModule(this.instance, @M);
 }
Beispiel #8
0
 public static extern string GetTarget(LLVMModuleRef @M);
Beispiel #9
0
 public static extern LLVMBool TargetMachineEmitToMemoryBuffer(LLVMTargetMachineRef @T, LLVMModuleRef @M, LLVMCodeGenFileType @codegen, out IntPtr @ErrorMessage, out LLVMMemoryBufferRef @OutMemBuf);
Beispiel #10
0
 public static extern int WriteBitcodeToFileHandle(LLVMModuleRef @M, int @Handle);
Beispiel #11
0
 public static string GetTarget(LLVMModuleRef M) => Marshal.PtrToStringAnsi(GetTargetAsPtr(M));
Beispiel #12
0
 internal Module(LLVMModuleRef module)
 {
     this.instance = LLVM.CloneModule(module);
 }
Beispiel #13
0
 public static string GetDataLayout(LLVMModuleRef M) => Marshal.PtrToStringAnsi(GetDataLayoutAsPtr(M));
Beispiel #14
0
 public static extern IntPtr GetTargetAsPtr(LLVMModuleRef M);
Beispiel #15
0
 public static extern IntPtr GetDataLayoutAsPtr(LLVMModuleRef M);
 public void AddModule(LLVMModuleRef M) => LLVM.AddModule(this, M);
Beispiel #17
0
 public bool RemoveModule(LLVMModuleRef @M, out LLVMModuleRef @OutMod, out IntPtr @OutError)
 {
     return(LLVM.RemoveModule(this.instance, @M, out @OutMod, out @OutError));
 }
Beispiel #18
0
 public static extern LLVMBool RunPassManager(LLVMPassManagerRef @PM, LLVMModuleRef @M);
Beispiel #19
0
 public bool ParseIRInContext(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage)
 {
     return LLVM.ParseIRInContext(this, @MemBuf, out @OutM, out @OutMessage);
 }
Beispiel #20
0
 public static extern void SetTarget(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Triple);
Beispiel #21
0
 public bool LinkModules(LLVMModuleRef @Src, LLVMLinkerMode @Unused, out IntPtr @OutMessage)
 {
     return(LLVM.LinkModules(this.instance, @Src, @Unused, out @OutMessage));
 }
Beispiel #22
0
 public static extern int WriteBitcodeToFD(LLVMModuleRef @M, int @FD, int @ShouldClose, int @Unbuffered);
Beispiel #23
0
 public static extern uint GetNamedMetadataNumOperands(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @name);
 public bool Run(LLVMModuleRef M) => LLVM.RunPassManager(this, M) != 0;
Beispiel #25
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);
 }
Beispiel #27
0
 public static extern IntPtr PrintModuleToString(LLVMModuleRef M);
Beispiel #28
0
 public static extern LLVMValueRef GetNamedGlobal(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Name);
Beispiel #29
0
 public static extern LLVMBool TargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M, IntPtr Filename, LLVMCodeGenFileType codegen, out IntPtr ErrorMessage);
Beispiel #30
0
 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);
Beispiel #32
0
 public static extern LLVMTypeRef GetTypeByName(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Name);
 public static extern LLVMDIBuilderRef NewDIBuilder(LLVMModuleRef @m);
Beispiel #34
0
 public static extern LLVMBool ParseBitcode(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutModule, out IntPtr @OutMessage);
Beispiel #35
0
 public PassManager(LLVMModuleRef module)
 {
     this.instance = LLVM.CreateFunctionPassManagerForModule(module);
 }
Beispiel #36
0
 public static extern LLVMBool PrintModuleToFile(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Filename, out IntPtr @ErrorMessage);
Beispiel #37
0
 public bool RunPassManager(LLVMModuleRef @M)
 {
     return(LLVM.RunPassManager(this.instance, @M));
 }
Beispiel #38
0
 public static extern LLVMBool RemoveModuleProvider(LLVMExecutionEngineRef @EE, LLVMModuleProviderRef @MP, out LLVMModuleRef @OutMod, out IntPtr @OutError);
Beispiel #39
0
 public bool GetBitcodeModuleInContext(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage)
 {
     return(LLVM.GetBitcodeModuleInContext(this, @MemBuf, out @OutM, out @OutMessage));
 }
Beispiel #40
0
 public static extern void SetModuleInlineAsm(LLVMModuleRef @M, [MarshalAs(UnmanagedType.LPStr)] string @Asm);
Beispiel #41
0
 public bool ParseIRInContext(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage)
 {
     return(LLVM.ParseIRInContext(this, @MemBuf, out @OutM, out @OutMessage));
 }
Beispiel #42
0
 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);
        }
Beispiel #44
0
 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);
        }
Beispiel #46
0
 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);
        }
Beispiel #48
0
 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);
        }
Beispiel #50
0
        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);
        }
Beispiel #52
0
 public bool GetBitcodeModuleInContext(LLVMMemoryBufferRef @MemBuf, out LLVMModuleRef @OutM, out IntPtr @OutMessage)
 {
     return LLVM.GetBitcodeModuleInContext(this, @MemBuf, out @OutM, out @OutMessage);
 }
Beispiel #53
0
 public static extern LLVMContextRef GetModuleContext(LLVMModuleRef @M);
 public void AddModule(LLVMModuleRef @M)
 {
     LLVM.AddModule(this.instance, @M);
 }
Beispiel #55
0
 public Module(string moduleId, LLVMContextRef context)
 {
     this.instance = LLVM.ModuleCreateWithNameInContext(moduleId, context);
 }