Skip to content

Commit

Permalink
Use Mips.calleeSaved.length instead of some magic numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
equation314 committed Dec 20, 2019
1 parent 99b9ef3 commit 315b97f
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class MipsSubroutineEmitter extends SubroutineEmitter {

MipsSubroutineEmitter(MipsAsmEmitter emitter, SubroutineInfo info) {
super(emitter, info);
nextLocalOffset = info.argsSize + 40;
nextLocalOffset = info.argsSize + 4 * Mips.calleeSaved.length + 4;
printer.printLabel(info.funcLabel, "function " + info.funcLabel.prettyString());
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public void emitEnd() {
printer.printComment("start of prologue");
printer.printInstr(new Mips.SPAdd(-nextLocalOffset), "push stack frame");
if (Mips.RA.isUsed() || info.hasCalls) {
printer.printInstr(new Mips.NativeStoreWord(Mips.RA, Mips.SP, info.argsSize + 36),
printer.printInstr(new Mips.NativeStoreWord(Mips.RA, Mips.SP, info.argsSize + 4 * Mips.calleeSaved.length),
"save the return address");
}
for (var i = 0; i < Mips.calleeSaved.length; i++) {
Expand Down Expand Up @@ -132,7 +132,7 @@ public void emitEnd() {
}
}
if (Mips.RA.isUsed() || info.hasCalls) {
printer.printInstr(new Mips.NativeLoadWord(Mips.RA, Mips.SP, info.argsSize + 36),
printer.printInstr(new Mips.NativeLoadWord(Mips.RA, Mips.SP, info.argsSize + 4 * Mips.calleeSaved.length),
"restore the return address");
}
printer.printInstr(new Mips.SPAdd(nextLocalOffset), "pop stack frame");
Expand Down

0 comments on commit 315b97f

Please sign in to comment.