Review What is an activation record What are

  • Slides: 10
Download presentation
 • Review: – What is an activation record? – What are the typical

• 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.

 • Display: • An alternative to access link ( a faster method to

• Display: • An alternative to access link ( a faster method to access nonlocals ). • Using an array d of pointers to activation records, the array is called a display. – Referencing nonlocal variables always requires only two memory references. • Suppose control is in a procedure p at nesting depth j, then the first j-1 elements of the display point to the most recent activation of the procedures that lexically enclose procedure p, and d[j] points to the activation of p.

 • Setting up the display: • When a new activation record for a

• Setting up the display: • When a new activation record for a procedure at nesting depth k: – save the value of d[k] in the new activation record – set d[k] to point to the new activation record. • Example: s - > q(1, 9) S s -> q(1, 9) ->q(1, 3) proc e s->q(1, 9) ->q(1, 3) -> p(1, 3) proc q s->q(1, 9)->q(1, 3)->p(1, 3)->e(1, 3) proc p

– Parameter passing • the method to associate actual parameters with formal parameters. •

– Parameter passing • the method to associate actual parameters with formal parameters. • The parameter passing method will effect the code generated. • Call-by-value: – the actual parameters are evaluated and their r-values are passed to the called procedure. – Implementation: » a formal parameter is treated like a local name, so the storage for the formals is in the activation record of the called procedure. » The caller evaluates the actual parameters and places their r-values in the storage for the formals.

– Call-by-reference: • also called call-by address or call-by-location. • The caller passes to

– Call-by-reference: • also called call-by address or call-by-location. • The caller passes to the called procedure a pointer to the storage address of each actual parameter. – Actual parameters must have addresses -- only variables make sense, an expression will not (location of the temporary that holds the result of the expression will be passed to the routine). – Copy-restore: • A hybrid between call-by-value and call-byreference. – The actual parameters are evaluated and its r-values are passed to the called procedure as in call-by-value. – When the control returns, the r-value of the formal parameters are copied back into the l-value of the actuals.

 • Chapter 8: Intermediate Code Generation • Generating machine-independent intermediate form. – Decouple

• 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: parser Static checker Intermediate Code generator

 • Intermediate Languages: – Graphical representations: • • • Syntax tree Control flow

• 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:

• Three address code: • A sequence of statement of the form x: =y op z • Example: a: =b*-c + b * -c t 1 : = -c t 2 : = b * t 1 t 3 : = -c t 4 : = b * t 3 t 5 = t 2 + t 4 a = t 5 t 1 : = -c t 2 : = b * t 1 t 3 = t 2 + t 2 a = t 3 • Three address statements are very close to the assembly statements (OP src 1 src 2 dst)

 • Some three-address statements that will be used later: – Assignment statements: •

• Some three-address statements that will be used later: – Assignment statements: • With a binary operation: • With a unary operation: • With no operation(copy) : x : = y op z x: = op y x : = y – Branch statements • Unconditional jump: • Conditional jumps: goto L 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

– Example: instructions for procedure call: p(x 1, x 2, x 3, …, xn):

– Example: instructions for procedure call: p(x 1, x 2, x 3, …, xn): param x 1 param x 2 … param xn call p, n – Indexed assignments: • x : = y[i] and x[i] : = y – Address and pointer assignments • x : = &y, x : = *y