Worth 16% of your project grade
For this project, you are asked to generate the Intermediate Representation (IR) structures for every AST left out from project #5.
You need to modify the file Code.gen to handle array and record construction, array indexing, record projection, function/procedure call, and function/procedure prologue/epilogue. The frame layout will be similar to that in Section 7.2 in the notes, but function arguments are pushed in the stack from left to right. The register v0 is used in passing the static link from the caller to the callee. This is done implicitly inside the IR Call(f,sl,...). There are two different cases for the static link. Lets say that caller_level and callee_level are the nesting levels of the caller and the callee procedures (recall that the nesting level of a top-level procedure is 0, while the nesting level of a nested procedure embedded inside another procedure with nesting level n, is n+1). When the callee is lexically inside the caller's body, that is, when callee_level=caller_level+1, the static link is Reg(fp). Otherwise, we follow the static link of the caller d+1 times, where d=caller_level-callee_level (the difference between the nesting level of the caller from that of the callee). For d=0, that is, when both caller and callee are at the same level, we have Mem(Binop(PLUS,Reg(fp),Const(-8))). For d=2 we have:
You need to run your parser against all tests/*.pcat files. For example:
run 6 helloYou also need to compare your output with that of the solution:
solution 6 helloAnother test, which is optional, is to temporarily remove the Mips.gen file and run, eg.
run 7 hellothat will convert your IR code into MIPS using the solution and will run it using SPIM.
After ensuring that your program compiles and executes correctly, cleanup your pcat directory using clean
Last modified: 04/10/12 by Leonidas Fegaras