aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-03-25 13:03:54 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-03-25 13:03:54 -0700
commit399bb2e154395f1f2372eccb10ea41d6ba5ef68f (patch)
tree91ca58a20bb65c8a404b74a130f06ab1cacbfce0 /src
parent31023de6c4b3957ef356be01b5454426844955a9 (diff)
downloadzig-399bb2e154395f1f2372eccb10ea41d6ba5ef68f.tar.gz
zig-399bb2e154395f1f2372eccb10ea41d6ba5ef68f.zip
astgen: fix array access
Diffstat (limited to 'src')
-rw-r--r--src/astgen.zig28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/astgen.zig b/src/astgen.zig
index 7245e09b66..bab9bda8ad 100644
--- a/src/astgen.zig
+++ b/src/astgen.zig
@@ -1838,25 +1838,21 @@ fn arrayAccess(
rl: ResultLoc,
node: ast.Node.Index,
) InnerError!zir.Inst.Ref {
- if (true) @panic("TODO update for zir-memory-layout");
- const tree = scope.tree();
+ const gz = scope.getGenZir();
+ const tree = gz.tree();
const main_tokens = tree.nodes.items(.main_token);
const node_datas = tree.nodes.items(.data);
-
- const usize_type = try addZIRInstConst(mod, scope, src, .{
- .ty = Type.initTag(.type),
- .val = Value.initTag(.usize_type),
- });
- const index_rl: ResultLoc = .{ .ty = usize_type };
switch (rl) {
- .ref => return addZirInstTag(mod, scope, src, .elem_ptr, .{
- .array = try expr(mod, scope, .ref, node_datas[node].lhs),
- .index = try expr(mod, scope, index_rl, node_datas[node].rhs),
- }),
- else => return rvalue(mod, scope, rl, try addZirInstTag(mod, scope, src, .elem_val, .{
- .array = try expr(mod, scope, .none, node_datas[node].lhs),
- .index = try expr(mod, scope, index_rl, node_datas[node].rhs),
- })),
+ .ref => return gz.addBin(
+ .elem_ptr,
+ try expr(mod, scope, .ref, node_datas[node].lhs),
+ try expr(mod, scope, .{ .ty = .usize_type }, node_datas[node].rhs),
+ ),
+ else => return rvalue(mod, scope, rl, try gz.addBin(
+ .elem_val,
+ try expr(mod, scope, .none, node_datas[node].lhs),
+ try expr(mod, scope, .{ .ty = .usize_type }, node_datas[node].rhs),
+ ), node),
}
}