CS 370 Lab #9: Intermediate Code Templates

You need to generate intermediate code for many C operators and statements. This is a big job. But if you have completed the last lab, and you have a set of rules for what code to generate for each operator and statement, the coding is mainly just a bunch of printf's and link list concatenations. So in this lab, you should write down what 3-address code corresponds to each part of C, starting with stuff from lecture. When you don't know what instructions correspond to a given C construct, you should ask about it.

Notes: For each thing on this list, is there an instruction to do the computation? Can a combination of 2 or more 3-address instructions do it? Or shall we write a runtime library function to do the work? For everything in cgram.y that's not in this list: you should generate a semantic error: ANSI C feature not implemented.

C feature Example    3-address equivalent   Notes
int lit3

generate "immediate" value in instruction
string lit"hi"

allocate from const region; no code
x

allocate from global region; no code
a[ i ]

are we assigning, or reading its value?
+ x + y
add L:12,G:24,G:28
L:12 is a temp variable
x - y

x * y

x / y

-x

unary "negation"
( i )

i == j

i != j

i <= j

i < j

i >= j

i > j

x = 5

f()

return x

if (expr) ...

if (expr) ... else ...