print_zir: fix more crashes during printing

This commit is contained in:
Jacob Young 2023-11-03 12:11:06 -04:00
parent 46d3e5bb04
commit 7b1a644d6e
2 changed files with 7 additions and 9 deletions

View File

@ -6492,6 +6492,7 @@ pub fn cmdDumpZir(
.mod = undefined,
.root_decl = .none,
};
defer file.zir.deinit(gpa);
{
const instruction_bytes = file.zir.instructions.len *

View File

@ -2456,20 +2456,15 @@ const Writer = struct {
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].save_err_ret_index;
try self.writeInstRef(stream, inst_data.operand);
try stream.writeAll(")");
}
fn writeRestoreErrRetIndex(self: *Writer, stream: anytype, inst: Zir.Inst.Index) !void {
const inst_data = self.code.instructions.items(.data)[@intFromEnum(inst)].restore_err_ret_index;
if (inst_data.block != .none) {
try self.writeInstRef(stream, inst_data.block);
}
if (inst_data.operand != .none) {
if (inst_data.block != .none) try stream.writeAll(", ");
try self.writeInstRef(stream, inst_data.operand);
}
try self.writeInstRef(stream, inst_data.block);
try self.writeInstRef(stream, inst_data.operand);
try stream.writeAll(")");
}
@ -2615,7 +2610,9 @@ const Writer = struct {
}
fn writeInstRef(self: *Writer, stream: anytype, ref: Zir.Inst.Ref) !void {
if (ref.toIndex()) |i| {
if (ref == .none) {
return stream.writeAll(".none");
} else if (ref.toIndex()) |i| {
return self.writeInstIndex(stream, i);
} else {
const val: InternPool.Index = @enumFromInt(@intFromEnum(ref));