authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-11-03 12:11:06-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-11-04 01:54:12-04:00
log7b1a644d6ee50740196328bd8f7b1a46ac46b4d2
tree2fc53e03788e484d056263166a5c461977905c8b
parent46d3e5bb04393c6be196b10e262d122e008403aa

print_zir: fix more crashes during printing


2 files changed, 7 insertions(+), 9 deletions(-)

src/main.zig+1
...@@ -6492,6 +6492,7 @@ pub fn cmdDumpZir(...@@ -6492,6 +6492,7 @@ pub fn cmdDumpZir(
6492 .mod = undefined,6492 .mod = undefined,
6493 .root_decl = .none,6493 .root_decl = .none,
6494 };6494 };
6495 defer file.zir.deinit(gpa);
64956496
6496 {6497 {
6497 const instruction_bytes = file.zir.instructions.len *6498 const instruction_bytes = file.zir.instructions.len *
src/print_zir.zig+6-9
...@@ -2456,20 +2456,15 @@ const Writer = struct {...@@ -2456,20 +2456,15 @@ const Writer = struct {
2456 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;2456 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
24572457
2458 try self.writeInstRef(stream, inst_data.operand);2458 try self.writeInstRef(stream, inst_data.operand);
2459
2459 try stream.writeAll(")");2460 try stream.writeAll(")");
2460 }2461 }
24612462
2462 fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {2463 fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
2463 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;2464 const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;
24642465
2465 if (inst_data.block != .none) {2466 try self.writeInstRef(stream, inst_data.block);
2466 try self.writeInstRef(stream, inst_data.block);2467 try self.writeInstRef(stream, inst_data.operand);
2467 }
2468
2469 if (inst_data.operand != .none) {
2470 if (inst_data.block != .none) try stream.writeAll(", ");
2471 try self.writeInstRef(stream, inst_data.operand);
2472 }
24732468
2474 try stream.writeAll(")");2469 try stream.writeAll(")");
2475 }2470 }
...@@ -2615,7 +2610,9 @@ const Writer = struct {...@@ -2615,7 +2610,9 @@ const Writer = struct {
2615 }2610 }
26162611
2617 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {2612 fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
2618 if (ref.toIndex()) |i| {2613 if (ref == .none) {
2614 return stream.writeAll(".none");
2615 } else if (ref.toIndex()) |i| {
2619 return self.writeInstIndex(stream, i);2616 return self.writeInstIndex(stream, i);
2620 } else {2617 } else {
2621 const val: InternPool.Index = @enumFromInt(@intFromEnum(ref));2618 const val: InternPool.Index = @enumFromInt(@intFromEnum(ref));