Your compiler should be invoked as follows:
% cflat -codegen sourcefile.cflat sourcefile.sIf the program passes all earlier phases of compiling -- scanning, parsing, resolving, and typechecking -- then you should print a valid assembly language program to the file specified in the third argument and exit with status zero. If some error is encountered along the way, then you must print a reasonable error and exit with status one.
Your program will need a runtime library to operate correctly. You may use this libcflat.c as a starting point. A print statement in C-Flat should result in one or more calls to the C functions print_string, print_integer, etc, depending on the type of the expression. You may add additional additional runtime calls as you see fit.
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()
{
print "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 print_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.
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.
As before, the options from the previous three projects must continue to work correctly. You must also turn in a set of test files named good[1-5].cflat and bad[1-5].cflat.
Your grade on this project will be based upon:
/afs/nd.edu/coursefa.08/cse/cse40243.01/dropbox/YOURNAME/codegen