Add jump to label in return statement

master
Sanjar Ahmadov 4 years ago
parent 3c4eeb2fdc
commit 026eb099b0

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

Loading…
Cancel
Save