master
Apoorva Ranade 4 years ago
parent 4d6e6fdede
commit 23a19c27f8

@ -814,7 +814,7 @@ public class CodeGenImpl extends CodeGenBase
node.right.dispatch(this); node.right.dispatch(this);
backend.emitSW(Register.A0, Register.FP, -sp_off*wordSize, "Push right operand on stack slot "+sp_off); backend.emitSW(Register.A0, Register.FP, -sp_off*wordSize, "Push right operand on stack slot "+sp_off);
incSp(1); incSp(1);
backend.emitADDI(Register.SP,Register.FP,-sp_off*wordSize,"Set SP to last argument"); backend.emitADDI(Register.SP,Register.FP,-(sp_off-1)*wordSize,"Set SP to last argument");
backend.emitJAL(concatLabel, "Call concatenation routine"); backend.emitJAL(concatLabel, "Call concatenation routine");
backend.emitADDI(Register.SP, Register.FP, "-"+size_label, "Set SP to stack frame"); backend.emitADDI(Register.SP, Register.FP, "-"+size_label, "Set SP to stack frame");
return Register.A0; return Register.A0;
@ -1095,19 +1095,19 @@ public class CodeGenImpl extends CodeGenBase
{ {
backend.emitLW(vacantReg, FP, -sp_off * wordSize, String.format("Pop stack slot %d", sp_off)); backend.emitLW(vacantReg, FP, -sp_off * wordSize, String.format("Pop stack slot %d", sp_off));
final Label bp = generateLocalLabel(); final Label bp = generateLocalLabel();
backend.emitBNEZ(listObj, bp, "Ensure not None"); backend.emitBNEZ(vacantReg, bp, "Ensure not None");
backend.emitJ(errorNone, "Go to error handler"); backend.emitJ(errorNone, "Go to error handler");
backend.emitLocalLabel(bp, "Not None"); backend.emitLocalLabel(bp, "Not None");
final Label bt = generateLocalLabel(); final Label bt = generateLocalLabel();
backend.emitLW(temp, listObj, getAttrOffset(listClass, "__len__"), "Load attribute: __len__"); backend.emitLW(temp, vacantReg, getAttrOffset(listClass, "__len__"), "Load attribute: __len__");
backend.emitBLTU(index, temp, bt, "Ensure 0 <= index < len"); backend.emitBLTU(index, temp, bt, "Ensure 0 <= index < len");
backend.emitJ(errorOob, "Go to error handler"); backend.emitJ(errorOob, "Go to error handler");
backend.emitLocalLabel(bt, "Index within bounds"); backend.emitLocalLabel(bt, "Index within bounds");
backend.emitADDI(index, index, 4, "Compute list element offset in words"); backend.emitADDI(index, index, 4, "Compute list element offset in words");
backend.emitLI(temp, wordSize, "Word size in bytes"); backend.emitLI(temp, wordSize, "Word size in bytes");
backend.emitMUL(index, index, temp, "Compute list element offset in bytes"); backend.emitMUL(index, index, temp, "Compute list element offset in bytes");
backend.emitADD(index, listObj, index, "Pointer to list element"); backend.emitADD(index, vacantReg, index, "Pointer to list element");
backend.emitLW(vacantReg, index, 0, "Set list element"); backend.emitLW(Register.A0, index, 0, "Set list element");
} }
else else
{ {

Loading…
Cancel
Save