|
|
@ -158,6 +158,11 @@ public class CodeGenImpl extends CodeGenBase {
|
|
|
|
/** The descriptor for the current function, or null at the top level. */
|
|
|
|
/** The descriptor for the current function, or null at the top level. */
|
|
|
|
private final FuncInfo funcInfo;
|
|
|
|
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
|
|
|
|
* An analyzer for the function described by FUNCINFO0, which is null for the
|
|
|
|
* top level.
|
|
|
|
* top level.
|
|
|
@ -237,38 +242,52 @@ public class CodeGenImpl extends CodeGenBase {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Void analyze(BinaryExpr node) {
|
|
|
|
public Void analyze(ExprStmt node) {
|
|
|
|
|
|
|
|
node.expr.dispatch(this);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Void analyze(ExprStmt node) {
|
|
|
|
public Void analyze(IfExpr node) {
|
|
|
|
node.expr.dispatch(this);
|
|
|
|
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;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Void analyze(ForStmt node) {
|
|
|
|
public Void analyze(IfStmt node) {
|
|
|
|
// control flow
|
|
|
|
node.condition.dispatch(this);
|
|
|
|
return defaultAction(node);
|
|
|
|
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
|
|
|
|
@Override
|
|
|
|
public Void analyze(Identifier node) {
|
|
|
|
public Void analyze(BinaryExpr node) {
|
|
|
|
// statement
|
|
|
|
elseBlock = generateLocalLabel();
|
|
|
|
return defaultAction(node);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Void analyze(IfExpr node) {
|
|
|
|
public Void analyze(ForStmt node) {
|
|
|
|
// control flow
|
|
|
|
// control flow
|
|
|
|
return defaultAction(node);
|
|
|
|
return defaultAction(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Void analyze(IfStmt node) {
|
|
|
|
public Void analyze(Identifier node) {
|
|
|
|
// control flow
|
|
|
|
// statement
|
|
|
|
return defaultAction(node);
|
|
|
|
return defaultAction(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Void analyze(IndexExpr node) {
|
|
|
|
public Void analyze(IndexExpr node) {
|
|
|
|
// statement
|
|
|
|
// statement
|
|
|
@ -276,7 +295,6 @@ public class CodeGenImpl extends CodeGenBase {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Void analyze(ListExpr node) {
|
|
|
|
public Void analyze(ListExpr node) {
|
|
|
|
// statement
|
|
|
|
// statement
|
|
|
|