aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorVeikka Tuominen <git@vexu.eu>2022-06-09 17:54:32 +0300
committerVeikka Tuominen <git@vexu.eu>2022-06-11 11:02:56 +0300
commit0f820d0bdf98b3f8429a9cf2f1b405c2c0a4d958 (patch)
treed8793ad6cd0258eb704d35fc536636aac3fa45fc /src/codegen
parent002df65b6ec55684d6bc6790ae7b0c0f4abb1375 (diff)
downloadzig-0f820d0bdf98b3f8429a9cf2f1b405c2c0a4d958.tar.gz
zig-0f820d0bdf98b3f8429a9cf2f1b405c2c0a4d958.zip
stage2: improve debugging tools
llvm: dump failed module when -femit-llvm-ir set print_air: * print fully qualified name * use Type.fmt and Value.fmtValue, fmtDebug is useless TypedValue * handle anon structs and tuples * fix bugs
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig19
-rw-r--r--src/codegen/llvm/bindings.zig3
2 files changed, 15 insertions, 7 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 19a6917be4..8031c4635e 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -599,6 +599,13 @@ pub const Object = struct {
self.llvm_module.dump();
}
+ var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa);
+ defer arena_allocator.deinit();
+ const arena = arena_allocator.allocator();
+
+ const mod = comp.bin_file.options.module.?;
+ const cache_dir = mod.zig_cache_artifact_directory;
+
if (std.debug.runtime_safety) {
var error_message: [*:0]const u8 = undefined;
// verifyModule always allocs the error_message even if there is no error
@@ -606,17 +613,15 @@ pub const Object = struct {
if (self.llvm_module.verify(.ReturnStatus, &error_message).toBool()) {
std.debug.print("\n{s}\n", .{error_message});
+
+ if (try locPath(arena, comp.emit_llvm_ir, cache_dir)) |emit_llvm_ir_path| {
+ _ = self.llvm_module.printModuleToFile(emit_llvm_ir_path, &error_message);
+ }
+
@panic("LLVM module verification failed");
}
}
- var arena_allocator = std.heap.ArenaAllocator.init(comp.gpa);
- defer arena_allocator.deinit();
- const arena = arena_allocator.allocator();
-
- const mod = comp.bin_file.options.module.?;
- const cache_dir = mod.zig_cache_artifact_directory;
-
var emit_bin_path: ?[*:0]const u8 = if (comp.bin_file.options.emit) |emit|
try emit.basenamePath(arena, try arena.dupeZ(u8, comp.bin_file.intermediary_basename.?))
else
diff --git a/src/codegen/llvm/bindings.zig b/src/codegen/llvm/bindings.zig
index ca748d3ce3..671014ba3b 100644
--- a/src/codegen/llvm/bindings.zig
+++ b/src/codegen/llvm/bindings.zig
@@ -390,6 +390,9 @@ pub const Module = opaque {
pub const setModuleInlineAsm2 = LLVMSetModuleInlineAsm2;
extern fn LLVMSetModuleInlineAsm2(M: *const Module, Asm: [*]const u8, Len: usize) void;
+
+ pub const printModuleToFile = LLVMPrintModuleToFile;
+ extern fn LLVMPrintModuleToFile(M: *const Module, Filename: [*:0]const u8, ErrorMessage: *[*:0]const u8) Bool;
};
pub const lookupIntrinsicID = LLVMLookupIntrinsicID;