diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-06-09 17:54:32 +0300 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-06-11 11:02:56 +0300 |
| commit | 0f820d0bdf98b3f8429a9cf2f1b405c2c0a4d958 (patch) | |
| tree | d8793ad6cd0258eb704d35fc536636aac3fa45fc /src/codegen/llvm.zig | |
| parent | 002df65b6ec55684d6bc6790ae7b0c0f4abb1375 (diff) | |
| download | zig-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/llvm.zig')
| -rw-r--r-- | src/codegen/llvm.zig | 19 |
1 files changed, 12 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 |
