From bf7c3e9355530680b066a573c1743f9d570fddc5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 23 Mar 2021 16:47:41 -0700 Subject: astgen: fixups regarding var decls and rl_ptr --- src/Module.zig | 31 ++++--------------------------- 1 file changed, 4 insertions(+), 27 deletions(-) (limited to 'src/Module.zig') diff --git a/src/Module.zig b/src/Module.zig index 5a2426d6af..36a42e96a6 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -930,7 +930,7 @@ pub const Scope = struct { /// Only valid when setBlockResultLoc is called. break_result_loc: astgen.ResultLoc = undefined, /// When a block has a pointer result location, here it is. - rl_ptr: zir.Inst.Index = 0, + rl_ptr: zir.Inst.Ref = 0, /// Keeps track of how many branches of a block did not actually /// consume the result location. astgen uses this to figure out /// whether to rely on break instructions or writing to the result @@ -1136,18 +1136,8 @@ pub const Scope = struct { /// Absolute node index. This function does the conversion to offset from Decl. src_node: ast.Node.Index, ) !zir.Inst.Ref { - return gz.zir_code.ref_start_index + try gz.addUnNodeAsIndex(tag, operand, src_node); - } - - pub fn addUnNodeAsIndex( - gz: *GenZir, - tag: zir.Inst.Tag, - operand: zir.Inst.Ref, - /// Absolute node index. This function does the conversion to offset from Decl. - src_node: ast.Node.Index, - ) !zir.Inst.Index { assert(operand != 0); - return gz.addAsIndex(.{ + return gz.add(.{ .tag = tag, .data = .{ .un_node = .{ .operand = operand, @@ -1245,18 +1235,9 @@ pub const Scope = struct { lhs: zir.Inst.Ref, rhs: zir.Inst.Ref, ) !zir.Inst.Ref { - return gz.zir_code.ref_start_index + try gz.addBinAsIndex(tag, lhs, rhs); - } - - pub fn addBinAsIndex( - gz: *GenZir, - tag: zir.Inst.Tag, - lhs: zir.Inst.Ref, - rhs: zir.Inst.Ref, - ) !zir.Inst.Index { assert(lhs != 0); assert(rhs != 0); - return gz.addAsIndex(.{ + return gz.add(.{ .tag = tag, .data = .{ .bin = .{ .lhs = lhs, @@ -1336,10 +1317,6 @@ pub const Scope = struct { } pub fn add(gz: *GenZir, inst: zir.Inst) !zir.Inst.Ref { - return gz.zir_code.ref_start_index + try gz.addAsIndex(inst); - } - - pub fn addAsIndex(gz: *GenZir, inst: zir.Inst) !zir.Inst.Index { const gpa = gz.zir_code.gpa; try gz.instructions.ensureCapacity(gpa, gz.instructions.items.len + 1); try gz.zir_code.instructions.ensureCapacity(gpa, gz.zir_code.instructions.len + 1); @@ -1347,7 +1324,7 @@ pub const Scope = struct { const new_index = @intCast(zir.Inst.Index, gz.zir_code.instructions.len); gz.zir_code.instructions.appendAssumeCapacity(inst); gz.instructions.appendAssumeCapacity(new_index); - return new_index; + return gz.zir_code.ref_start_index + new_index; } }; -- cgit v1.2.3