| ... | @@ -86,6 +86,9 @@ next_stack_offset: u32 = 0, | ... | @@ -86,6 +86,9 @@ next_stack_offset: u32 = 0, |
| 86 | /// Debug field, used to find bugs in the compiler. | 86 | /// Debug field, used to find bugs in the compiler. |
| 87 | air_bookkeeping: @TypeOf(air_bookkeeping_init) = air_bookkeeping_init, | 87 | air_bookkeeping: @TypeOf(air_bookkeeping_init) = air_bookkeeping_init, |
| 88 | | 88 | |
| | 89 | /// For mir debug info, maps a mir index to a air index |
| | 90 | mir_to_air_map: if (builtin.mode == .Debug) std.AutoHashMap(Mir.Inst.Index, Air.Inst.Index) else void, |
| | 91 | |
| 89 | const air_bookkeeping_init = if (std.debug.runtime_safety) @as(usize, 0) else {}; | 92 | const air_bookkeeping_init = if (std.debug.runtime_safety) @as(usize, 0) else {}; |
| 90 | | 93 | |
| 91 | pub const MCValue = union(enum) { | 94 | pub const MCValue = union(enum) { |
| ... | @@ -272,12 +275,14 @@ pub fn generate( | ... | @@ -272,12 +275,14 @@ pub fn generate( |
| 272 | .stack_align = undefined, | 275 | .stack_align = undefined, |
| 273 | .end_di_line = module_fn.rbrace_line, | 276 | .end_di_line = module_fn.rbrace_line, |
| 274 | .end_di_column = module_fn.rbrace_column, | 277 | .end_di_column = module_fn.rbrace_column, |
| | 278 | .mir_to_air_map = if (builtin.mode == .Debug) std.AutoHashMap(Mir.Inst.Index, Air.Inst.Index).init(bin_file.allocator) else {}, |
| 275 | }; | 279 | }; |
| 276 | defer function.stack.deinit(bin_file.allocator); | 280 | defer function.stack.deinit(bin_file.allocator); |
| 277 | defer function.blocks.deinit(bin_file.allocator); | 281 | defer function.blocks.deinit(bin_file.allocator); |
| 278 | defer function.exitlude_jump_relocs.deinit(bin_file.allocator); | 282 | defer function.exitlude_jump_relocs.deinit(bin_file.allocator); |
| 279 | defer function.mir_instructions.deinit(bin_file.allocator); | 283 | defer function.mir_instructions.deinit(bin_file.allocator); |
| 280 | defer function.mir_extra.deinit(bin_file.allocator); | 284 | defer function.mir_extra.deinit(bin_file.allocator); |
| | 285 | defer if (builtin.mode == .Debug) function.mir_to_air_map.deinit(); |
| 281 | | 286 | |
| 282 | var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) { | 287 | var call_info = function.resolveCallingConventionValues(fn_type) catch |err| switch (err) { |
| 283 | error.CodegenFail => return FnResult{ .fail = function.err_msg.? }, | 288 | error.CodegenFail => return FnResult{ .fail = function.err_msg.? }, |
| ... | @@ -323,8 +328,8 @@ pub fn generate( | ... | @@ -323,8 +328,8 @@ pub fn generate( |
| 323 | const w = std.io.getStdErr().writer(); | 328 | const w = std.io.getStdErr().writer(); |
| 324 | w.print("# Begin Function MIR: {s}:\n", .{module_fn.owner_decl.name}) catch {}; | 329 | w.print("# Begin Function MIR: {s}:\n", .{module_fn.owner_decl.name}) catch {}; |
| 325 | const print = @import("./PrintMir.zig"){ .mir = mir }; | 330 | const print = @import("./PrintMir.zig"){ .mir = mir }; |
| 326 | print.printMir(w) catch {}; // we don't care if the debug printing fails | 331 | print.printMir(w, function.mir_to_air_map, air) catch {}; // we don't care if the debug printing fails |
| 327 | w.print("# End Function MIR: {s}:\n\n", .{module_fn.owner_decl.name}) catch {}; | 332 | w.print("# End Function MIR: {s}\n\n", .{module_fn.owner_decl.name}) catch {}; |
| 328 | } | 333 | } |
| 329 | | 334 | |
| 330 | if (function.err_msg) |em| { | 335 | if (function.err_msg) |em| { |
| ... | @@ -525,6 +530,9 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { | ... | @@ -525,6 +530,9 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void { |
| 525 | for (body) |inst| { | 530 | for (body) |inst| { |
| 526 | const old_air_bookkeeping = self.air_bookkeeping; | 531 | const old_air_bookkeeping = self.air_bookkeeping; |
| 527 | try self.ensureProcessDeathCapacity(Liveness.bpi); | 532 | try self.ensureProcessDeathCapacity(Liveness.bpi); |
| | 533 | if (builtin.mode == .Debug) { |
| | 534 | try self.mir_to_air_map.put(@intCast(u32, self.mir_instructions.len), inst); |
| | 535 | } |
| 528 | | 536 | |
| 529 | switch (air_tags[inst]) { | 537 | switch (air_tags[inst]) { |
| 530 | // zig fmt: off | 538 | // zig fmt: off |