|
|
|
@ -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");
|
|
|
|
@ -802,13 +795,13 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
{
|
|
|
|
|
if(operator.equals("=="))
|
|
|
|
|
{
|
|
|
|
|
incSp(2);
|
|
|
|
|
backend.emitSW(node.left.dispatch(this), FP, (1 - sp_off) *wordSize, "Push argument 0 from last.");
|
|
|
|
|
backend.emitSW(node.right.dispatch(this), FP, ( - sp_off) *wordSize, "Push argument 1 from last.");
|
|
|
|
|
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");
|
|
|
|
|
incSp(2);
|
|
|
|
|
backend.emitSW(node.left.dispatch(this), FP, (1 - sp_off) *wordSize, "Push argument 0 from last.");
|
|
|
|
|
backend.emitSW(node.right.dispatch(this), FP, ( - sp_off) *wordSize, "Push argument 1 from last.");
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
else if(operator.equals("!="))
|
|
|
|
|
{
|
|
|
|
@ -866,9 +859,7 @@ 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;
|
|
|
|
|
Identifier targetID = (Identifier)node;
|
|
|
|
|
Object var = getVar(targetID);
|
|
|
|
|
if(var instanceof StackVarRuntimeInfo){
|
|
|
|
|
StackVarRuntimeInfo rtinfo = (StackVarRuntimeInfo) var;
|
|
|
|
@ -880,13 +871,11 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
|
|
|
|
|
return Register.A0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Register analyze(WhileStmt node)
|
|
|
|
|
{
|
|
|
|
|
System.out.println("Inside WhileStmt: ");
|
|
|
|
|
Label startLoop = generateLocalLabel();
|
|
|
|
|
Label startLoop = generateLocalLabel();
|
|
|
|
|
backend.emitLocalLabel(startLoop, "Beginning of while loop");
|
|
|
|
|
Register result = node.condition.dispatch(this);
|
|
|
|
|
Label endLoop = generateLocalLabel();
|
|
|
|
@ -933,17 +922,12 @@ 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);
|
|
|
|
|
backend.emitLI(A0, node.value, "Load integer literal " + 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);
|
|
|
|
@ -1124,7 +1106,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
backend.emitLBU(T0, T0, 0, "Load character");
|
|
|
|
|
backend.emitSLLI(A0, T0, 2, "A0 = T0 * 4");
|
|
|
|
|
backend.emitSLLI(T0, T0, 4, "T0 = T0 * 16");
|
|
|
|
|
backend.emitADD(T0, T0, A0, " T0*20 = offset to all chars");
|
|
|
|
|
backend.emitADD(T0, T0, A0, "T0*20 = offset to all chars");
|
|
|
|
|
backend.emitLA(A0, allCharsLabel, "All chars");
|
|
|
|
|
backend.emitADD(A0, A0, T0, "get the char");
|
|
|
|
|
}
|
|
|
|
@ -1149,7 +1131,7 @@ public class CodeGenImpl extends CodeGenBase
|
|
|
|
|
backend.emitADDI(A0, obj, getAttrOffset(objectClass, node.member.name), "get address of attr");
|
|
|
|
|
else
|
|
|
|
|
backend.emitLW(A0, obj, getAttrOffset(objectClass, node.member.name),
|
|
|
|
|
String.format("Get value of attribute: %s.%s", objectClass.getClassName(), node.member.name));
|
|
|
|
|
String.format("Get value of attribute: %s.%s", objectClass.getClassName(), node.member.name));
|
|
|
|
|
return A0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -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);
|
|
|
|
|