Intermediate code generation


Many compilers first generate code for an “idealized machine”. For example, the intermediate code generated would assume that the target has an unlimited number of registers and that any register can be used for any operation. Another common assumption is that machine operations take (up to) three operands, two source and one target.

With these assumptions one generates three-address code by walking the semantic tree. Our example C instruction would produce

temp1 = inttoreal(3)
temp2 = id2 + temp1
temp3 = realtoint(temp2)
id1 = temp3

We see that three-address code can include instructions with fewer than 3 operands.

Sometimes three-address code is called quadruples because one can view the previous code sequence as

inttoreal temp1 3     --
add       temp2 id2   temp1
realtoint temp3 temp2 --
assign    id1   temp3 --

Each “quad” has the form

  operation  target source1 source2


Amrita Bagchi

Amrita Bagchi Creator

(No description available)

Suggested Creators

Amrita Bagchi