Why Intermediate Representation
- Machine and Language Independent version of the original source code
- The use of intermediate representation provides
- Increased abstraction
- Cleaner separation between the frontend and backend
- Adds possibilities for re-targeting/cross-compilation.
- Supports compiler optimizations.
Types of Intermediate Representation
- Trees
- Includes parse trees and abstract syntax trees
- Linear Representation
- Intermediate Representations are categorized according to where they fall between a high-level language and machine code.
- IRs close to high-level language are called ****high-level IRs
- It preserves information like
- Loop-structure, array subscripts, if-then-else statements, etc.
- They tend to reflect the source language they are compiling more than low-level IRs
- IRs close to assembly are called ****low-level IRs
- Converts the array subscripts into explicit addresses and offsets.
- Tend to reflect the target architecture very closely, often machine-dependent.
- Different Optimizations are possible at different IR levels.
Directed Acyclic Graph (DAG)
A syntax tree with more than one path from the start symbol to the terminal is called DAG.

Three Address Code (TAC)
A three-address code is a linearized representation of a syntax tree or a DAG in which explicit names correspond to the interior nodes of the graph.
A DAG and its corresponding three-address code

Three-Address Code Various Statements

Implementation of Three Address Code
IR is implemented in a data structure as objects with fields for their operators and operands.
Commonly used data structures are