|
Assignment 5 (Finally! The code generating assignment) |
450 points |
| DUE: Sat Dec 12 at 5 PM PST |
In this assignment you will convert your compiler into a full code generating compiler. This is the moment we have been waiting for. Congratulations! You have created a large complex program that will compile programs! You will be able to compile a C- program and... amazingly... it will execute on the TM machine! It is so cool to see the code actually run. This was our goal at the beginning of class!
Do not be fooled. This is a nontrivial homework.
Do not put this off until you are doing end of semester projects and
studying for tests. If you get stuck ASK EARLY. Do not be in the
position of figuring out how to do it with only 24 hours to go.
To do this final stage, you will need to make modifications to the semantic section and to create a code generation section. The text below combined with what you learned in class will tell you what you will need to do to get this to work.
The results will be a C- compiler that will compile files for execution on the TM machine. The assignment will be graded by running your compiler on each test file. if there are no errors (warnings are OK) TM code will be generated. The code will then be given to the TM machine to execute. Your code running on the TM will need to produce the same behavior as my code on the TM. The TM code itself is free to be different. I have tried to not do any crazy special cases in my code so it can be used as an example. Code is supplied in the test data.
c- fred.c- -o sally.tm c- -o fred.tm -p fred.c- c- fred.c- # here the output will go to fred.tm c- < fred.c- # here the output will go to stdout
The offset and size that is used for variables goes unused for all the rest of the nodes accept the function declaration nodes. We will use the size in the function node for storing the stack frame size. This can be set on exit of the code generation for the declarations in the function. The offset in function declaration nodes will be used later for storing the starting address of the function so that it can be looked up in the symbol table and we can jump to the various functions.
If there are no errors (warnings OK), the Code Generation section will take the annotated tree, the symbol table containing the pointers to the global declaration nodes and the value of the top of the global space and generate the TM code as discussed in class. You might want to pass the size of the global space in a separate variable into the code generation code as well. You will need to know where the globals end and the function memory begins.
I will supply you with the emit code you can use to write out TM code. If you want to modify this code or do it completely differently then great. Be my guest. It is similar to the code discussed in the book so you can use the book as a reference. This is your compiler.
You will need to put the address of the start of the code for each routine as you come across the declartion during code generation. Calls can then be constructed using the address found by symbol table lookups.
ERROR(LINKER): Procedure main is not defined.
Final note: You do not need to do the short cutting AND and OR. I think I would prefer you focus on the rest of the assignment and any extra credit I may offer. We discussed this short cutting AND and OR in class and it is not difficult. I just think it is defocusing at this point. Cheers.
Homework will be submitted as an uncompressed tar file to the homework submission page. You can submit as many times as you like. The LAST file you submit BEFORE the deadline will be the one graded. For all submissions you will receive email showing how your file performed on the pre-grade tests. The grading program will use more extensive tests and those results will be mailed to when they are run.
If you have tests you really think are important or just cool please
send them to me and I will consider adding them to the test suite.
| Robert Heckendorn | Up One Level | Last updated: |