Skip to content

Commit

Permalink
CodeGen: fix child nodes usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ehaas authored and Vexu committed Sep 10, 2024
1 parent 3ab8111 commit 46f3995
Showing 1 changed file with 10 additions and 27 deletions.
37 changes: 10 additions & 27 deletions src/aro/CodeGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -316,18 +316,13 @@ fn genExpr(c: *CodeGen, node: NodeIndex) Error!Ir.Ref {
try c.builder.startBlock(label);
try c.genStmt(data.decl.node);
},
.compound_stmt_two => {
const old_sym_len = c.symbols.items.len;
c.symbols.items.len = old_sym_len;
.compound_stmt_two, .compound_stmt => {
const child_nodes = c.tree.childNodes(node);

if (data.bin.lhs != .none) try c.genStmt(data.bin.lhs);
if (data.bin.rhs != .none) try c.genStmt(data.bin.rhs);
},
.compound_stmt => {
const old_sym_len = c.symbols.items.len;
c.symbols.items.len = old_sym_len;

for (c.tree.data[data.range.start..data.range.end]) |stmt| try c.genStmt(stmt);
for (child_nodes) |stmt| try c.genStmt(stmt);
},
.if_then_else_stmt => {
const then_label = try c.builder.makeLabel("if.then");
Expand Down Expand Up @@ -820,13 +815,9 @@ fn genExpr(c: *CodeGen, node: NodeIndex) Error!Ir.Ref {
};
return c.builder.addPhi(&phi_buf, try c.genType(ty));
},
.call_expr_one => if (data.bin.rhs == .none) {
return c.genCall(data.bin.lhs, &.{}, ty);
} else {
return c.genCall(data.bin.lhs, &.{data.bin.rhs}, ty);
},
.call_expr => {
return c.genCall(c.tree.data[data.range.start], c.tree.data[data.range.start + 1 .. data.range.end], ty);
.call_expr_one, .call_expr => {
const child_nodes = c.tree.childNodes(node);
return c.genCall(child_nodes[0], child_nodes[1..], ty);
},
.bool_or_expr => {
if (c.tree.value_map.get(data.bin.lhs)) |lhs| {
Expand Down Expand Up @@ -912,22 +903,14 @@ fn genExpr(c: *CodeGen, node: NodeIndex) Error!Ir.Ref {
},
.generic_association_expr, .generic_default_expr => unreachable,
.stmt_expr => switch (c.node_tag[@intFromEnum(data.un)]) {
.compound_stmt_two => {
const old_sym_len = c.symbols.items.len;
c.symbols.items.len = old_sym_len;
.compound_stmt_two, .compound_stmt => {
const child_nodes = c.tree.childNodes(data.un);

const stmt_data = c.node_data[@intFromEnum(data.un)];
if (stmt_data.bin.rhs == .none) return c.genExpr(stmt_data.bin.lhs);
try c.genStmt(stmt_data.bin.lhs);
return c.genExpr(stmt_data.bin.rhs);
},
.compound_stmt => {
const old_sym_len = c.symbols.items.len;
c.symbols.items.len = old_sym_len;

const stmt_data = c.node_data[@intFromEnum(data.un)];
for (c.tree.data[stmt_data.range.start .. stmt_data.range.end - 1]) |stmt| try c.genStmt(stmt);
return c.genExpr(c.tree.data[stmt_data.range.end]);
for (child_nodes[0 .. child_nodes.len - 1]) |stmt| try c.genStmt(stmt);
return c.genExpr(child_nodes[child_nodes.len - 1]);
},
else => unreachable,
},
Expand Down

0 comments on commit 46f3995

Please sign in to comment.