CS 6013 - Modern Compilers, Theory and Practice

Assignment 2: Intermediate Code Generation

This assignment is the first part of a multi part project to write an optimizing compiler for Minijava. We start with typechecked Minijava programs and generate programs in MiniIR 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 (miniIR).

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

java P2 < P.java > P.miniIR

should create P.miniIR in MiniIR form and is semantically equivalent to P.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 MiniIR form, you could tie the MiniIR.jj and Main.java to build a parser. To ensure that your MiniIR program is semantically equivalent to the Minijava program, you can use the MiniIR interpreter (download) to compare the output of P.java with the output of the miniIR program generated by P2; say the generated miniIR code is stored in P.miniIR, then to invoke the interpreter use: java -jar pgi.jar < P.miniIR ]. A sample Main.java can be found here.

Grading policy
Your homework will be graded for a total of 100 marks. Of these 40 marks will be for the public testcases, 20 marks for the contributed testcases and 40 marks for the TA testcases.
[ under development ]