



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Name: (Please print)
Put the answers on these sheets. Use additional sheets when necessary. Show how you derived your answer when applicable (this is required for full credit and helpful for partial credit). You can collect 100 points in total for this exam. A bonus question for an additional 15 points is included. If the total number of points for this exam exceed 100, the excess points are carried over to the next exams.
(1) static link (7) stack pointer (2) access link (8) control link (3) state (9) environment (4) local (10) global (5) live (11) dead (6) code motion (12) reduction in strength
(a) A transformation on a program is called if it can be performed by looking only at the statements in a basic block rather than an entire region of code. (b) An implementation of lexical scope for nested procedures is obtained by adding a pointer called to each activation record. (c) In liveness analysis, a variable is said to be if it has no next use. (d) The loop optimization called moves loop-invariant statements to the loop header. (e) In programming language semantics, the term refers to a function that maps a name to a storage location (i.e. to an `-value) and the term refers to a function that maps a storage location to the value held (i.e. to an r-value).
a := read() b := read() if a>0 goto L
L1: b := 1
a := 1 goto L
L2: c := a * b c := c + b
To determine a coloring, show the live ranges of the variables a, b, and c in the CFG, assuming that the variables are dead at the exit from the CFG Then draw the register-interference graph (conflict graph) for the variables and determine the minimum number of colors necessary to color the graph. (15 points)
program P(input, output) var n : integer; procedure Q(k : integer) procedure S(i : integer) begin ... (* body of S *) end; begin S(k) end procedure R(j : integer); var m : integer begin Q(n + m) end; begin R(n) end
(a) Program P calls R, R in turn calls Q, and Q in turn calls S. Draw the resulting stack layout with activation records. Show the arguments and local variables in each record and draw the access links. (10 points)
(b) Which variables are visible (in scope) in the body of S and how many access links must be traversed to reach the nonlocal data? (5 points) Var visible (Y/N) #links i j k n m