2015-03-03 Code Generation (Ch. 5-6) Chapter 6: Intermediate-Code Generation "intermediate-code" generation, not "intermediate code generation" - emits an intermediate/internal representation (IR) directed acyclic graph (DAG) form of syntax tree - saves storage space in the presence of common subexpressions - unnecessary for our project three-address code (3AC or TAC) - maximum of three locations ("addresses") involved in each operation - name (from source code) - constant - temporary variable (compiler-generated) - at most one operator on the right side - assignment: = - simple copy - indexed assignment - single-op assignment - unary ops: - ! - binary ops: + - * / % < > <= >= && || - unconditional jump - conditional jump (single variable) - parameter passing - procedure call representation: - quadruple: (op, result, arg1, arg2) - triple: (op, arg1, arg2) - temporary result variables are given implicit names (indices) static single-assignment (SSA) form - every variable is only assigned once - basically, 3AC w/ subscripts - use φ-function to handle control flow sensitivity Ex. 6.2.1: + a - + b c 3AC: t1 = b + c t2 = -t1 t3 = a + t2 quads (t1, +, b, c ) (t2, -, t1, ) (t3, +, a, t2) triples 0: (+, b, c ) 1: (-, 0, ) 2: (+, a, 1 )