In this assignment you will implement a code generator that generates MIPS assembly language for a Decaf program. The assembly code your compiler generates will be run on the SPIM simulator. SPIM simulates the MIPS machine architecture.
In addition to generating assembly code for a Decaf program, your compiler is also responsible for generating assembly code that creates a runtime environment for the Decaf program. This runtime environment includes:
If a Decaf program contains no errors, your Decaf compiler should place the compiled program in a file named a.out; otherwise, it should generate an appropriate set of error messages.
When the a.out file is run in the SPIM simulator, the output should consist of
Compiled Decaf programs should not crash. Instead, they should exit gracefully with an error message. If you are unable to fully implement the assignment, then your compiler should not generate the a.out file and a message should be printed indicating that the feature is unimplemented. Please do not allow your compiler to produce segmentation faults!
You should do all your developement within a single directory. When you are ready to submit the assignment, copy the contents of this directory to a new directory named DECAF_COMPILER_FINAL under your home directory. Provide a make file so that I need only run make to build your compiler. Everything should be present in that directory to build a working compiler. The executable should be named decafc. It should be possible to execute this program on a Decaf source file using the command
decafc < filename
Include a file named README describing any limitations of your compiler. It is better to say a feature is not implemented than to have it fail while testing. Decaf programs that exercise a documented unimplemented feature of your compiler will be avoided while testing your compiler.
Your compiler will be tested against a variety of test files.
Points will be awarded based on the level of functionality exhibited by your compiler. The levels are described below.
class MyMain { void main() { print(2); // Prints 2 followed by a space print(-45); // Prints -45 followed by a space print(); // Prints a newline } }At this level you need not worry about parameter passing, argument lists, significant stack management (parameters, locals, return address), objects, expressions, and control flow statements. Eventually you must be able to use argument lists with print, but here you'll find it easy to pass a single argument to print without using the stack.
class MyMain { void main() { int x; int y; x = 10; y = 2; print((x - 2) * 2); print(x + y); } }At this level you'll need to address stack mangement (for local variables and temporaries) and deal with arithmetic expressions.
class MyMain { int f(int i) { return i + 4; } void g(int a, int b) { int x; x = 2; print(x + a); } void main() { int x; int y; x = 10; y = 2; print((x - 2) * 2, 3, x + 2); print(x + y); x = f(x + y); g(y - 7, 2); g(f(4) - f(x), x + 10); } }At this level you'll need to enhance your stack mangement to include method return addresses, return values, and parameters. Your program may have more than one stack frame active at any given time.
The possible number of points for this assignment is 10. Points are based upon the highest level achieved:
Level 1 | See above | 3 |
Level 2 | See above | 5 |
Level 3 | See above | 6 |
Level 4 | All the Level 3 stuff plus control statements if, while and relational operators |
7 |
Level 5 | All the Level 4 stuff plus multiple classes, multiple objects, and instance variables |
8 |
Level 6 | All the Level 5 stuff plus arrays | 9 |
Level 7 | Generates executable MIPS assembly code for all correct Decaf programs |
10 |
Important! Even if you have implemented portions of functionality at higher levels, your grade is based on the highest level achieved with complete functionality at that level. Complete functionality at a given level requires complete functionality of all levels below that level.
Your strategy should be to quickly produce a Level 1-compliant compiler, then build a Level 2-compilant compiler, etc. until you have a complete Decaf compiler. You should not attempt to produce a Level-n compiler until you have a correct and complete Level-(n-1) compiler.