// add body to map for emitting later
bodies.put(bodyLabel, whenNode.getBodyNode());
}
// Jump to else or the end in case nothing matches!
m.addInstr(new JumpInstr(hasElse ? elseLabel : endLabel));
// build "else" if it exists
if (hasElse) {
caseInstr.setElse(elseLabel);
bodies.put(elseLabel, caseNode.getElseNode());
}
// now emit bodies
for (Map.Entry<Label, Node> entry : bodies.entrySet()) {
m.addInstr(new LABEL_Instr(entry.getKey()));
Operand bodyValue = build(entry.getValue(), m);
// bodyValue can be null if the body ends with a return!
if (bodyValue != null) {
// Local optimization of break results (followed by a copy & jump) to short-circuit the jump right away
// rather than wait to do it during an optimization pass when a dead jump needs to be removed.
Label tgt = endLabel;
if (bodyValue instanceof BreakResult) {
BreakResult br = (BreakResult)bodyValue;
bodyValue = br._result;
tgt = br._jumpTarget;
}
m.addInstr(new CopyInstr(result, bodyValue));
m.addInstr(new JumpInstr(tgt));
}
}
// close it out
m.addInstr(new LABEL_Instr(endLabel));