|
|
|
@ -434,8 +434,9 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(IfExpr node)
|
|
|
|
|
{
|
|
|
|
|
node.condition.dispatch(this);
|
|
|
|
|
Register result = node.condition.dispatch(this);
|
|
|
|
|
Label ln = generateLocalLabel();
|
|
|
|
|
backend.emitBEQZ(result, ln,"Jump to beginning of loop");
|
|
|
|
|
node.thenExpr.dispatch(this);
|
|
|
|
|
backend.emitJ(ln, "Jump to end of if expression");
|
|
|
|
|
backend.emitLocalLabel(elseBlock, "Else part of if expression");
|
|
|
|
@ -447,8 +448,9 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(IfStmt node)
|
|
|
|
|
{
|
|
|
|
|
node.condition.dispatch(this);
|
|
|
|
|
Register result = node.condition.dispatch(this);
|
|
|
|
|
Label ln = generateLocalLabel();
|
|
|
|
|
backend.emitBEQZ(result, ln,"Jump to beginning of loop");
|
|
|
|
|
for(Stmt s:node.thenBody)
|
|
|
|
|
s.dispatch(this);
|
|
|
|
|
backend.emitJ(ln, "Jump to end of if statement");
|
|
|
|
@ -737,13 +739,13 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
{
|
|
|
|
|
Label startLoop = generateLocalLabel();
|
|
|
|
|
backend.emitLocalLabel(startLoop, "Beginning of while loop");
|
|
|
|
|
node.condition.dispatch(this);
|
|
|
|
|
Register result = node.condition.dispatch(this);
|
|
|
|
|
Label endLoop = elseBlock;
|
|
|
|
|
backend.emitBEQZ(result, endLoop,"Jump to beginning of loop");
|
|
|
|
|
for(Stmt stmt:node.body)
|
|
|
|
|
stmt.dispatch(this);
|
|
|
|
|
backend.emitJ(startLoop, "Jump to beginning of loop");
|
|
|
|
|
backend.emitLocalLabel(endLoop, "End of while loop");
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|