Programming Assignment #5 - Final Project



Getting Started

* Locate and install the Labs/5 project into your eclipse workspace.
* Browse this lab document to get an idea of the work you will do for this assignment.



Part I

Abstract: You will generate code for simple expressions, using Jasmin



Preparation

As was the case in Lab 4, you can use either the course-sponsored components or the solutions from your previous labs. These choices are made in CodeGenVisitor (found in the submit package), which contains comments to help you choose your own components if you wish.

Look at the documented API for the reference solution to Part I of this problem, which shows the visit(...) methods used by the reference solution to complete this assignment.

Look at the various emit methods in the CodeGenVisitor file. Those methods produce Jasmin output for your pass.

The build.xml file is more complicated than usual. Generally, you will run the build with one of the following targets:

* build (default), which generates the jmm compiler using your code generator
* run, which performs build and then runs the resulting compiler on the test files.

The result of running your compiler is the generation of one or more Jasmin assembly source files. The Jasmin assembler is then run on those files using the internal assemble target. The resulting class files are executed using the internal runJasminGeneratedClass target.



Assignment

* By interception of MethodDeclaring, emit code to define methods properly -- including static, public, etc. For this part, do not worry about the parameters (the examples have none), but you must emit the return type of the method, which can be obtained from MethodDeclaring's getType() method and then calling getTypeString() on that.

* By interception of ComputeIsh, first visit the node's children to place their results on top of the stack, and then emit code to accomplish the node's computation.

* By interception of AssignIsh, generate code for assignment statements by evaluating the right-hand side (recursive visit), and then storing the result in register 1 (ignoring, for now, the left-hand side).

After storing the result, print the following out:

  Register 1 has ....

where the .... are replaced by the integer value in register 1.

* By interception of other types of nodes, generate code for the constant and arithmetic nodes.

* The skeleton code provided in CodeGenVisitor automatically calls the method main431(), so you don't have to handle the invoke instruction.



Part II

Abstract: You will complete your code generator for a subset of Java.



Setup

For this part, you continue your work from your solution to part I. No additional setup is required.

However:

* You are not provided with a course solution for the final code generator. Continue working with your code generator from Part I and work toward a solution that handles the test files and any extra credit you wish to do.

* The build.xml file will run every test that you place in the TestFiles folder. The test files for the final project can be found in the FinalProjectTestFiles folder.

When you are ready to test a given feature, just move the corresponding test file from the FinalProjectTestFiles folder into the TestFiles folder.

Notes

You will no doubt notice some strange notation in the test files for the final project. The method calls and field acccesses are annotated so that you don't have to look in any other source or class files to determine types.

Java overloads the period symbol in references to methods, statics, and fields. Given
w.x.y.z
we can't tell whether this is some static field z in a class w.x.y, or perhaps y is a static field in class w.x and z is a field of the instance Y

To simplify matters, the notation for fields and methods is as follows:

* The period symbol is used only within a class reference. Thus, w.x.y.z is class z in package w.x.y.

* To reference a static field or method of a class, use two colons (::), so that java.lang.System::out is the System.out output stream.

* To reference a field of an instance, use ->. Thus, (obj)->a references field a using the reference obj

* Methods work the same way. To call a static method, use: java.lang.Math::abs(num).

* All references and methods also include the return type of the result, which appears after a single colon. Thus, the reference above for System.out is really

java.lang.System::out : java.io.PrintStream

and to print something using println

(java.lang.System::out : java.io.PrintStream) -> println : void ("hello")

and the absolute value method would be

java.lang.Math :: abs : int (num)

Unless you are attempting extra credit, CodeGenVisitor.java is the only file you should submit. Any extra credit must be arranged with your instructor.

Your assignment must generate correct object code for the constructs found in the project test files. These include expressions, assignment statements, if, while, return, "short-circuiting and", "short-circuiting or", "and", "or", method invocations and declarations, and field references (but not declarations).

One issue you will have to confront is how to handle Boolean-valued expressions. The Java interperter does not have a built-in notion of what a Boolean value is nor how it should be represented.



Some ideas for extra credit extensions to the compiler are as follows:

* Pre/post increment/decrement
* Floating point primitive types
* Semantic analysis: widening
* Semantic analysis: coercion to general type
* Compile == and != into .equals method calls
* Extendable primitive types
* Checking for assignment to "this" -- it's illegal
* Processing of field declarations -- the .field directive for Jasmin
* Processing of constructors
* Accurate declaration for .locals
* Emitting "short" forms for iload and aload, so that they take
one byte instead of two. For example, iload_1 instead of iload 1.
* Handling of new and constructor calls