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

reconstruct done

parent e77ef040
No related branches found
No related tags found
No related merge requests found
......@@ -39,11 +39,15 @@ public class CodeGenImpl extends CodeGenBase {
}
public void emitPush(RiscVBackend.Register reg, String comment) {
if(comment == null) comment = "";
comment = "PUSH: " + comment;
backend.emitADDI(SP, SP, -1 * backend.getWordSize(), comment);
backend.emitSW(reg, SP, 0, comment);
}
public void emitPop(RiscVBackend.Register reg, String comment) {
if(comment == null) comment = "";
comment = "POP: " + comment;
if (reg != null)
backend.emitLW(reg, SP, 0, comment);
backend.emitADDI(SP, SP, backend.getWordSize(), comment);
......@@ -491,9 +495,7 @@ public class CodeGenImpl extends CodeGenBase {
switch (binaryExpr.operator) {
case "+":
if (binaryExpr.left.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -504,9 +506,7 @@ public class CodeGenImpl extends CodeGenBase {
}
case "-":
if (binaryExpr.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -517,9 +517,7 @@ public class CodeGenImpl extends CodeGenBase {
}
case "*":
if (binaryExpr.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -530,9 +528,7 @@ public class CodeGenImpl extends CodeGenBase {
}
case "//":
if (binaryExpr.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -543,9 +539,7 @@ public class CodeGenImpl extends CodeGenBase {
}
case "%":
if (binaryExpr.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -557,9 +551,7 @@ public class CodeGenImpl extends CodeGenBase {
case "==":
if (binaryExpr.getInferredType().equals(SymbolType.BOOL_TYPE) ||
binaryExpr.getInferredType().equals(SymbolType.INT_TYPE) ) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -573,9 +565,7 @@ public class CodeGenImpl extends CodeGenBase {
case "!=":
if (binaryExpr.getInferredType().equals(SymbolType.BOOL_TYPE) ||
binaryExpr.getInferredType().equals(SymbolType.INT_TYPE) ) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -589,9 +579,7 @@ public class CodeGenImpl extends CodeGenBase {
}
case "<=":
if (binaryExpr.left.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -603,9 +591,7 @@ public class CodeGenImpl extends CodeGenBase {
}
case ">=":
if (binaryExpr.left.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -617,9 +603,7 @@ public class CodeGenImpl extends CodeGenBase {
}
case "<":
if (binaryExpr.left.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -630,9 +614,7 @@ public class CodeGenImpl extends CodeGenBase {
}
case ">":
if (binaryExpr.left.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
betterBackend.emitPop(T1, "Load operand 1 into t1");
......@@ -643,13 +625,11 @@ public class CodeGenImpl extends CodeGenBase {
}
case "and":
if (binaryExpr.getInferredType().equals(SymbolType.BOOL_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
betterBackend.emitPop(T1, "Load operand 1 into t1");
Label skipSecond = generateLocalLabel();
backend.emitBEQZ(T1, skipSecond, "If operand 1 is FALSE, don't eval second");
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
backend.emitAND(T1, T1, T0, "AND operands");
......@@ -659,13 +639,11 @@ public class CodeGenImpl extends CodeGenBase {
}
case "or":
if (binaryExpr.getInferredType().equals(SymbolType.BOOL_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
binaryExpr.left.dispatch(this);
betterBackend.emitPop(T0, "Load operand 1 into t0");
Label skipSecond = generateLocalLabel();
backend.emitBNEZ(T0, skipSecond, "If first is not zero (it's true), skip second");
backend.emitADDI(SP, SP, -4, "Increment stack ptr for second operand");
binaryExpr.right.dispatch(this);
betterBackend.emitPop(T0, "Load operand 2 into t0");
backend.emitOR(T0, T1, T0, "OR operands");
......@@ -683,7 +661,6 @@ public class CodeGenImpl extends CodeGenBase {
switch (unaryExpr.operator) {
case "-":
if (unaryExpr.getInferredType().equals(SymbolType.INT_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
unaryExpr.operand.dispatch(this);
betterBackend.emitPop(T0, "Load operand into t0");
......@@ -693,7 +670,6 @@ public class CodeGenImpl extends CodeGenBase {
}
case "not":
if (unaryExpr.getInferredType().equals(SymbolType.BOOL_TYPE)) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr for first operand");
unaryExpr.operand.dispatch(this);
betterBackend.emitPop(T0, "Load operand into t0");
......
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