aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-03-23 16:47:41 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-03-23 16:47:41 -0700
commitbf7c3e9355530680b066a573c1743f9d570fddc5 (patch)
treec38db95a607a14ac89df17079ad465845cf9a6b3 /src/Module.zig
parentbe673e67937bbc3e2c74591f8f447f848b2a566a (diff)
downloadzig-bf7c3e9355530680b066a573c1743f9d570fddc5.tar.gz
zig-bf7c3e9355530680b066a573c1743f9d570fddc5.zip
astgen: fixups regarding var decls and rl_ptr
Diffstat (limited to 'src/Module.zig')
-rw-r--r--src/Module.zig31
1 files changed, 4 insertions, 27 deletions
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;
}
};