示例#1
0
        /// <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);
            }
        }
示例#2
0
        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));
        }
示例#3
0
        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);
        }
示例#4
0
 internal void RemoveModule(NativeModule module)
 {
     ModuleCache.Remove(module.ModuleHandle.Pointer);
 }
示例#5
0
 internal void AddModule(NativeModule module)
 {
     ModuleCache.Add(module.ModuleHandle.Pointer, module);
 }
示例#6
0
 internal Comdat(NativeModule module, LLVMComdatRef comdatRef)
 {
     Module       = module;
     ComdatHandle = comdatRef;
 }
示例#7
0
 internal ComdatCollection(NativeModule module)
 {
     Module = module;
     NativeMethods.ModuleEnumerateComdats(Module.ModuleHandle, AddComdat);
 }