예제 #1
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);
            }
        }
예제 #2
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));
        }