authorgravatar for rpkak@noreply.codeberg.orgrpkak <rpkak@noreply.codeberg.org> 2026-08-14 11:25:26+02:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2026-10-16 21:56:09-04:00
log58baf6dcdfe5fa4a496e8048e9ba6750719c4e55
tree46ba63ca1286e194c74628315ee6908c18da9c7b
parent588aa35b3a83bf7d3db17db8187d82257bdea2c9

-femit-llvm-bc: output optimized llvm bc


1 files changed, 4 insertions(+), 14 deletions(-)

src/codegen/llvm.zig+4-14
...@@ -336,7 +336,7 @@ pub const Object = struct {...@@ -336,7 +336,7 @@ pub const Object = struct {
336 bin_path: ?[:0]const u8,336 bin_path: ?[:0]const u8,
337 asm_path: ?[:0]const u8,337 asm_path: ?[:0]const u8,
338 post_ir_path: ?[:0]const u8,338 post_ir_path: ?[:0]const u8,
339 post_bc_path: ?[]const u8,339 post_bc_path: ?[:0]const u8,
340340
341 is_debug: bool,341 is_debug: bool,
342 is_small: bool,342 is_small: bool,
...@@ -543,24 +543,13 @@ pub const Object = struct {...@@ -543,24 +543,13 @@ pub const Object = struct {
543 return diags.fail("failed to create '{s}': {t}", .{ path, err });543 return diags.fail("failed to create '{s}': {t}", .{ path, err });
544 defer file.close(io);544 defer file.close(io);
545545
546 const ptr: [*]const u8 = @ptrCast(bitcode.ptr);546 file.writeStreamingAll(io, @ptrCast(bitcode)) catch |err|
547 file.writeStreamingAll(io, ptr[0..(bitcode.len * 4)]) catch |err|
548 return diags.fail("failed to write to '{s}': {t}", .{ path, err });547 return diags.fail("failed to write to '{s}': {t}", .{ path, err });
549 }548 }
550549
551 if (options.asm_path == null and options.bin_path == null and550 if (options.asm_path == null and options.bin_path == null and
552 options.post_ir_path == null and options.post_bc_path == null) return;551 options.post_ir_path == null and options.post_bc_path == null) return;
553552
554 if (options.post_bc_path) |path| {
555 var file = Io.Dir.cwd().createFile(io, path, .{}) catch |err|
556 return diags.fail("failed to create '{s}': {t}", .{ path, err });
557 defer file.close(io);
558
559 const ptr: [*]const u8 = @ptrCast(bitcode.ptr);
560 file.writeStreamingAll(io, ptr[0..(bitcode.len * 4)]) catch |err|
561 return diags.fail("failed to write to '{s}': {t}", .{ path, err });
562 }
563
564 if (!build_options.have_llvm or !comp.config.use_lib_llvm) {553 if (!build_options.have_llvm or !comp.config.use_lib_llvm) {
565 return diags.fail("emitting without libllvm not implemented", .{});554 return diags.fail("emitting without libllvm not implemented", .{});
566 }555 }
...@@ -663,7 +652,7 @@ pub const Object = struct {...@@ -663,7 +652,7 @@ pub const Object = struct {
663 .asm_filename = null,652 .asm_filename = null,
664 .bin_filename = if (options.bin_path) |x| x.ptr else null,653 .bin_filename = if (options.bin_path) |x| x.ptr else null,
665 .llvm_ir_filename = if (options.post_ir_path) |x| x.ptr else null,654 .llvm_ir_filename = if (options.post_ir_path) |x| x.ptr else null,
666 .bitcode_filename = null,655 .bitcode_filename = if (options.post_bc_path) |x| x.ptr else null,
667656
668 // `.coverage` value is only used when `.sancov` is enabled.657 // `.coverage` value is only used when `.sancov` is enabled.
669 .sancov = options.fuzz or comp.config.san_cov_trace_pc_guard,658 .sancov = options.fuzz or comp.config.san_cov_trace_pc_guard,
...@@ -702,6 +691,7 @@ pub const Object = struct {...@@ -702,6 +691,7 @@ pub const Object = struct {
702 }691 }
703 lowered_options.bin_filename = null;692 lowered_options.bin_filename = null;
704 lowered_options.llvm_ir_filename = null;693 lowered_options.llvm_ir_filename = null;
694 lowered_options.bitcode_filename = null;
705 }695 }
706696
707 var time_report_c_str: [*:0]u8 = undefined;697 var time_report_c_str: [*:0]u8 = undefined;