Skip to content
Snippets Groups Projects
Verified Commit 772b0697 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

PUSH instruction problem fixed: now push satisfies x86 spec

parent 6bb094b5
No related branches found
No related tags found
No related merge requests found
Pipeline #237 passed with warnings with stages
in 4 minutes and 8 seconds
...@@ -39,13 +39,13 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -39,13 +39,13 @@ public class CodeGenImpl extends CodeGenBase {
} }
} }
public void emitPush(RiscVBackend.Register reg, String comment) { public void emitPush(RiscVBackend.Register reg, String comment) {
backend.emitSW(reg, SP, 0, comment);
backend.emitADDI(SP, SP, -1 * backend.getWordSize(), comment); backend.emitADDI(SP, SP, -1 * backend.getWordSize(), comment);
backend.emitSW(reg, SP, 0, comment);
} }
public void emitPop(RiscVBackend.Register reg, String comment) { public void emitPop(RiscVBackend.Register reg, String comment) {
backend.emitADDI(SP, SP, backend.getWordSize(), comment);
if(reg != null) if(reg != null)
backend.emitLW(reg, SP, 0, comment); backend.emitLW(reg, SP, 0, comment);
backend.emitADDI(SP, SP, backend.getWordSize(), comment);
} }
public void emitCall(Label calledLabel, String comment) { public void emitCall(Label calledLabel, String comment) {
// Arguments should be already pushed to stack. // Arguments should be already pushed to stack.
...@@ -56,7 +56,7 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -56,7 +56,7 @@ public class CodeGenImpl extends CodeGenBase {
// jal will set RA register properly. // jal will set RA register properly.
// FIXME: Testing fucking silly $print // FIXME: Testing fucking silly $print
backend.emitADDI(SP, SP, 3 * backend.getWordSize(), "FUCKING SILLY BUILTIN CODE"); backend.emitADDI(SP, SP, 2 * backend.getWordSize(), "FUCKING SILLY BUILTIN CODE");
backend.emitJAL(calledLabel, "Call it!"); backend.emitJAL(calledLabel, "Call it!");
backend.emitADDI(SP, FP, -2 * backend.getWordSize(), "Revert all local variables on this dying frame."); backend.emitADDI(SP, FP, -2 * backend.getWordSize(), "Revert all local variables on this dying frame.");
...@@ -79,7 +79,7 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -79,7 +79,7 @@ public class CodeGenImpl extends CodeGenBase {
emitPush(tmpReg, null); emitPush(tmpReg, null);
backend.emitLI(tmpReg, 1, "OBJECT HEAD - TYPE = INT"); backend.emitLI(tmpReg, 1, "OBJECT HEAD - TYPE = INT");
emitPush(tmpReg, null); emitPush(tmpReg, null);
backend.emitADDI(tmpReg, SP, backend.getWordSize(), "Return INT address."); backend.emitMV(tmpReg, SP, "Return INT address.");
} }
public void emitPushBoolVal(RiscVBackend.Register tmpReg, Boolean val, String comment) { public void emitPushBoolVal(RiscVBackend.Register tmpReg, Boolean val, String comment) {
emitNoop(comment); emitNoop(comment);
...@@ -91,7 +91,7 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -91,7 +91,7 @@ public class CodeGenImpl extends CodeGenBase {
emitPush(tmpReg, null); emitPush(tmpReg, null);
backend.emitLI(tmpReg, 2, "OBJECT HEAD - TYPE = BOOL"); backend.emitLI(tmpReg, 2, "OBJECT HEAD - TYPE = BOOL");
emitPush(tmpReg, null); emitPush(tmpReg, null);
backend.emitADDI(tmpReg, SP, backend.getWordSize(), "Return BOOL address."); backend.emitMV(tmpReg, SP, "Return BOOL address.");
} }
public void emitPushStrVal(RiscVBackend.Register tmpReg, String val, String comment) { public void emitPushStrVal(RiscVBackend.Register tmpReg, String val, String comment) {
emitNoop(comment); emitNoop(comment);
...@@ -121,7 +121,7 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -121,7 +121,7 @@ public class CodeGenImpl extends CodeGenBase {
emitPush(tmpReg, null); emitPush(tmpReg, null);
backend.emitLI(tmpReg, 3, "OBJECT HEAD - TYPE = STR"); backend.emitLI(tmpReg, 3, "OBJECT HEAD - TYPE = STR");
emitPush(tmpReg, null); emitPush(tmpReg, null);
backend.emitADDI(tmpReg, SP, backend.getWordSize(), "Return STR OBJ address."); backend.emitMV(tmpReg, SP, "Return STR OBJ address.");
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment