change zir definition to use *Inst instead of []const u8

This commit is contained in:
g-w1 2020-12-26 11:11:29 -05:00
parent 641bf4c46e
commit 504c78c022
2 changed files with 52 additions and 5 deletions

View File

@ -706,7 +706,7 @@ pub const Inst = struct {
base: Inst,
positionals: struct {
msg: []const u8,
msg: *Inst,
},
kw_args: struct {},
};
@ -1950,7 +1950,23 @@ const EmitZIR = struct {
.tag = Inst.CompileError.base_tag,
},
.positionals = .{
.msg = try self.arena.allocator.dupe(u8, err_msg_list.items[0].msg),
.msg = blk: {
const msg_str = try self.arena.allocator.dupe(u8, err_msg_list.items[0].msg);
const str_inst = try self.arena.allocator.create(Inst.Str);
str_inst.* = .{
.base = .{
.src = ir_decl.src(),
.tag = Inst.Str.base_tag,
},
.positionals = .{
.bytes = msg_str,
},
.kw_args = .{},
};
break :blk &str_inst.base;
},
},
.kw_args = .{},
};
@ -2080,7 +2096,22 @@ const EmitZIR = struct {
.tag = Inst.CompileError.base_tag,
},
.positionals = .{
.msg = try self.arena.allocator.dupe(u8, err_msg.msg),
.msg = blk: {
const msg_str = try self.arena.allocator.dupe(u8, err_msg.msg);
const str_inst = try self.arena.allocator.create(Inst.Str);
str_inst.* = .{
.base = .{
.src = src,
.tag = Inst.Str.base_tag,
},
.positionals = .{
.bytes = msg_str,
},
.kw_args = .{},
};
break :blk &str_inst.base;
},
},
.kw_args = .{},
};
@ -2094,7 +2125,22 @@ const EmitZIR = struct {
.tag = Inst.CompileError.base_tag,
},
.positionals = .{
.msg = try self.arena.allocator.dupe(u8, "depends on another failed Decl"),
.msg = blk: {
const msg_str = try self.arena.allocator.dupe(u8, "depends on another failed Decl");
const str_inst = try self.arena.allocator.create(Inst.Str);
str_inst.* = .{
.base = .{
.src = src,
.tag = Inst.Str.base_tag,
},
.positionals = .{
.bytes = msg_str,
},
.kw_args = .{},
};
break :blk &str_inst.base;
},
},
.kw_args = .{},
};

View File

@ -487,7 +487,8 @@ fn analyzeInstExport(mod: *Module, scope: *Scope, export_inst: *zir.Inst.Export)
}
fn analyzeInstCompileError(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileError) InnerError!*Inst {
return mod.fail(scope, inst.base.src, "{}", .{inst.positionals.msg});
const msg = try resolveConstString(mod,scope,inst.positionals.msg);
return mod.fail(scope, inst.base.src, "{}", .{msg});
}
fn analyzeInstCompileLog(mod: *Module, scope: *Scope, inst: *zir.Inst.CompileLog) InnerError!*Inst {