worklog and cleanup
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user