Your compiler should be invoked as follows:
% cflat filename.cflat filename.sObviously, filename.cflat is the input file, and filename.s is the output assembly file. It's ok if the compiler prints some information on the standard output as it goes; we will only look at the output assembly code.
The most important requirement is simply that the output code should work correctly. It need not be optimal, it need not be pretty, it need not be simple, but it must work correctly. You may use a simple non-spilling register allocator; it's ok if the compiler stops with an "out of registers" error message on really complicated expressions.
You should start implementing the code generator by using what you submitted as the solution for project 3. For the final project, you may assume that the input C-Flat code is correct, so if your semantic checker isn't perfect, you won't lose points on project 4. It's quite possible that this final stage of the project will require you do go back and make a few changes to earlier stages. For example, you will discover that to properly handle string constants in the middle of expressions:
int main()
{
write_string("hello");
}
You must first define a global string with an anonymous name like .S0 and then emit it at the top of the program:
.data
.S0:
.string "hello"
.text
.global main
main:
pushl %ebp
movl %esp, %ebp
pushl $.LS0
call write_string
leave
ret
To make this work, you will have to create a table of immediate
strings in the semantic checking phase. You will certainly
find other examples of this problem.
An extra credit attempt for this project should be documented in a file called EXTRA.codegen at the root of your submitted project package. The documentation should explain what has been done to extend/enhance the project and how to go about testing this claim. The submitted package should also contain any test code if required by the nature of the extension/improvement.