|
|
@ -264,7 +264,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
|
|
|
|
|
|
|
public Register analyze(CallExpr node) {
|
|
|
|
public Register analyze(CallExpr node) {
|
|
|
|
System.out.println("Inside CallExpr: " + node.function.name);
|
|
|
|
System.out.println("Inside CallExpr: " + node.function.name);
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside CallExpr: " + node.function.name);
|
|
|
|
//ackend.emitLW(T6, FP, 0, "Inside CallExpr: " + node.function.name);
|
|
|
|
|
|
|
|
|
|
|
|
SymbolInfo Ty = sym.get(node.function.name);
|
|
|
|
SymbolInfo Ty = sym.get(node.function.name);
|
|
|
|
if(Ty instanceof ClassInfo){
|
|
|
|
if(Ty instanceof ClassInfo){
|
|
|
@ -366,7 +366,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);
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
@ -402,7 +402,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Register analyze(ReturnStmt stmt) {
|
|
|
|
public Register analyze(ReturnStmt stmt) {
|
|
|
|
System.out.println("Inside ReturnStmt: ");
|
|
|
|
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) {
|
|
|
|
backend.emitMV(A0, ZERO, "Return None");
|
|
|
|
backend.emitMV(A0, ZERO, "Return None");
|
|
|
@ -423,7 +423,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
public Register analyze(NoneLiteral node)
|
|
|
|
public Register analyze(NoneLiteral node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("Inside NoneLiteral: ");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -432,7 +432,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
public Register analyze(StringLiteral node)
|
|
|
|
public Register analyze(StringLiteral node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("Inside StringLiteral: ");
|
|
|
|
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");
|
|
|
|
return Register.A0;
|
|
|
|
return Register.A0;
|
|
|
@ -442,7 +442,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
public Register analyze(BooleanLiteral node)
|
|
|
|
public Register analyze(BooleanLiteral node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("Inside BooleanLiteral: ");
|
|
|
|
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 ");
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -521,7 +521,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
public Register analyze(AssignStmt node)
|
|
|
|
public Register analyze(AssignStmt node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("Inside AssignStmt: ");
|
|
|
|
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())
|
|
|
|
//{
|
|
|
|
//{
|
|
|
@ -556,7 +556,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
public Register analyze(ExprStmt node)
|
|
|
|
public Register analyze(ExprStmt node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("Inside ExprStmt: ");
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -667,7 +667,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
System.out.println("Inside BinaryExpr: ");
|
|
|
|
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: ");
|
|
|
|
|
|
|
|
|
|
|
|
if(node.left.getInferredType().equals(Type.INT_TYPE) && node.right.getInferredType().equals(Type.INT_TYPE))
|
|
|
|
if(node.left.getInferredType().equals(Type.INT_TYPE) && node.right.getInferredType().equals(Type.INT_TYPE))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -883,8 +883,9 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
if(node.operator.equals("-") && node.getInferredType().equals(Type.INT_TYPE))
|
|
|
|
if(node.operator.equals("-") && node.getInferredType().equals(Type.INT_TYPE))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
node.operand.dispatch(this);
|
|
|
|
node.operand.dispatch(this);
|
|
|
|
backend.emitLI(Register.T0, -1, "Set value of Register T0 to -1");
|
|
|
|
//backend.emitLI(Register.T0, -1, "Set value of Register T0 to -1");
|
|
|
|
backend.emitMUL(Register.A0, Register.A0, Register.T0, "Multiply by -1");
|
|
|
|
//backend.emitMUL(Register.A0, Register.A0, Register.T0, "Multiply by -1");
|
|
|
|
|
|
|
|
backend.emitSUB(Register.A0, Register.ZERO, Register.A0, "Unary negation");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(node.operator.equals("not") && node.getInferredType().equals(Type.BOOL_TYPE))
|
|
|
|
else if(node.operator.equals("not") && node.getInferredType().equals(Type.BOOL_TYPE))
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -898,7 +899,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Register analyze(Identifier node)
|
|
|
|
public Register analyze(Identifier node)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside Identifier: ");
|
|
|
|
//backend.emitLW(T6, FP, 0, "Inside Identifier: ");
|
|
|
|
|
|
|
|
|
|
|
|
Identifier targetID = (Identifier)node;
|
|
|
|
Identifier targetID = (Identifier)node;
|
|
|
|
Object var = getVar(targetID);
|
|
|
|
Object var = getVar(targetID);
|
|
|
@ -970,7 +971,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Register analyze(IntegerLiteral node) {
|
|
|
|
public Register analyze(IntegerLiteral node) {
|
|
|
|
System.out.println("Inside IntegerLiteral: " + node.value);
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
return A0;
|
|
|
|
return A0;
|
|
|
@ -1189,6 +1190,9 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
/** Emit an error routine labeled ERRLABEL that aborts with message MSG. */
|
|
|
|
/** Emit an error routine labeled ERRLABEL that aborts with message MSG. */
|
|
|
|
private void emitErrorFunc(Label errLabel, String msg) {
|
|
|
|
private void emitErrorFunc(Label errLabel, String msg) {
|
|
|
|
backend.emitGlobalLabel(errLabel);
|
|
|
|
backend.emitGlobalLabel(errLabel);
|
|
|
|
|
|
|
|
if(errLabel==errorOob)
|
|
|
|
|
|
|
|
backend.emitLI(A0, ERROR_OOB, "Exit code for: " + msg);
|
|
|
|
|
|
|
|
else
|
|
|
|
backend.emitLI(A0, ERROR_NONE, "Exit code for: " + msg);
|
|
|
|
backend.emitLI(A0, ERROR_NONE, "Exit code for: " + msg);
|
|
|
|
backend.emitLA(A1, constants.getStrConstant(msg), "Load error message as str");
|
|
|
|
backend.emitLA(A1, constants.getStrConstant(msg), "Load error message as str");
|
|
|
|
backend.emitADDI(
|
|
|
|
backend.emitADDI(
|
|
|
|