Skip to content
Snippets Groups Projects
Commit 6d8a1cd4 authored by Shivane Sabharwal's avatar Shivane Sabharwal
Browse files

started work on call_with_args

parent 7a1691c7
No related branches found
No related tags found
No related merge requests found
......@@ -364,6 +364,7 @@ public class CodeGenImpl extends CodeGenBase {
FuncInfo func = (FuncInfo) globalSymbols.get(callExpr.function.name);
for (Expr e : callExpr.args) {
backend.emitADDI(SP, SP, -4, "Increment stack ptr by 1");
System.out.println(e.getInferredType());
e.dispatch(this);
}
// Push parameters onto stack
......@@ -410,9 +411,21 @@ public class CodeGenImpl extends CodeGenBase {
@Override
public Void analyze(Identifier id) {
// NOT DONE
boolean argFlag = false;
int argCtr = 0;
for (String s : funcInfo.getParams()) {
if (id.name.equals(s)) {
argFlag = true;
break;
}
argCtr++;
}
SymbolInfo ident = sym.get(id.name);
// global var case
if (ident instanceof GlobalVarInfo) {
System.out.println(id.name);
if (argFlag){
int offset = argCtr * backend.getWordSize();
backend.emitLW(A0, FP, offset, "Load stack argument");
} else if (ident instanceof GlobalVarInfo) { // global var case
backend.emitLW(A0, ((GlobalVarInfo) ident).getLabel(), "Load identifier");
backend.emitSW(A0, SP, 0, "Push to stack");
} else if (ident instanceof StackVarInfo){ // local variable
......@@ -518,6 +531,7 @@ public class CodeGenImpl extends CodeGenBase {
backend.emitXOR(T0, T0, T1, "== operator on BOOL/INT");
backend.emitSEQZ(T0, T0, "Set to 1 if XOR results in 0, they were equal");
backend.emitSW(T0, SP, 0, "Push result onto stack");
return null;
}
case "!=":
......
This diff is collapsed.
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