6
Intermediate Code Representation:
In the analysis-synthesis model of a compiler, the front end of a compiler translates a source
program into an independent intermediate code, then the back end of the compiler uses this
intermediate code to generate the target code (which can be understood by the machine).
The benefits of using machine independent intermediate code are:
1. Intermediate code eliminates the need of a new full compiler for every unique machine by
keeping the analysis portion same for all the compilers.
2. The second part of compiler, synthesis, is changed according to the target machine.
3. It becomes easier to apply the source code modifications to improve code performance by
applying code optimization techniques on the intermediate code.
Intermediate codes can be represented in a variety of ways and they have their own benefits.
1. High Level IR - High-level intermediate code representation is very close to the source
language itself. They can be easily generated from the source code and we can easily
apply code modifications to enhance performance. But for target machine optimization, it
is less preferred.
2. Low Level IR - This one is close to the target machine, which makes it suitable for register
and memory allocation, instruction set selection, etc. It is good for machine-dependent
optimizations.
Intermediate code can be either language specific (e.g., Byte Code for Java) or language
independent (three-address code).
• During the translation of a source program into the object code for a target machine, a
compiler may generate a middle-level language code, which is known as intermediate
code or intermediate text.
• The complexity of this code lies between the source language code and the object code.
• The intermediate code can be represented in the form of:
– Postfix notation,
– Syntax tree,
– Three-address code.
Postfix Notation:
The ordinary (infix) way of writing the sum of a and b is with operator in the middle : a + b. The
postfix notation for the same expression places the operator at the right end as ab +. In general, if