|
|
|
@ -769,12 +769,6 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
backend.emitOR(Register.A0, Register.A0, Register.T0, "OR operation");
|
|
|
|
|
backend.emitLocalLabel(label, "Next step after OR");
|
|
|
|
|
}
|
|
|
|
|
/*Maybe NA
|
|
|
|
|
else if(operator.equals("is"))
|
|
|
|
|
{
|
|
|
|
|
backend.emitXOR(Register.A0, Register.A0, Register.T0, comment);
|
|
|
|
|
backend.emitSEQZ(Register.A0, Register.A0, "Result is True if XOR equals 0");
|
|
|
|
|
}*/
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
backend.emitJAL(errorNI, "Operator not implemented for boolean operands");
|
|
|
|
@ -792,7 +786,6 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
backend.emitADDI(Register.SP, Register.FP, "-"+size_label, "Set SP to stack frame");
|
|
|
|
|
sp_off -= 2;
|
|
|
|
|
return Register.A0;
|
|
|
|
|
//addLists();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
backend.emitJAL(errorNI, "Operator not implemented for list operands");
|
|
|
|
@ -808,7 +801,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
backend.emitADDI(SP, FP, -sp_off * wordSize, "Set SP to last argument.");
|
|
|
|
|
backend.emitJAL(streqlLabel, "Invoke method:streql");
|
|
|
|
|
sp_off -= 2;
|
|
|
|
|
backend.emitADDI(SP, FP, -sp_off*wordSize, "restore sp");
|
|
|
|
|
backend.emitADDI(SP, FP, -sp_off*wordSize, "Restore sp");
|
|
|
|
|
}
|
|
|
|
|
else if(operator.equals("!="))
|
|
|
|
|
{
|
|
|
|
@ -866,8 +859,6 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(Identifier node)
|
|
|
|
|
{
|
|
|
|
|
//backend.emitLW(T6, FP, 0, "Inside Identifier: ");
|
|
|
|
|
System.out.println(node.getInferredType());
|
|
|
|
|
Identifier targetID = (Identifier)node;
|
|
|
|
|
Object var = getVar(targetID);
|
|
|
|
|
if(var instanceof StackVarRuntimeInfo){
|
|
|
|
@ -881,11 +872,9 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
return Register.A0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(WhileStmt node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside WhileStmt: ");
|
|
|
|
|
Label startLoop = generateLocalLabel();
|
|
|
|
|
backend.emitLocalLabel(startLoop, "Beginning of while loop");
|
|
|
|
|
Register result = node.condition.dispatch(this);
|
|
|
|
@ -933,18 +922,13 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
return Register.A0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(IntegerLiteral node) {
|
|
|
|
|
System.out.println("Inside IntegerLiteral: " + node.value);
|
|
|
|
|
//backend.emitLW(T6, FP, 0, "Inside IntegerLiteral: " + node.value);
|
|
|
|
|
public Register analyze(IntegerLiteral node)
|
|
|
|
|
{
|
|
|
|
|
backend.emitLI(A0, node.value, "Load integer literal " + node.value);
|
|
|
|
|
|
|
|
|
|
return A0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(ForStmt node)
|
|
|
|
|
{
|
|
|
|
@ -1011,7 +995,6 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
{
|
|
|
|
|
Label startLoop = generateLocalLabel();
|
|
|
|
|
Label endLoop = generateLocalLabel();
|
|
|
|
|
//Label temp = generateLocalLabel();
|
|
|
|
|
r=getRegister();
|
|
|
|
|
regs.add(r);
|
|
|
|
|
Register iden = registerPool[r];
|
|
|
|
@ -1031,7 +1014,6 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
backend.emitMV(iter, Register.ZERO, "Initialize index variable");
|
|
|
|
|
backend.emitSW(iter, Register.FP, -sp_off*wordSize, "Store index on stack");
|
|
|
|
|
incSp(1);
|
|
|
|
|
//backend.emitADDI(Register.SP, Register.SP, -2*wordSize, "Set SP to last argument");
|
|
|
|
|
backend.emitLocalLabel(startLoop, "Start for loop");
|
|
|
|
|
backend.emitLW(iter, Register.FP, -(sp_off-1)*wordSize, "Load index from stack");
|
|
|
|
|
backend.emitLW(l, Register.FP, -(sp_off-2)*wordSize, "Load string location from stack");
|
|
|
|
@ -1067,7 +1049,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Iterable not a list or a string");
|
|
|
|
|
backend.emitJAL(errorNI, "Operator not implemented");
|
|
|
|
|
}
|
|
|
|
|
for(int n:regs)
|
|
|
|
|
freeRegister(n);
|
|
|
|
@ -1172,7 +1154,8 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
* error and exit the program. For example, to throw an OOB error: backend.emitJ(errorOob, "Go
|
|
|
|
|
* to out-of-bounds error and abort");
|
|
|
|
|
*/
|
|
|
|
|
protected void emitCustomCode() {
|
|
|
|
|
protected void emitCustomCode()
|
|
|
|
|
{
|
|
|
|
|
emitStdFunc("concat");
|
|
|
|
|
emitStdFunc("conslist");
|
|
|
|
|
emitStdFunc("strcat");
|
|
|
|
@ -1190,7 +1173,8 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 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);
|
|
|
|
|
if(errLabel==errorOob)
|
|
|
|
|
backend.emitLI(A0, ERROR_OOB, "Exit code for: " + msg);
|
|
|
|
|