Release Date 13/09/2022
Deadline 25/09/2022, 23:59 hours


This assignment is the second part of a multi part project to write an optimizing compiler for Minijava. We start with type checked Minijava programs and generate programs in MircoIR format. Akin to a standard optimizing compiler, in this assignment, we will implement a module that translates programs in a high level language minijava to programs in intermediate form microIR.

Use JTB and JavaCC and write in Java one or more visitors which translate MiniJava programs to MicroIR form. Your main file should be called P2.java, if A.java contains a program to be simplified then

$ javac P2.java
$ java P2 < A.java > A.microIR

should create A.microIR in MicroIR form and is semantically equivalent to A.java. Note, your program must take input from standard input and write to standard output (so that we can use redirection).

To check that a program is in microIR form, you could tie the microIR.jj to build a parser. To ensure that your MicroIR program is semantically equivalent to the A.java program, you can use the interpreter of MicroIR download to compare the output of A.java with the output of the java program generated by your javac compiler; say the generated microIR code is stored in A.microIR, then to invoke the interpreter use: java -jar pgi.jar < A.microIR.

Note: Please do not alter the directory structure of RollN0_P2. Only edit GJDepthFirst.java and P2.java

Resources

The source files are on Github.

Get the source by cloning the entire repo:

$ git clone https://github.com/kayceesrk/cs3300_m22

If you have already cloned the repo, you can get the latest updates by:

$ cd cs3300_m22 # go to the cloned repo
$ git pull

The MiniJava grammar specification is here.

The microIR grammar specification is BNF-microIR.

The slides are available here A3_slides

Submission

Rename the folder RollN0_P2 with your roll number. For example, if your roll number is cs99b999, then the folder should be named cs99b999_P2. Remove all the .class files before submission. For example, you can do:

$ cd cs99b999_P2
$ find . -name "*.class" | xargs rm

Then produce the compressed gzip archive as follows:

$ tar cvzf cs99b999_P2.tar.gz cs99b999_P1

Submit the .tar.gz file.

Note: You should thoroughly test your code. Some sample mini java programs are provided for testing. Create positive and negative tests per feature and test your code before submission. Please ensure that there are no compilation errors. If there are compilation errors, that code will yield zero marks.