aboutsummaryrefslogtreecommitdiff
path: root/src/zig_llvm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/zig_llvm.cpp')
-rw-r--r--src/zig_llvm.cpp36
1 files changed, 23 insertions, 13 deletions
diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp
index 0e1a067bc6..086c1d6f96 100644
--- a/src/zig_llvm.cpp
+++ b/src/zig_llvm.cpp
@@ -77,7 +77,7 @@ static const bool assertions_on = false;
#endif
bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref,
- const char *filename, LLVMCodeGenFileType file_type, char **error_message, bool is_debug)
+ const char *filename, ZigLLVM_EmitOutputType output_type, char **error_message, bool is_debug)
{
std::error_code EC;
raw_fd_ostream dest(filename, EC, sys::fs::F_None);
@@ -135,18 +135,24 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
MPM.add(createTargetTransformInfoWrapperPass(target_machine->getTargetIRAnalysis()));
PMBuilder->populateModulePassManager(MPM);
+ // Set output pass.
TargetMachine::CodeGenFileType ft;
- switch (file_type) {
- case LLVMAssemblyFile:
- ft = TargetMachine::CGFT_AssemblyFile;
- break;
- default:
- ft = TargetMachine::CGFT_ObjectFile;
- break;
- }
- if (target_machine->addPassesToEmitFile(MPM, dest, ft)) {
- *error_message = strdup("TargetMachine can't emit a file of this type");
- return true;
+ if (output_type != ZigLLVM_EmitLLVMIr) {
+ switch (output_type) {
+ case ZigLLVM_EmitAssembly:
+ ft = TargetMachine::CGFT_AssemblyFile;
+ break;
+ case ZigLLVM_EmitBinary:
+ ft = TargetMachine::CGFT_ObjectFile;
+ break;
+ default:
+ abort();
+ }
+
+ if (target_machine->addPassesToEmitFile(MPM, dest, ft)) {
+ *error_message = strdup("TargetMachine can't emit a file of this type");
+ return true;
+ }
}
// run per function optimization passes
@@ -158,7 +164,11 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
MPM.run(*module);
- dest.close();
+ if (output_type == ZigLLVM_EmitLLVMIr) {
+ if (LLVMPrintModuleToFile(module_ref, filename, error_message)) {
+ return true;
+ }
+ }
return false;
}