Project 3c: Code Generation
Due: Sunday, December 9, 2012

Description

We now have everything we need from the front end and middle to generate machine code.

In this final phase of the project, you will walk the IR from Project 3c and generate MIPS machine code that runs under MARS.

Since this is another non-trivial task to complete, I am imposing a milestone approach to the project. You must do the steps of this project in the order below. You will only be graded by the highest level that works completely (plus partial credit for the next milestone attempted.)

Milestone 1: Hello, 9

class Test {

    public static void main(String[] args) {

        System.out.println(9);

    }

}

 

No additional classes, no register allocation, no expressions. Just print 9 on the screen.

Milestone 2: Hello 5+4

class Test {

    public static void main(String[] args) {

        System.out.println(5+4);

    }

}

 

Milestone 1 plus an expression with constants. The expression can only use $t0-$t9. Abort if there are more than 9 values necessary (you do not need to implement reuse of the registers).

Milestone 3: Hello 9 with functions and parameters

class Test {

    public static void main(String[] args) {

        System.out.println(new Test2().Start(9));

    }

}

class Test2 {

    public int Start(int y) {

        return y;

    }

}

 

Call an identity function and print out the result. Note that you do not need to implement “new” yet since there are no class scope variables.

Call multiple functions with 4 or less parameters.

Milestone 4: Hello with variables

class Test {

    public static void main(String[] args) {

        System.out.println(new Test2().Start(0));

    }

}

class Test2 {

    public int Start(int y) {

        //Arbitrary straight-line code

        return y;

    }

}

 

The expressions can use all general purpose registers that are not $zero, $a0-$a3, $v0, or used in manipulating the stack ($sp, $fp). Abort if you need more. Save all registers on function call. Restore all on function return.

Milestone 5: Control Flow and Recursion

Support if and while (iftrue and goto IR statements).

Support recursive functions (probably trivial with Milestone 4 and control flow).

Milestone 6: Register Allocation, no spills, no coalescing.

Compute the liveness of the variables and use graph coloring to allocate them to the registers as in Milestone 4. Abort if a spill is required.

Precolor parameters into $a0…$a3 and return values in $v0.

Milestone 7: Register Allocation, no spills, coalescing.

Add coalescing to Milestone 7.

Milestone 8: Objects and Arrays

Create dynamic objects and arrays with new. An array of n integers will require n+1 bytes of storage. At position n+0, store the length of the array. Locations n+4 … n+4*length should hold the array data.

Milestone 9: Register Allocation, spills, calling convention

Eliminate the naïve spilling of all registers in the function prologue and epilogue.

Support spills.

Support the proper MIPS calling convention by having calls interfere with the caller-saved ($t0-$t9) registers.

Milestone 10: Optimization

Implement any optimization of your choosing. This can be something simple like strength-reduction (converting multiplications into shifts) or preferably something that reduces dynamic instruction count so that we can see the effect of the optimization in MARS. Write up what you implemented in your README and have the optimization enabled by passing -O1 to your program so we can see the differing code. Provide an example that exercises your optimization.

Submission

Since CSSD has taken away our submission site, please use SFTP to copy your zipfile to unixs.cis.pitt.edu and then copy your file to:

~jrmst106/submit/1622

 

Please remove all .class files and version control directories before submission. Make sure to name the file with both you and your partner’s username.

Do include:

·         All of the source code

·         A README

·         A Makefile

·         Examples testing each Milestone, named Milestone1.java … Milestone10.java