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

[DO NOT BUILD] working on push/pop

parent 69f303d4
No related branches found
No related tags found
No related merge requests found
...@@ -299,7 +299,6 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -299,7 +299,6 @@ public class CodeGenImpl extends CodeGenBase {
@Override @Override
public Void analyze(AssignStmt node) { public Void analyze(AssignStmt node) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr by 1 for Condition");
node.value.dispatch(this); node.value.dispatch(this);
RiscVBackend.Register tmpReg = /*regMgr.borrowOneTmp()*/ T6; RiscVBackend.Register tmpReg = /*regMgr.borrowOneTmp()*/ T6;
RiscVBackend.Register tmpReg2 = /*regMgr.borrowOneTmp()*/ T5; RiscVBackend.Register tmpReg2 = /*regMgr.borrowOneTmp()*/ T5;
...@@ -358,7 +357,6 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -358,7 +357,6 @@ public class CodeGenImpl extends CodeGenBase {
@Override @Override
public Void analyze(IfStmt node) { public Void analyze(IfStmt node) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr by 1 for Condition");
node.condition.dispatch(this); node.condition.dispatch(this);
RiscVBackend.Register tmpReg = /*regMgr.borrowTmp()*/ T6; RiscVBackend.Register tmpReg = /*regMgr.borrowTmp()*/ T6;
betterBackend.emitPop(tmpReg, "IfStmt: Get condition"); betterBackend.emitPop(tmpReg, "IfStmt: Get condition");
...@@ -389,7 +387,6 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -389,7 +387,6 @@ public class CodeGenImpl extends CodeGenBase {
Label exitLabel = new Label(labelPrefix + ".exit"); Label exitLabel = new Label(labelPrefix + ".exit");
backend.emitLocalLabel(beginLabel, "WhileStmt: Begin"); backend.emitLocalLabel(beginLabel, "WhileStmt: Begin");
backend.emitADDI(SP, SP, -4, "Increment stack ptr by 1 for Condition");
node.condition.dispatch(this); node.condition.dispatch(this);
RiscVBackend.Register tmpReg = /*borrowOneTmp*/ T6; RiscVBackend.Register tmpReg = /*borrowOneTmp*/ T6;
betterBackend.emitPop(tmpReg, "GetCondition"); betterBackend.emitPop(tmpReg, "GetCondition");
...@@ -472,20 +469,20 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -472,20 +469,20 @@ public class CodeGenImpl extends CodeGenBase {
SymbolInfo ident = sym.get(id.name); SymbolInfo ident = sym.get(id.name);
if (ident instanceof GlobalVarInfo) { // global var case if (ident instanceof GlobalVarInfo) { // global var case
backend.emitLW(A0, ((GlobalVarInfo) ident).getLabel(), "Load identifier"); backend.emitLW(A0, ((GlobalVarInfo) ident).getLabel(), "Load identifier");
backend.emitSW(A0, SP, 0, "Push to stack"); betterBackend.emitPush(A0, "Ident: GlobalVar");
} else if (ident instanceof StackVarInfo){ // local variable } else if (ident instanceof StackVarInfo){ // local variable
StackVarInfo identVar = (StackVarInfo) ident; StackVarInfo identVar = (StackVarInfo) ident;
if(funcArgsMap.containsKey(identVar.getVarName())) { if(funcArgsMap.containsKey(identVar.getVarName())) {
// is a function arg. // is a function arg.
backend.emitLW(T6, FP, funcArgsMap.get(identVar.getVarName()), "Idnet:get FuncArg identifier value to reg"); backend.emitLW(T6, FP, funcArgsMap.get(identVar.getVarName()), "Idnet:get FuncArg identifier value to reg");
backend.emitSW(T6, SP, 0, "Push to stack without decrease SP"); betterBackend.emitPush(T6, "Ident: Arg");
return null; // DO NOT RUN THE FUCKING SILLY CODE BELOW return null; // DO NOT RUN THE FUCKING SILLY CODE BELOW
} }
// TODO: Function arg works, but local var won't work. // TODO: Function arg works, but local var won't work.
if (id.getInferredType().equals(SymbolType.INT_TYPE)) { if (id.getInferredType().equals(SymbolType.INT_TYPE)) {
IntegerLiteral value = (IntegerLiteral) (identVar.getInitialValue()); IntegerLiteral value = (IntegerLiteral) (identVar.getInitialValue());
backend.emitLI(A0, value.value, "Load initial value of StackVar"); backend.emitLI(A0, value.value, "Load initial value of StackVar");
backend.emitSW(A0, SP, 0, "Push to stack"); betterBackend.emitPush(A0, "Ident: LocalVar");
} }
} }
return null; return null;
......
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