aboutsummaryrefslogtreecommitdiff
path: root/src/zig_llvm.cpp
diff options
context:
space:
mode:
authorMarc Tiehuis <marctiehuis@gmail.com>2017-11-04 02:09:33 +1300
committerAndrew Kelley <superjoe30@gmail.com>2017-11-03 09:09:33 -0400
commit795703a39cfe0d59fcd9fff7a605a7efe9c5bdb2 (patch)
tree3a0883c024420f9cd7ddee0d54cbd223a3775a32 /src/zig_llvm.cpp
parenta31b23c46ba2a8c28df01adc1aa0b4d878b9a5cf (diff)
downloadzig-795703a39cfe0d59fcd9fff7a605a7efe9c5bdb2.tar.gz
zig-795703a39cfe0d59fcd9fff7a605a7efe9c5bdb2.zip
Add emit command-line option (#580)
Add emit command-line option
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;
}