aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-03-16 01:32:43 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-03-17 01:57:14 -0400
commitcfcd6698cd9385938df27a2052c2309229171e4f (patch)
tree3ac0ce351109462a9f0e96c5f06fe94737be48a8 /src/codegen/llvm.zig
parent4ec299007a6a183edddfcb0505a9c1501da7ad0c (diff)
downloadzig-cfcd6698cd9385938df27a2052c2309229171e4f.tar.gz
zig-cfcd6698cd9385938df27a2052c2309229171e4f.zip
main: add debug option to dump unoptimized llvm ir
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig31
1 files changed, 29 insertions, 2 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 85a82f4eda..11fc44747e 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -751,8 +751,35 @@ pub const Object = struct {
dib.finalize();
}
- if (comp.verbose_llvm_ir) {
- self.llvm_module.dump();
+ if (comp.verbose_llvm_ir) |path| {
+ if (std.mem.eql(u8, path, "-")) {
+ self.llvm_module.dump();
+ } else {
+ const path_z = try comp.gpa.dupeZ(u8, path);
+ defer comp.gpa.free(path_z);
+
+ var error_message: [*:0]const u8 = undefined;
+
+ if (self.llvm_module.printModuleToFile(path_z, &error_message).toBool()) {
+ defer llvm.disposeMessage(error_message);
+
+ log.err("dump LLVM module failed ir={s}: {s}", .{
+ path, error_message,
+ });
+ }
+ }
+ }
+
+ if (comp.verbose_llvm_bc) |path| {
+ const path_z = try comp.gpa.dupeZ(u8, path);
+ defer comp.gpa.free(path_z);
+
+ const error_code = self.llvm_module.writeBitcodeToFile(path_z);
+ if (error_code != 0) {
+ log.err("dump LLVM module failed bc={s}: {d}", .{
+ path, error_code,
+ });
+ }
}
var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa);