setCondBrPayload
Supports else_scope stacked on then_scope. Unstacks else_scope then then_scope.
Function parameters
Parameters
- condbr:Zir.Inst.Index
- cond:Zir.Inst.Ref
- then_scope:*GenZir
- else_scope:*GenZir
Functions in this namespace
Functions
Source
Implementation
fn setCondBrPayload(
condbr: Zir.Inst.Index,
cond: Zir.Inst.Ref,
then_scope: *GenZir,
else_scope: *GenZir,
) !void {
defer then_scope.unstack();
defer else_scope.unstack();
const astgen = then_scope.astgen;
const then_body = then_scope.instructionsSliceUpto(else_scope);
const else_body = else_scope.instructionsSlice();
const then_body_len = astgen.countBodyLenAfterFixups(then_body);
const else_body_len = astgen.countBodyLenAfterFixups(else_body);
try astgen.extra.ensureUnusedCapacity(
astgen.gpa,
@typeInfo(Zir.Inst.CondBr).@"struct".fields.len + then_body_len + else_body_len,
);
const zir_datas = astgen.instructions.items(.data);
zir_datas[@intFromEnum(condbr)].pl_node.payload_index = astgen.addExtraAssumeCapacity(Zir.Inst.CondBr{
.condition = cond,
.then_body_len = then_body_len,
.else_body_len = else_body_len,
});
astgen.appendBodyWithFixups(then_body);
astgen.appendBodyWithFixups(else_body);
}