|
|
|
@ -264,7 +264,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
|
|
|
|
|
public Register analyze(CallExpr node) {
|
|
|
|
|
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);
|
|
|
|
|
if(Ty instanceof ClassInfo){
|
|
|
|
@ -366,7 +366,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);
|
|
|
|
|
// backend.emitLW(T6, FP, 0, "Inside MethodCallExpr: " + node.method.member.name);
|
|
|
|
|
Register obj = node.method.object.dispatch(this);
|
|
|
|
|
int n_args = node.args.size();
|
|
|
|
|
|
|
|
|
@ -402,7 +402,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
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;
|
|
|
|
|
if (expr == null) {
|
|
|
|
|
backend.emitMV(A0, ZERO, "Return None");
|
|
|
|
@ -423,7 +423,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
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");
|
|
|
|
|
return Register.A0;
|
|
|
|
|
}
|
|
|
|
@ -432,7 +432,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
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);
|
|
|
|
|
backend.emitLA(Register.A0, l, "Load string literal");
|
|
|
|
|
return Register.A0;
|
|
|
|
@ -442,7 +442,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
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)
|
|
|
|
|
backend.emitLI(Register.A0, 1, "Load boolean literal: true ");
|
|
|
|
|
else
|
|
|
|
@ -521,7 +521,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
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();
|
|
|
|
|
// if(t.isSpecialType() || t.isListType())
|
|
|
|
|
//{
|
|
|
|
@ -556,7 +556,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
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);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
@ -667,7 +667,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside BinaryExpr: ");
|
|
|
|
|
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))
|
|
|
|
|
{
|
|
|
|
@ -883,8 +883,9 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
if(node.operator.equals("-") && node.getInferredType().equals(Type.INT_TYPE))
|
|
|
|
|
{
|
|
|
|
|
node.operand.dispatch(this);
|
|
|
|
|
backend.emitLI(Register.T0, -1, "Set value of Register T0 to -1");
|
|
|
|
|
backend.emitMUL(Register.A0, Register.A0, Register.T0, "Multiply by -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.emitSUB(Register.A0, Register.ZERO, Register.A0, "Unary negation");
|
|
|
|
|
}
|
|
|
|
|
else if(node.operator.equals("not") && node.getInferredType().equals(Type.BOOL_TYPE))
|
|
|
|
|
{
|
|
|
|
@ -898,7 +899,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(Identifier node)
|
|
|
|
|
{
|
|
|
|
|
backend.emitLW(T6, FP, 0, "Inside Identifier: ");
|
|
|
|
|
//backend.emitLW(T6, FP, 0, "Inside Identifier: ");
|
|
|
|
|
|
|
|
|
|
Identifier targetID = (Identifier)node;
|
|
|
|
|
Object var = getVar(targetID);
|
|
|
|
@ -970,7 +971,7 @@ 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.emitLW(T6, FP, 0, "Inside IntegerLiteral: " + node.value);
|
|
|
|
|
backend.emitLI(A0, node.value, "Load integer literal " + node.value);
|
|
|
|
|
|
|
|
|
|
return A0;
|
|
|
|
@ -1189,7 +1190,10 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
/** Emit an error routine labeled ERRLABEL that aborts with message MSG. */
|
|
|
|
|
private void emitErrorFunc(Label errLabel, String msg) {
|
|
|
|
|
backend.emitGlobalLabel(errLabel);
|
|
|
|
|
backend.emitLI(A0, ERROR_NONE, "Exit code for: " + msg);
|
|
|
|
|
if(errLabel==errorOob)
|
|
|
|
|
backend.emitLI(A0, ERROR_OOB, "Exit code for: " + msg);
|
|
|
|
|
else
|
|
|
|
|
backend.emitLI(A0, ERROR_NONE, "Exit code for: " + msg);
|
|
|
|
|
backend.emitLA(A1, constants.getStrConstant(msg), "Load error message as str");
|
|
|
|
|
backend.emitADDI(
|
|
|
|
|
A1, A1, getAttrOffset(strClass, "__str__"), "Load address of attribute __str__");
|
|
|
|
|