Changed variable name and fixed indentation

master
Apoorva Ranade 4 years ago
parent aed2114af0
commit 748b42fc53

@ -148,20 +148,20 @@ public class CodeGenImpl extends CodeGenBase
/** Label of code that exits from block. */
protected Label elseBlock;
/** Variable to keep track of offsets of stored variables */
private Map<SymbolInfo, Integer> offsetMap = new HashMap<>();
private final String size_label;
/** Variable to store offset from frame pointer to identify next
* empty space on stack frame to store variable*/
private int offset = 3;
private Map<SymbolInfo, Integer> offsetMap = new HashMap<>();
private int sp_off;
/** Variable to store maximum possible offset depending on stack size.*/
private int max_sp;
/**
* An analyzer for the function described by FUNCINFO0, which is null for the
* top level.
*/
private final String size_label;
private int sp_off, max_sp;
/** Variable to store offset from frame pointer to identify next
* empty space on stack frame to store variable*/
/** An analyzer for the function described by FUNCINFO0, which is null for the top level. */
StmtAnalyzer(FuncInfo funcInfo0) {
funcInfo = funcInfo0;
if (funcInfo == null) {
@ -314,11 +314,11 @@ public class CodeGenImpl extends CodeGenBase
public Register analyze(BinaryExpr node)
{
node.left.dispatch(this);
backend.emitSW(Register.A0, Register.FP, -offset*4, "Push on stack slot "+offset);
offset++;
backend.emitSW(Register.A0, Register.FP, -sp_off*wordSize, "Push on stack slot "+sp_off);
sp_off++;
node.right.dispatch(this);
offset--;
backend.emitLW(Register.T0, Register.FP, -offset*4, "Pop stack slot "+offset);
sp_off--;
backend.emitLW(Register.T0, Register.FP, -sp_off*wordSize, "Pop stack slot "+sp_off);
// Arithmetic Operators
if(node.operator.equals("+"))
backend.emitADD(Register.A0, Register.A0, Register.T0, "Add operation");
@ -361,7 +361,7 @@ public class CodeGenImpl extends CodeGenBase
node.operand.dispatch(this);
if(node.operator.equals("-"))
{
backend.emitLI(Register.T0, -1, "Set value of Registr T0 to -1");
backend.emitLI(Register.T0, -1, "Set value of Register T0 to -1");
backend.emitMUL(Register.A0, Register.A0, Register.T0, "Multiply by -1");
}
return Register.A0;
@ -388,9 +388,9 @@ public class CodeGenImpl extends CodeGenBase
{
StackVarInfo svi = (StackVarInfo) sym.get(node.var.identifier.name);
node.value.dispatch(this);
backend.emitSW(Register.A0, Register.FP, -offset*4, "Store variable "+node.var.identifier.name+" value in Stack");
offsetMap.put(svi, offset);
offset++;
backend.emitSW(Register.A0, Register.FP, -sp_off*wordSize, "Store variable "+node.var.identifier.name+" value in Stack");
offsetMap.put(svi, sp_off);
sp_off++;
return null;
}
@ -414,14 +414,14 @@ public class CodeGenImpl extends CodeGenBase
for(Expr exp:node.elements)
{
Register r = exp.dispatch(this);
backend.emitSW(r,Register.FP,-offset*4,"Push argument "+i+" from last.");
offset++;
backend.emitSW(r,Register.FP,-sp_off*wordSize,"Push argument "+i+" from last.");
sp_off++;
i--;
}
backend.emitLI(Register.A0, l, "Pass list length");
backend.emitSW(Register.A0, Register.FP, -offset*4, "Push argument "+i+" from last.");
offset++;
backend.emitADDI(Register.SP, Register.SP, -offset*4, "Set SP to last argument.");
backend.emitSW(Register.A0, Register.FP, -sp_off*wordSize, "Push argument "+i+" from last.");
sp_off++;
backend.emitADDI(Register.SP, Register.SP, -sp_off*wordSize, "Set SP to last argument.");
//TODO: Store reference to variable
return Register.A0;
}
@ -445,13 +445,15 @@ public class CodeGenImpl extends CodeGenBase
@Override
public Register analyze(IndexExpr node) {
public Register analyze(IndexExpr node)
{
System.out.println(node);
return defaultAction(node);
}
public Register analyze(MemberExpr node) {
public Register analyze(MemberExpr node)
{
ClassInfo objectClass = (ClassInfo) globalSymbols.get(node.object.getInferredType().className());
Label label = generateLocalLabel();
Register obj = node.object.dispatch(this);
@ -464,7 +466,8 @@ public class CodeGenImpl extends CodeGenBase
return A0;
}
public Register analyze(MethodCallExpr node) {
public Register analyze(MethodCallExpr node)
{
Register obj = node.method.object.dispatch(this);
int n_args = node.args.size();
@ -495,14 +498,11 @@ public class CodeGenImpl extends CodeGenBase
public Register analyze(ReturnStmt node) {
public Register analyze(ReturnStmt node)
{
return null;
}
// FIXME: More, of course.
}
/**

Loading…
Cancel
Save