Skip to content

Commit

Permalink
gen allocas for params :(
Browse files Browse the repository at this point in the history
  • Loading branch information
probably-neb committed May 9, 2024
1 parent 134587d commit ce5d4c7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/ir/stack.zig
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ pub fn gen_function(
const alloca = Inst.alloca(declType);
_ = try fun.addNamedInst(entryBB, alloca, declName, declType);
}
// add allocas for all function parameters
// and store the params into them
// this is necessary to allow for mutating params
// PERF: identify params that are stored to and gen alloca/store
// for them only
for (fun.params.items, 0..) |item, ID| {
const name = item.name;
const typ = item.type;
const alloca = Inst.alloca(typ);
const allocaReg = try fun.addNamedInst(entryBB, alloca, name, typ);
const storeInst = Inst.store(IR.Ref.fromReg(allocaReg), IR.Ref.param(@intCast(ID), name, typ));
_ = try fun.addAnonInst(entryBB, storeInst);
}

const bodyBB = try fun.newBBWithParent(entryBB, "body");
try fun.addCtrlFlowInst(entryBB, Inst.jmp(IR.Ref.label(bodyBB)));
Expand Down

0 comments on commit ce5d4c7

Please sign in to comment.