Esempio n. 1
0
        /// <summary>Initializes a new instance of the <see cref="ComdatCollection"/> class for a module</summary>
        /// <param name="module">Module the comdats are enumerated from</param>
        internal ComdatCollection(BitcodeModule module)
        {
            module.ValidateNotNull(nameof(module));

            Module = module;
            LibLLVMModuleEnumerateComdats(Module.ModuleHandle, AddComdat);
        }
Esempio n. 2
0
        /// <summary>Link another module into this one</summary>
        /// <param name="otherModule">module to link into this one</param>
        /// <remarks>
        /// <note type="warning">
        /// <paramref name="otherModule"/> is destroyed by this process and no longer usable
        /// when this method returns.
        /// </note>
        /// </remarks>
        public void Link(BitcodeModule otherModule)
        {
            ThrowIfDisposed( );

            if (otherModule.Context != Context)
            {
                throw new ArgumentException( );
            }

            if (ModuleHandle.Link(otherModule.ModuleHandle))
            {
                throw new InternalCodeGeneratorException( );
            }

            Context.RemoveModule(otherModule);
            otherModule.Detach( ).Dispose( );
        }
Esempio n. 3
0
        /// <summary>Generate code for the target machine from a module</summary>
        /// <param name="module"><see cref="BitcodeModule"/> 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(BitcodeModule module, string path, CodeGenFileType fileType)
        {
            module.ValidateNotNull(nameof(module));
            path.ValidateNotNullOrWhiteSpace(nameof(path));
            fileType.ValidateDefined(nameof(path));

            if (module.TargetTriple != null && Triple != module.TargetTriple)
            {
                throw new ArgumentException(Resources.Triple_specified_for_the_module_doesn_t_match_target_machine, nameof(module));
            }

            var status = LLVMTargetMachineEmitToFile(TargetMachineHandle
                                                     , module.ModuleHandle
                                                     , path
                                                     , ( LLVMCodeGenFileType )fileType
                                                     , out string errTxt
                                                     );

            if (status.Failed)
            {
                throw new InternalCodeGeneratorException(errTxt);
            }
        }
Esempio n. 4
0
        /// <summary>Emits the module for the target machine to a <see cref="MemoryBuffer"/></summary>
        /// <param name="module">Module to emit to the buffer</param>
        /// <param name="fileType">Type of file to generate into the buffer</param>
        /// <returns><see cref="MemoryBuffer"/> containing the generated code</returns>
        /// <remarks>
        /// The <see cref="BitcodeModule.TargetTriple"/> must match the <see cref="Triple"/> for this
        /// target.
        /// </remarks>
        public MemoryBuffer EmitToBuffer(BitcodeModule module, CodeGenFileType fileType)
        {
            module.ValidateNotNull(nameof(module));
            fileType.ValidateDefined(nameof(fileType));

            if (module.TargetTriple != null && Triple != module.TargetTriple)
            {
                throw new ArgumentException(Resources.Triple_specified_for_the_module_doesn_t_match_target_machine, nameof(module));
            }

            var status = LLVMTargetMachineEmitToMemoryBuffer(TargetMachineHandle
                                                             , module.ModuleHandle
                                                             , ( LLVMCodeGenFileType )fileType
                                                             , out string errTxt
                                                             , out LLVMMemoryBufferRef bufferHandle
                                                             );

            if (status.Failed)
            {
                throw new InternalCodeGeneratorException(errTxt);
            }

            return(new MemoryBuffer(bufferHandle));
        }