In this final part of the project, you will implement an IC code optimizer and a simple MIPS code generator. This will be for a restricted language which does not include floats or subroutines. You will write your compiler so that it outputs MiniMIPS assembly language to the standard output instead of IC code (I had planned on having you generate the hex code, but this does not seem to be worth it in the time we have left). This code should follow the MiniMIPS language presented in the handout on the website and distributed in class.
Your project must provide the following functionality:
Action MiniMIPS Code
------ -------------
$4 = A; lw $4, 12($0)
A = $3; sw $3, 12($0)
$2 = B[2]; lw $2, 28($0)
B[A] = $5; addi $1, $0, 12
sw $5, 20($1)
Note carefully how in the last example, you must load the offset
of one of the variables into a register, and then use this as
base.
You must generate code using the method shown in class, by calculating next use information for all variables and then allocating registers using the algorithm from lecture (GetReg()).
You can proceed one of two basic ways to do this: (1) Keep your IC code generator exactly as it is, and add code to optimize your IC program, and then perform the translation into MiniMIPS, or (2) modify your IC generator so that it generates MiniMIPS code, but without registers.
I did (1), because I had some existing code to work from, but I recommend strongly that you do (2). This is not the way most books explain the phases of the compilation process, but I think it is actually the simplest thing to do for this last project. Here are the steps I suggest you follow:
IC Code MiniMIPS Code
------- -------------
move A, -, B add A, 0, B
move A, -, 4 addi A, 0, 4
add A, B, C add A, B, C
sub C, 0, A sub C, 0, A
add A, B, 4 addi A, B, 4
add A, 8, C addi A, C, 8
sub A, B, 3 addi A, B, -3
sub A, B, -2 addi A, B, 2
add A, 4, 9 addi Ti, 0, 4
addi A, Ti, 9
Any of these variables could be array references (e.g. "A[t23]") as well; the
only significant issue is where the non-zero constants appear
(only in an addi).