Skip to main content
Intermediate Code
Generation
Presented By:
Anil Pokhrel
BscCSIT VI sem
Contents
• Introduction
• Features
• Why Intermediate code
• Three Address statements
• Quadruples
• Conclusion
2
Introduction
3
 Retargeting: Build a compiler for a new
machine by attaching a new code generator to
an existing front-end.
 Optimization: reuse intermediate code
optimizers in compilers for different languages
and different machines
5
Why intermediate code
6
Three address code
 Most instruction of three address code is of the
form
 a = b op c
 Example: a = b * c + 10
 The three address code will be
 t1 = b * C
 t2 = t1 + 10
 a = t2
7
Types of Three-address Statements
Assignment:
– Binary: x := y op z
– Unary: x := op y
– “op” can be any reasonable arithmetic or logic
operator
Copy:
– Simple: x := y
– Indexed: x := y[i] or x[i] := y
– Address and pointer manipulation:
• x := &y
Jump:
– Unconditional: goto L
– Conditional: if x relop y goto L1
[else goto L2
], where relop is
<,=, >, , or ≠. ≧ ≦
Quadruples
• Quadruples consists of four fields in the record
structure
• A quadruple is a record structure with four fields:
op, arg1, arg2, and result
Quadruples Examp
a := b * -c + b * -c
Conclusion
• Intermediate code is the interface between front
end and back end in a compiler
• Ideally the details of source language are
confined to the front end and the details of target
machines to the back end
References
 https://www.tutorialspoint.com/compiler_design/
compiler_design_intermediate_code_generation
s.htm
 https://www.geeksforgeeks.org/intermediate-
code-generation-in-compiler-design/
 https://www.javatpoint.com/intermediate-code
14
15