Review: What is an activation record? What are the typical fields in an activation record? What are the storage allocation strategies? Which program construct in C prevents the compiler from using the static allocation scheme? What do we do in a calling sequence? In a return sequence? Accessing nonlocal variables, is it a problem in static allocation scheme? Accessing nonlocal variables, how to do it in the stack allocation scheme? What is the difference with and without nested loop? How to access the non-locals with access link, how to maintain the access link.
Chapter 8: Intermediate Code Generation Generating machine-independent intermediate form. Decouple backend from frontend, facilitate retargeting Machine independent code optimizer can be applied here. Position of intermediate code generator: Intermediate Code generator Code optimizer Static checker parser Code generator
Intermediate Languages: Graphical representations: Syntax tree Control flow graph Program dependence graph (PDG) DAG (direct acyclic graph) Example: a := b* -c + b * -c
Three address code: A sequence of statement of the form x:=y op z Example: a:=b*-c + b * -c Three address statements are very close to the assembly statements (OP src1 src2 dst) t1 := -c t2 := b * t1 t3 := -c t4 := b * t3 t5 = t2 + t4 a = t5 t1 := -c t2 := b * t1 t3 = t2 + t2 a = t3
Some three-address statements that will be used later: Assignment statements: With a binary operation: x := y op z With a unary operation: x:= op y With no operation(copy) : x := y Branch statements Unconditional jump: goto L Conditional jumps: if x relop y goto L Statement for procedure calls Param x, set a parameter for a procedure call Call p, n call procedure p with n parameters Return y return from a procedure with return value y
How to choose an intermediate language to be used by the compiler? Example: instructions for procedure call: p(x1, x2, x3, …, xn): param x1 param x2 … param xn call p, n Indexed assignments: x := y[i] and x[i] := y Address and pointer assignments x := &y, x := *y How to choose an intermediate language to be used by the compiler?