โ Compiler Design learning pathCompiler Design ยท Module 7 of 10
Intermediate code generation
Three-address code and friends.
๐ Key ideas
- Intermediate representation (IR) sits between source and machine code, making optimisation and retargeting easier.
- Three-address code has at most one operator on the right: t1 = b * c.
- Representations: quadruples, triples and indirect triples.
- Other IRs: syntax trees, DAGs, static single assignment (SSA) form, LLVM IR and JVM bytecode.
- 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