From 3511a46c262f24c89038fe7be6e7a2feae132156 Mon Sep 17 00:00:00 2001 From: Sanjar Ahmadov Date: Fri, 7 May 2021 11:52:30 -0400 Subject: [PATCH] worklog and cleanup --- WORKLOG.md | 4 +++- src/main/java/chocopy/pa3/CodeGenImpl.java | 10 +--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/WORKLOG.md b/WORKLOG.md index 6f7068f..a82ad21 100644 --- a/WORKLOG.md +++ b/WORKLOG.md @@ -15,6 +15,8 @@ - - Testing various scenarious with similarly defined variables were time consuming. Instead, we defined certain set of variables in the beginning of the student contributed test programs, and then used the same variables throughout the programs to cover various bad and good scenarious. - Another challenge was to come up with good test cases to have a broader cover. Our approach to this issue was investigating Type Checking rules and writing adverse code to those rules to see if our analyzer can make correct inferences. - + - Syncornizing the implementation was extra challening for pa3 compared to previous ones. Reason was the flexbility and freedom of the code generation step. Our RISC-V code did not need to match the one generated by reference compiler though we tried to get as close to it as we can. + - Agreeing on the common interfaces and behavior of the compiler was necessary to make synchronization easier. ## Improvements: - Added more tests to rigorously check program flow. And a test(diff.py) to show a case where our implementation showed better recoverability compared to the reference compiler. + - Added extra error state to the compiler if the actual parameter and formal parameter of the function can not resolve to a type. For example, if function expects an integer type parameter while the caller passes in a string typed param then our compiler will warn the user accordingly \ No newline at end of file diff --git a/src/main/java/chocopy/pa3/CodeGenImpl.java b/src/main/java/chocopy/pa3/CodeGenImpl.java index d13182c..f95f2b4 100644 --- a/src/main/java/chocopy/pa3/CodeGenImpl.java +++ b/src/main/java/chocopy/pa3/CodeGenImpl.java @@ -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");