Intermediate Code Generation
Intermediate Code Generation
Chapter 4-B
Intermediate Code Generation
Introduction
⚫ Intermediate code is the interface between front end
and back end in a compiler
⚫ In this chapter we study intermediate representations,
static type checking and intermediate code generation
perspective.
Three address code
⚫ In a three address code there is at most one operator at
the right side of an instruction
⚫ Example:
a+a*(b-c)+(b-c)*d
+
t1 = b – c
+ * t2 = a * t1
t3 = a + t2
* t4 = t1 * d
d
t5 = t3 + t4
a -
b c
Data structures for three address
codes
⚫ Quadruples
⚫ Has four fields: op, arg1, arg2 and result
⚫ Triples
⚫ Temporaries are not used and instead references to
instructions are made
⚫ Indirect triples
⚫ In addition to triples we use a list of pointers to triples
Implementation of 3-address
• 3-address statement is an abstract form of
intermediate code
• Need a concrete form
• Records with fields for operator and operands
• Quadruples
• Triples
• Indirect triples
a := 5 + 6
c := a + 3