worklog and cleanup

This commit is contained in:
Sanjar Ahmadov
2021-05-07 11:52:30 -04:00
parent 47d85f8df4
commit 3511a46c26
2 changed files with 4 additions and 10 deletions
+1 -9
View File
@@ -110,15 +110,10 @@ public class CodeGenImpl extends CodeGenBase
backend.emitGlobalLabel(funcInfo.getCodeLabel());
// --- Prologue ---
// space for return address = 1
// space for control link = 1
// space for static link = 1
// space for locals = num of locals
String sizelabel = "@" + funcInfo.getFuncName()+".size";
backend.emitADDI(SP, SP, "-"+sizelabel, "Reserve space for stack frame.");
backend.emitSW(RA, SP, sizelabel+"-4", "return address");
backend.emitSW(FP, SP, sizelabel + "-8", "control link");
// if we want to add static link
backend.emitADDI(FP, SP, sizelabel, "New FP is at old SP.");
StmtAnalyzer stmtAnalyzer = new StmtAnalyzer(funcInfo);
@@ -134,10 +129,6 @@ public class CodeGenImpl extends CodeGenBase
// --- Function Body ---
// statements load all the variables that caller put on stack
// statements use fp to load the variables
// example: 0(fp) is the last variable (z) while 8(fp) is the first variable (x)
// for function with 3 params f(x, y, z)
for (Stmt stmt : funcInfo.getStatements())
{
stmt.dispatch(stmtAnalyzer);
@@ -145,6 +136,7 @@ public class CodeGenImpl extends CodeGenBase
stmtAnalyzer.emitSizeLabel();
backend.emitJ(stmtAnalyzer.epilogue, "Jump to function epilogue");
// --- Epilogue ---
backend.emitLocalLabel(stmtAnalyzer.epilogue, "Epilogue");
backend.emitLW(RA, FP, -4, "Get return address");