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

Assign Stmt

parent 75570697
No related branches found
No related tags found
No related merge requests found
...@@ -147,3 +147,5 @@ tramp ...@@ -147,3 +147,5 @@ tramp
Session.vim Session.vim
.netrwhist .netrwhist
*~ *~
*.gi
...@@ -9,6 +9,7 @@ import java.util.Stack; ...@@ -9,6 +9,7 @@ import java.util.Stack;
import chocopy.common.analysis.SymbolTable; import chocopy.common.analysis.SymbolTable;
import chocopy.common.analysis.AbstractNodeAnalyzer; import chocopy.common.analysis.AbstractNodeAnalyzer;
import chocopy.common.analysis.types.SymbolType; import chocopy.common.analysis.types.SymbolType;
import chocopy.common.analysis.types.ValueType;
import chocopy.common.astnodes.*; import chocopy.common.astnodes.*;
import chocopy.common.codegen.*; import chocopy.common.codegen.*;
...@@ -220,7 +221,7 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -220,7 +221,7 @@ public class CodeGenImpl extends CodeGenBase {
} }
/** An analyzer that encapsulates code generation for statments. */ /** An analyzer that encapsulates code generation for statments. */
private class StmtAnalyzer extends AbstractNodeAnalyzer<Object> { private class StmtAnalyzer extends AbstractNodeAnalyzer<Void> {
/* /*
* The symbol table has all the info you need to determine * The symbol table has all the info you need to determine
* what a given identifier 'x' in the current scope is. You can * what a given identifier 'x' in the current scope is. You can
...@@ -302,7 +303,6 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -302,7 +303,6 @@ public class CodeGenImpl extends CodeGenBase {
stmt.value.dispatch(this); stmt.value.dispatch(this);
backend.emitLW(A0, SP, 0, "Load return value into A0"); backend.emitLW(A0, SP, 0, "Load return value into A0");
return null; return null;
} }
@Override @Override
...@@ -311,6 +311,51 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -311,6 +311,51 @@ public class CodeGenImpl extends CodeGenBase {
return null; return null;
} }
@Override
public Void analyze(AssignStmt node) {
node.value.dispatch(this);
RiscVBackend.Register tmpReg = /*regMgr.borrowOneTmp()*/ T6;
RiscVBackend.Register tmpReg2 = /*regMgr.borrowOneTmp()*/ T5;
betterBackend.emitPop(tmpReg, "ASSIGN: Get the value to assign: Pop the expr result from stack");
SymbolType symbolType = null;
for(Expr expr : node.targets) {
if(! (expr instanceof Identifier)) {
throw new RuntimeException("assignment target should be Identifier.");
}
SymbolInfo symbolInfo = sym.get(((Identifier) expr).name);
Label label = null;
if(symbolType == null) {
// first run:
if (symbolInfo instanceof GlobalVarInfo) {
GlobalVarInfo globalVarInfo = (GlobalVarInfo) symbolInfo;
symbolType = globalVarInfo.getVarType();
} else if (symbolInfo instanceof StackVarInfo) {
StackVarInfo stackVarInfo = (StackVarInfo) symbolInfo;
symbolType = stackVarInfo.getVarType();
}
if (symbolType.equals(SymbolType.INT_TYPE) || symbolType.equals(SymbolType.BOOL_TYPE)) {
// first run:
/*
backend.emitLW(tmpReg, tmpReg, 3 * backend.getWordSize(), "ASSIGN: Load the value of INT or BOOL");
*/
}
}
// do assign
if (symbolInfo instanceof GlobalVarInfo) {
GlobalVarInfo globalVarInfo = (GlobalVarInfo) symbolInfo;
symbolType = globalVarInfo.getVarType();
backend.emitSW(tmpReg, globalVarInfo.getLabel(), tmpReg2, "ASSIGN: Assign to global var");
} else if (symbolInfo instanceof StackVarInfo) {
StackVarInfo stackVarInfo = (StackVarInfo) symbolInfo;
symbolType = stackVarInfo.getVarType();
throw new RuntimeException("ASSIGN to stack variable: NOT IMPLEMENTED: StackVarInfo not implemented.");
}
}
return null;
}
@Override @Override
public Void analyze(CallExpr callExpr) { public Void analyze(CallExpr callExpr) {
...@@ -485,10 +530,6 @@ public class CodeGenImpl extends CodeGenBase { ...@@ -485,10 +530,6 @@ public class CodeGenImpl extends CodeGenBase {
} }
@Override
public Void analyze(AssignStmt assignStmt) {
return null;
}
// FIXME: More, of course. // FIXME: More, of course.
} }
......
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