|
|
|
@ -236,7 +236,10 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
// *********** functions start ***********
|
|
|
|
|
|
|
|
|
|
public Register analyze(CallExpr node) {
|
|
|
|
|
System.out.println("Inside CallExpr: " + node.function.name);
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside CallExpr: " + node.function.name);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SymbolInfo Ty = globalSymbols.get(node.function.name);
|
|
|
|
|
if(Ty instanceof ClassInfo){
|
|
|
|
|
//object create
|
|
|
|
@ -295,6 +298,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Register analyze(MethodCallExpr node) {
|
|
|
|
|
System.out.println("Inside MethodCallExpr: " + node.method.member.name);
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside MethodCallExpr: " + node.method.member.name);
|
|
|
|
|
Register obj = node.method.object.dispatch(this);
|
|
|
|
|
int n_args = node.args.size();
|
|
|
|
@ -327,6 +331,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(ReturnStmt stmt) {
|
|
|
|
|
System.out.println("Inside ReturnStmt: ");
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside ReturnStmt: ");
|
|
|
|
|
Expr expr = stmt.value;
|
|
|
|
|
if (expr == null) {
|
|
|
|
@ -336,7 +341,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
|
|
|
|
|
// All expressions should save their end result in A0
|
|
|
|
|
expr.dispatch(this);
|
|
|
|
|
|
|
|
|
|
backend.emitJ(this.epilogue, "Jump to function epilogue");
|
|
|
|
|
return A0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -347,6 +352,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(NoneLiteral node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside NoneLiteral: ");
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside NoneLiteral: ");
|
|
|
|
|
backend.emitMV(Register.A0, Register.ZERO, "Load none");
|
|
|
|
|
return Register.A0;
|
|
|
|
@ -355,6 +361,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(StringLiteral node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside StringLiteral: ");
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside StringLiteral: ");
|
|
|
|
|
Label l = constants.getStrConstant(node.value);
|
|
|
|
|
backend.emitLA(Register.A0, l, "Load string literal");
|
|
|
|
@ -364,6 +371,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(BooleanLiteral node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside BooleanLiteral: ");
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside BooleanLiteral: ");
|
|
|
|
|
if(node.value==true)
|
|
|
|
|
backend.emitLI(Register.A0, 1, "Load boolean literal: true ");
|
|
|
|
@ -376,6 +384,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(AssignStmt node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside AssignStmt: ");
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside AssignStmt: ");
|
|
|
|
|
Type t = node.value.getInferredType();
|
|
|
|
|
// if(t.isSpecialType() || t.isListType())
|
|
|
|
@ -415,6 +424,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(ExprStmt node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside ExprStmt: ");
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside ExprStmt: ");
|
|
|
|
|
node.expr.dispatch(this);
|
|
|
|
|
return null;
|
|
|
|
@ -423,6 +433,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(IfExpr node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside IfExpr: ");
|
|
|
|
|
node.condition.dispatch(this);
|
|
|
|
|
Label ln = generateLocalLabel();
|
|
|
|
|
node.thenExpr.dispatch(this);
|
|
|
|
@ -436,6 +447,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(IfStmt node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside IfStmt: ");
|
|
|
|
|
node.condition.dispatch(this);
|
|
|
|
|
Label ln = generateLocalLabel();
|
|
|
|
|
for(Stmt s:node.thenBody)
|
|
|
|
@ -514,6 +526,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(BinaryExpr node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside BinaryExpr: ");
|
|
|
|
|
String operator = node.operator;
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside BinaryExpr: ");
|
|
|
|
|
|
|
|
|
@ -724,15 +737,18 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(WhileStmt node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside WhileStmt: ");
|
|
|
|
|
Label startLoop = generateLocalLabel();
|
|
|
|
|
backend.emitLocalLabel(startLoop, "Beginning of while loop");
|
|
|
|
|
node.condition.dispatch(this);
|
|
|
|
|
Label endLoop = elseBlock;
|
|
|
|
|
for(Stmt stmt:node.body)
|
|
|
|
|
for(Stmt stmt:node.body) {
|
|
|
|
|
System.out.println("Inside WhileStmt: for loop " + stmt.toString());
|
|
|
|
|
stmt.dispatch(this);
|
|
|
|
|
}
|
|
|
|
|
backend.emitJ(startLoop, "Jump to beginning of loop");
|
|
|
|
|
backend.emitLocalLabel(endLoop, "End of while loop");
|
|
|
|
|
|
|
|
|
|
System.out.println("Inside WhileStmt: Done with while");
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -765,9 +781,12 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(IntegerLiteral node) {
|
|
|
|
|
System.out.println("Inside IntegerLiteral: " + node.value);
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside IntegerLiteral: " + node.value);
|
|
|
|
|
backend.emitLI(A0, node.value, "Load integer literal " + node.value);
|
|
|
|
|
//backend.emitJAL(makeintLabel, "Box integer");
|
|
|
|
|
|
|
|
|
|
// FIXME: Remove line below later once you are boxing it in function call
|
|
|
|
|
backend.emitJAL(makeintLabel, "Box integer");
|
|
|
|
|
return A0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|