| ... | ... | @@ -115,58 +115,6 @@ void LLVMZigOptimizeModule(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef |
| 115 | 115 | MPM->run(*module); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | | static LLVMBool LLVMZigTargetMachineEmit(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, |
| 119 | | raw_pwrite_stream &out_stream, LLVMCodeGenFileType codegen, char **err_msg) |
| 120 | | { |
| 121 | | TargetMachine* target_machine = reinterpret_cast<TargetMachine*>(targ_machine_ref); |
| 122 | | Module* module = unwrap(module_ref); |
| 123 | | TargetLibraryInfoImpl tlii(Triple(module->getTargetTriple())); |
| 124 | | |
| 125 | | legacy::PassManager pass; |
| 126 | | |
| 127 | | pass.add(new TargetLibraryInfoWrapperPass(tlii)); |
| 128 | | |
| 129 | | const DataLayout *td = target_machine->getDataLayout(); |
| 130 | | |
| 131 | | if (!td) { |
| 132 | | *err_msg = strdup("No DataLayout in TargetMachine"); |
| 133 | | return true; |
| 134 | | } |
| 135 | | module->setDataLayout(*td); |
| 136 | | |
| 137 | | |
| 138 | | TargetMachine::CodeGenFileType ft; |
| 139 | | switch (codegen) { |
| 140 | | case LLVMAssemblyFile: |
| 141 | | ft = TargetMachine::CGFT_AssemblyFile; |
| 142 | | break; |
| 143 | | default: |
| 144 | | ft = TargetMachine::CGFT_ObjectFile; |
| 145 | | break; |
| 146 | | } |
| 147 | | if (target_machine->addPassesToEmitFile(pass, out_stream, ft)) { |
| 148 | | *err_msg = strdup("TargetMachine can't emit a file of this type"); |
| 149 | | return true; |
| 150 | | } |
| 151 | | |
| 152 | | pass.run(*module); |
| 153 | | |
| 154 | | out_stream.flush(); |
| 155 | | return false; |
| 156 | | } |
| 157 | | |
| 158 | | LLVMBool LLVMZigTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, |
| 159 | | const char* filename, LLVMCodeGenFileType codegen, char** err_msg) |
| 160 | | { |
| 161 | | std::error_code error_code; |
| 162 | | raw_fd_ostream dest(filename, error_code, sys::fs::F_None); |
| 163 | | if (error_code) { |
| 164 | | *err_msg = strdup(error_code.message().c_str()); |
| 165 | | return true; |
| 166 | | } |
| 167 | | return LLVMZigTargetMachineEmit(targ_machine_ref, module_ref, dest, codegen, err_msg); |
| 168 | | } |
| 169 | | |
| 170 | 118 | LLVMValueRef LLVMZigBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *Args, |
| 171 | 119 | unsigned NumArgs, unsigned CC, const char *Name) |
| 172 | 120 | { |