Different Types of Intermediate Forms
1. Why IR
IR bridges front-end (many languages) and back-end (many machines): n×m → n+m translators. Must be easy to generate, optimize, and translate.
2. Main Forms
| Form | Shape | Example a=b+c |
|---|---|---|
| Three-address code (TAC) | ≤3 operands + labels | t1=b+c; a=t1 |
| Quadruples | table (op,arg1,arg2,res) | (+,b,c,t1) |
| Triples | op + refs to prior rows (no temp names) | (0) b c + referenced as (0) |
| Indirect triples | triples + order list (easy reorder) | pointer list → triples |
| SSA | each var assigned once ( with φ at joins) | x1=..; x2=φ(x1,x3) |
| Syntax tree / DAG | graphical | = with + child |
| Postfix / stack | b c + a = |
JVM-style |
3. Quadruple vs Triple
quad: (0) +,b,c,t1 | (1) =,t1,,a — temps explicit, move easy
triple: (0) b,c,+ | (1) (0),,= — no temps, but copy/optimize shifts indices
DAG shares common subexpressions (a+b twice → one node).
4. Choice
TAC/quadruples for teaching + optimization; SSA in LLVM/GCC for data-flow; stack code for JVM.
5. Exam Points
- List IR forms with example — 7 marks, very frequent.
- Quadruple vs triple vs indirect — 5 marks, very frequent.
- SSA + φ idea — 3-5 marks, frequent.