This assignment involves generating executable SPIM code from the intermediate code fragments you generated in Assignment 5. You will need all of the classes from Assginment 5 plus some new ones in /use/local/class/cs415/sp99/tiger/PROJECT6. We expect you to run your outputted SPIM codes to make sure they work. We will supply some simple test programs so you can tell what output to expect. A description of the new subdirectories and files is as follows:
Canon package is used for symplifying the intermidiate code tree produced so far . We will use only one translormation called linearize , which will transform the intermidiate code tree into a list of smaller and simpler subtrees linked in a list, which will subsequently be used for SPIM code generation.
linearize() method is called in the provided Parse/Main.java file .
A new abstract method ( implemented in
SPIM/SPIMFrame.java) has been added to the class Frame.java :
abstract public Tree.StmList procEntryExit3(Tree.StmList body);
The implementation for procEntryExit3 has been added . This method adds the prologue and epilogue of a function ( in our case only the main program ). It is called in the Parse/Main.java driver provided .
This class contains the code generation routines as suggested in book at page 215 .
Here is where you have to write code for this part of the project .
It contains
You are given some startup code which generates SPIM code for a program containing just a number . I suggest you run the project as soon as you copy it using the test1 file .
Suggestion: As we will not use register allocation , don't construct any new temporary register . You will use the following rules :
$v0register.
$t0
Example : addition will have the following code
add $v0,$v0,$t0
Hint: You will have to use the stack to save $t0 , each time you will generate code for an expression/ statement which uses it. Here is the code you have to generate for saving a register on the stack :
sw $t0,($sp) addi $sp,$sp,-4and for restoring a register:
addi $sp,$sp,4 lw $t0,($sp)
After you generate the code, run it on the SPIM to make sure it's error free.
As usual, in writing the methods in this assignment, you should proceed incrementally. We suggest first generating SPIM code for Ocelot programs consisting solely of numerical expressions with constant operands. Next add let expressions and scalar variables. Then add conditional expressions, assignments, looping statements without breaks and then breaks.
Make sure you check the errata sheet for the textbook before starting.
For organizing your cs415 work, you should create a new subdirectory for every new assignment. All assignment directories and files should be read and write protected so that only you can read or write the directory and its files.
In addition, you will need to add to your CLASSPATH in order to access the packages needed to do this, and subsequent assignments. The easiest way to do this is to add the following line to your .cshrc or .tshrc file:
#a change to access packages in cs415 setenv CLASSPATH .:/ug/s1/class/cs415/sp99/JLex/classes/:/ug/s1/class/cs415/sp99/CUP/classes/
To begin, you should create a working directory proj6 for Assignment 6 and then copy the directories contained in /usr/local/class/cs415/sp99/tiger/PROJECT6. recursively (use -R to get subdirectories) into your working directory. If you don't use your files you can start . If you use your files , read the list of modifications above and update your files appropriately.
To execute your program on input file test.tig in your
working directory using the main method in Parse.Main,
type:
java Parse.Main test.tig
We will be using tar to turn in all the packages and classes you use in this assignment, so we can see how you may have customized them. Please follow these directions:
Connect to your working directory (where your makefile is); let's assume this is proj6
Type tar cvf proj6.tar proj6
Then use the handin program we have been using to turn in the file proj6.tar
Last updated by Florin Isaila at 3:04pm
on April 15, 1999.