This chapter deal with intermediate representations, static type checking,
and intermediate code generation.
We will use syntax trees and "three-address code" of the general form
x = y op z using three addresses: two for the operands y and z and one for the result x.
An address can be one of the following:
Common three-address instructions used in Text
Fig 6.8 gives two ways of assigning labels - we will use the first one.
L: t1 = i+1 i = t1 t2 = i*8 t3=a[t2] if t3 < v goto L Symbolic Labels
Example 6.6 Three-address code for the assignment a = b * -c + b * -c has its syntax tree in Fig 6.11a and its three-address code in Fig 6.10a. Note: extensive use of temporariries (t1 through t5)
p. 368 "A benefit of quadruples over triples can be seen in an optimizing compiler, where instructions are often moved around. With quadruples, if we move an instruction that computers a temporary t, then the instruction that use t require no change. With triples, the result of an operation is referred to by its position, so moving an instruction may require us to change all references to that result. This problem does not occur with indirect triples, which we consider next."
A compromise for the CS 524 course at SDSU is to avoid considerations of optimization, making our use of the Abstract Syntax Tree and triples a reasonable approach.