$29
Objective: To enhance your mini compiler with code generation capabilities (This is an extension to Lab #9)
A simple code generator: Consider the intermediate code instructions containing just arithmetic expressions, containing operators valid arithmetic operators from C language, and generate the equivalent MIPS machine code. You use any naive approach. Your program has to take any valid arithmetic expression written in C language as input through a file and then display
1. The equivalent three address code
2. The equivalent MIPS code
You have already done part 1 as your Lab #9. You need to extend the same to generate the MIPS code.
Input : Blocks of C variable declarations and statements containing arithmetic expressions.
Output: three address code and then MIPS code
Execusion: $./minicc prog.c
Input:
{
i n t a , d ;
{
i n t b , c ;
d = a + b + c ;
}
}
Output:
t 0 = b + c
• = a + t 0
LD R0 , b
LD R1 , c
ADD R0, R0, R1
ST t0 , R0
LD R0 , t 0
LD R1 , a
ADD R0, R0, R1
ST d , R0
Note: You may simplify your approach wherever needed.