aboutsummaryrefslogtreecommitdiff
path: root/src/stage1/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-07-23 02:22:23 -0400
committerGitHub <noreply@github.com>2021-07-23 02:22:23 -0400
commite3fe3acce0fc65a7f0c7227085456e8d167ed2a7 (patch)
tree17b5feeab6232ed6bbeff5f5ea7026c6b1ec2235 /src/stage1/codegen.cpp
parenta38a6914875ab3bda02fb1732467228ef876074e (diff)
parent80ba9f060d81e8c5674acb4eb07c833d26121462 (diff)
downloadzig-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/stage1/codegen.cpp')
-rw-r--r--src/stage1/codegen.cpp33
1 files changed, 27 insertions, 6 deletions
diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp
index 9ab0e269a2..67d787427f 100644
--- a/src/stage1/codegen.cpp
+++ b/src/stage1/codegen.cpp
@@ -8506,19 +8506,22 @@ static void zig_llvm_emit_output(CodeGen *g) {
const char *asm_filename = nullptr;
const char *bin_filename = nullptr;
const char *llvm_ir_filename = nullptr;
+ const char *bitcode_filename = nullptr;
if (buf_len(&g->o_file_output_path) != 0) bin_filename = buf_ptr(&g->o_file_output_path);
if (buf_len(&g->asm_file_output_path) != 0) asm_filename = buf_ptr(&g->asm_file_output_path);
if (buf_len(&g->llvm_ir_file_output_path) != 0) llvm_ir_filename = buf_ptr(&g->llvm_ir_file_output_path);
+ if (buf_len(&g->bitcode_file_output_path) != 0) bitcode_filename = buf_ptr(&g->bitcode_file_output_path);
- // Unfortunately, LLVM shits the bed when we ask for both binary and assembly. So we call the entire
- // pipeline multiple times if this is requested.
+ // Unfortunately, LLVM shits the bed when we ask for both binary and assembly.
+ // So we call the entire pipeline multiple times if this is requested.
if (asm_filename != nullptr && bin_filename != nullptr) {
if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, &err_msg,
g->build_mode == BuildModeDebug, is_small, g->enable_time_report, g->tsan_enabled,
- g->have_lto, nullptr, bin_filename, llvm_ir_filename))
+ g->have_lto, nullptr, bin_filename, llvm_ir_filename, nullptr))
{
- fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);
+ fprintf(stderr, "LLVM failed to emit bin=%s, ir=%s: %s\n",
+ bin_filename, llvm_ir_filename, err_msg);
exit(1);
}
bin_filename = nullptr;
@@ -8527,9 +8530,11 @@ static void zig_llvm_emit_output(CodeGen *g) {
if (ZigLLVMTargetMachineEmitToFile(g->target_machine, g->module, &err_msg,
g->build_mode == BuildModeDebug, is_small, g->enable_time_report, g->tsan_enabled,
- g->have_lto, asm_filename, bin_filename, llvm_ir_filename))
+ g->have_lto, asm_filename, bin_filename, llvm_ir_filename, bitcode_filename))
{
- fprintf(stderr, "LLVM failed to emit file: %s\n", err_msg);
+ fprintf(stderr, "LLVM failed to emit asm=%s, bin=%s, ir=%s, bc=%s: %s\n",
+ asm_filename, bin_filename, llvm_ir_filename, bitcode_filename,
+ err_msg);
exit(1);
}
@@ -9537,6 +9542,22 @@ static void gen_root_source(CodeGen *g) {
g->panic_fn = panic_fn_val->data.x_ptr.data.fn.fn_entry;
assert(g->panic_fn != nullptr);
+ if (g->include_compiler_rt) {
+ Buf *import_target_path;
+ Buf full_path = BUF_INIT;
+ ZigType *compiler_rt_import;
+ if ((err = analyze_import(g, std_import, buf_create_from_str("./special/compiler_rt.zig"),
+ &compiler_rt_import, &import_target_path, &full_path)))
+ {
+ if (err == ErrorFileNotFound) {
+ fprintf(stderr, "unable to find '%s'", buf_ptr(import_target_path));
+ } else {
+ fprintf(stderr, "unable to open '%s': %s\n", buf_ptr(&full_path), err_str(err));
+ }
+ exit(1);
+ }
+ }
+
if (!g->error_during_imports) {
semantic_analyze(g);
}