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