Analyze if expr and stmt
This commit is contained in:
@@ -158,6 +158,11 @@ public class CodeGenImpl extends CodeGenBase {
|
||||
/** The descriptor for the current function, or null at the top level. */
|
||||
private final FuncInfo funcInfo;
|
||||
|
||||
/** Label of code that exits from block. */
|
||||
protected Label elseBlock;
|
||||
// Variable to store offset from frame pointer to identify next
|
||||
// empty space on stack frame to store variable
|
||||
private final int offset = 12;
|
||||
/**
|
||||
* An analyzer for the function described by FUNCINFO0, which is null for the
|
||||
* top level.
|
||||
@@ -236,15 +241,40 @@ public class CodeGenImpl extends CodeGenBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void analyze(BinaryExpr node) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Void analyze(ExprStmt node) {
|
||||
node.expr.dispatch(this);
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Void analyze(IfExpr node) {
|
||||
node.condition.dispatch(this);
|
||||
Label ln = generateLocalLabel();
|
||||
node.thenExpr.dispatch(this);
|
||||
backend.emitJ(ln, "Jump to end of if expression");
|
||||
backend.emitLocalLabel(elseBlock, "Else part of if expression");
|
||||
node.elseExpr.dispatch(this);
|
||||
backend.emitLocalLabel(ln, "End of if expression");
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Void analyze(IfStmt node) {
|
||||
node.condition.dispatch(this);
|
||||
Label ln = generateLocalLabel();
|
||||
for(Stmt s:node.thenBody)
|
||||
s.dispatch(this);
|
||||
backend.emitJ(ln, "Jump to end of if statement");
|
||||
backend.emitLocalLabel(elseBlock, "Else part of if statement");
|
||||
for(Stmt s:node.elseBody)
|
||||
s.dispatch(this);
|
||||
backend.emitLocalLabel(ln, "End of if statement");
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Void analyze(BinaryExpr node) {
|
||||
elseBlock = generateLocalLabel();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void analyze(ForStmt node) {
|
||||
@@ -257,17 +287,6 @@ public class CodeGenImpl extends CodeGenBase {
|
||||
return defaultAction(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void analyze(IfExpr node) {
|
||||
// control flow
|
||||
return defaultAction(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void analyze(IfStmt node) {
|
||||
// control flow
|
||||
return defaultAction(node);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void analyze(IndexExpr node) {
|
||||
@@ -276,7 +295,6 @@ public class CodeGenImpl extends CodeGenBase {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Void analyze(ListExpr node) {
|
||||
// statement
|
||||
|
||||
Reference in New Issue
Block a user