diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-07-23 02:22:23 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-07-23 02:22:23 -0400 |
| commit | e3fe3acce0fc65a7f0c7227085456e8d167ed2a7 (patch) | |
| tree | 17b5feeab6232ed6bbeff5f5ea7026c6b1ec2235 /src/zig_llvm.cpp | |
| parent | a38a6914875ab3bda02fb1732467228ef876074e (diff) | |
| parent | 80ba9f060d81e8c5674acb4eb07c833d26121462 (diff) | |
| download | zig-e3fe3acce0fc65a7f0c7227085456e8d167ed2a7.tar.gz zig-e3fe3acce0fc65a7f0c7227085456e8d167ed2a7.zip | |
Merge pull request #9440 from ziglang/emit-bc
add -femit-llvm-bc CLI option and implement it, and improve -fcompiler-rt support
Diffstat (limited to 'src/zig_llvm.cpp')
| -rw-r--r-- | src/zig_llvm.cpp | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 6d40f4089a..d5d6f9f670 100644 --- a/src/zig_llvm.cpp +++ b/src/zig_llvm.cpp @@ -229,12 +229,14 @@ struct TimeTracerRAII { bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMModuleRef module_ref, char **error_message, bool is_debug, bool is_small, bool time_report, bool tsan, bool lto, - const char *asm_filename, const char *bin_filename, const char *llvm_ir_filename) + const char *asm_filename, const char *bin_filename, + const char *llvm_ir_filename, const char *bitcode_filename) { TimePassesIsEnabled = time_report; raw_fd_ostream *dest_asm_ptr = nullptr; raw_fd_ostream *dest_bin_ptr = nullptr; + raw_fd_ostream *dest_bitcode_ptr = nullptr; if (asm_filename) { std::error_code EC; @@ -252,9 +254,19 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM return true; } } + if (bitcode_filename) { + std::error_code EC; + dest_bitcode_ptr = new(std::nothrow) raw_fd_ostream(bitcode_filename, EC, sys::fs::F_None); + if (EC) { + *error_message = strdup((const char *)StringRef(EC.message()).bytes_begin()); + return true; + } + } std::unique_ptr<raw_fd_ostream> dest_asm(dest_asm_ptr), - dest_bin(dest_bin_ptr); + dest_bin(dest_bin_ptr), + dest_bitcode(dest_bitcode_ptr); + auto PID = sys::Process::getProcessId(); std::string ProcName = "zig-"; @@ -389,6 +401,9 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM if (dest_bin && lto) { WriteBitcodeToFile(module, *dest_bin); } + if (dest_bitcode) { + WriteBitcodeToFile(module, *dest_bitcode); + } if (time_report) { TimerGroup::printAll(errs()); |
