Homework # 7
due 2004/12/14

Typed Intermediate Code

For this assignment, you will rewrite the code generator completely to generate Java Bytecode instead of MIPS assembly. You will write the program in Java using the bytecode engineering library BCEL. I have provided the inputs to your compiler: files containing the output of the semantic analyzer. You will also need to write the basic classes in Java directly, unless you wish to generate the native methods directly from your code generator, which is neater but much more tedious.

Documentation on Java, Java Bytecode and the Bytecode Engineering Library is available from the course web page

Hints

Every Cool class $C$ should be implemented as a Java class C_$C$ in the empty package and every Cool method $m$ as c_$m$ to avoid name clashes.

Getting the Files

I have provided routines to read in the Cool AST into a set of recursive Java AST classes. You will want to add your code generation routines to each class, as you did in PA7 in CompSci 654. Each class also provides a function for dumping the AST. Finally, I provide an example of using the BCEL to create a class C_Object with a single method c_abort in it. You will need to do the rest.

The source is provided in /afs/cs.uwm.edu/users/classes/cs754/src/homework7/ as a set of Java files plus some Cool files and their attributed trees. The Cool source is provided only for reference: your code generator will start with the attributed ASTs.

To see what exists currently:


grid.cs: setenv CLASSPATH .:/afs/cs.uwm.edu/users/classes/cs754/lib/bcel-5.1.jar
grid.cs: mkdir hw7
grid.cs: cd hw7
grid.cs: cp /afs/cs.uwm.edu/users/classes/cs754/src/homework7/* .
grid.cs: javac *.java
grid.cs: javap -c C_Object
grid.cs: rm C_Object.class
grid.cs: java Example
grid.cs: javap -c C_Object
grid.cs: java ExampleTest
grid.cs: java ASTNode hello_world.atree



John Tang Boyland
2004-11-29