In this assignment you will start to implement code generation for Cool. You will prepare the data segment with prototype objects, dispatch tables, and constant objects (strings, integers and booleans). The real code generation part of the Cool compiler remains for PA7.
To get the assignment type
make -f /afs/cs/users/classes/cs654/assignments/PA6/Makefilein the PA6 directory of your AFS volume. This command copies a number of files to your directory, some of them with read-only permission. As usual, you should not modify files that are read-only. Please read and follow the directions in the README file.
The files that you may need to modify are:
buggy-cgen-coolc and
check-buggy-cgen that can help to check your test suite.
The bug numbers and number of bugs may change from time to time.
Many of the bugs will only be detected by a full code generator.
There will be many other files in your directory containing other pieces of the compiler. These files were described in previous handouts and are listed in the README file. The files we will collect and use to grade your assignment are the first set listed above; you should not modify any other files.
In the previous assignments, you implemented the semantic analyzer, finding errors and setting attributes needed by the code generator. Your code generator will only be invoked if the semantic analyzer finds no errors. In this case, the following table shows what attributes the semantic analyzer has set for you. This is the same table you saw in PA4 and PA5, but this time it represents things you can use, not things you must define.
| constructor or phylum | attribute | meaning |
| program | obj_class | AST for class Object |
| int_class | AST for class Integer | |
| str_class | AST for class String | |
| bool_class | AST for class Boolean | |
| class | super | AST for super class (or NULL for Object) |
| method | overrides | AST of method being overridden (or NULL) |
| return_of_class | AST for class of return type | |
| attr | of_class | AST for class of type |
| formal | of_class | AST for class of type |
| branch | of_class | AST for class of type of branch variable |
| type | symbol for type of value of expression in branch | |
| Expression | type | symbol for type of value of expression (or NoType) |
| let | of_class | AST for class of type of let variable |
| object | binding | description of variable being used |
| assign | binding | description of variable being assigned |
| dispatch | method | AST for (statically selected) method |
| static_dispatch | method | AST for method selected |
| new_ | of_class | AST for class being instantiated. |
The assembly language file, when everything is done, has the following structure:
_int_tag, _bool_tag, and
_string_tag. These labels (and the stored tag values)
are needed by the run-time system, which doesn't know
what tags are assigned to the these three basic classes.
NoGC collector: in other
words, we don't garbage collect at all.
typename method of class
Object. It is indexed by class tag.
The code ends with a definition of a main procedure that
does nothing. This label definition is used merely to satisfy
spim which otherwise complains about main being
undefined.
You will need a working lexer, parser, and semantic analyzer to test your code generator. See the README file for instructions on how to use either your own components or the components from coolc. It is wise to test your code generator with the coolc lexer, parser, and semantic analyzer at least once, because we will grade your code generator using coolc's version.
See the README file for instructions for compiling and running a compiler with your code generator. Essentially you use mycoolc6 to run your partial code generator. You will need to make sure you assign the exact same offsets, class tags, string and integer constant indices as the installed code generator. You probably should use diff to compare the output of your (partial) code generator to the installed version.
For your convenience, a command line debugging flag -c is included in the skeleton, which controls the global variable cgen_debug. Use this to control whether to print verbose output.
The file you start with has many functions in it that you will not use this assignment. You will need to use your solution to PA6 in order to do PA7, so do not delete these functions. The file also includes extra code needed for memory management even if you don't use garbage collection. Do not make any changes in this part of the code generator.
The basic stages of the code generator for this assignment are as follows: