โ† Compiler Design learning path
Compiler Design ยท Module 7 of 10

Intermediate code generation

Three-address code and friends.

๐Ÿ“– Key ideas

  1. Intermediate representation (IR) sits between source and machine code, making optimisation and retargeting easier.
  2. Three-address code has at most one operator on the right: t1 = b * c.
  3. Representations: quadruples, triples and indirect triples.
  4. Other IRs: syntax trees, DAGs, static single assignment (SSA) form, LLVM IR and JVM bytecode.
  5. Boolean expressions and control flow are translated with labels and jumps.
๐Ÿ’ก Real-life example: IR is like a universal plug adapter: every language plugs in on one side and every machine on the other.
Three-address codeIR with at most three addresses per instruction
QuadrupleRecord of operator, two arguments and a result
SSA formEach variable is assigned exactly once
DAGGraph sharing common subexpressions