compiler design

10
COMPILER DESIGN COMPILER DESIGN RUN-TIME RUN-TIME ENVIRONMENTS ENVIRONMENTS

Upload: vsunny488

Post on 13-Nov-2014

675 views

Category:

Documents


8 download

TRANSCRIPT

Page 1: COMPILER DESIGN

COMPILER DESIGNCOMPILER DESIGN

RUN-TIME RUN-TIME ENVIRONMENTSENVIRONMENTS

Page 2: COMPILER DESIGN

Run-time mainly deals with the actions that Run-time mainly deals with the actions that must occur to implement the programmust occur to implement the program

• The allocation and deallocation of The allocation and deallocation of data objects is managed by the data objects is managed by the run-time support packagerun-time support package

• The representation of data objects The representation of data objects at run-time is determined by its at run-time is determined by its typetype

Page 3: COMPILER DESIGN

Source Language IssuesSource Language Issues

ProceduresProcedures

A A procedure definitionprocedure definition is a declaration is a declaration that, in its simplest form, associates that, in its simplest form, associates an identifier with a statement.an identifier with a statement.

identifier is the identifier is the procedure nameprocedure name & &

statement is the statement is the procedure bodyprocedure body

Page 4: COMPILER DESIGN

A Pascal pgm for reading & sorting integersA Pascal pgm for reading & sorting integers program sort(input,output);program sort(input,output); var a : array [0…10] of integer;var a : array [0…10] of integer;

procedure readarray;procedure readarray; var i: integer;var i: integer; beginbegin for i := 1 to 9 do read (a[i])for i := 1 to 9 do read (a[i]) end;end;

function partition (y, z: integer) : integer;function partition (y, z: integer) : integer; var i,j,x,v : integer;var i,j,x,v : integer; begin…begin… end;end;

procedure quicksort (m,n : integer);procedure quicksort (m,n : integer); var i : integer;var i : integer; beginbegin if( n > m) then beginif( n > m) then begin i := partition(m,n);i := partition(m,n); quicksort(m,i-1);quicksort(m,i-1);

quicksort(i+1,n);quicksort(i+1,n); endend

end;end; beginbegin

a[0] := -9999; a[10] := 9999;a[0] := -9999; a[10] := 9999; readarray;readarray; quicksort(1,9)quicksort(1,9)endend

Page 5: COMPILER DESIGN

Activation TreesActivation Trees

Assumptions about the flow of control Assumptions about the flow of control among procedures during the execution of among procedures during the execution of a program:a program:Control flows sequentiallyControl flows sequentiallyEach execution of a procedure starts at Each execution of a procedure starts at the beginning of the procedure body and the beginning of the procedure body and eventually returns control to the point eventually returns control to the point immediately following the place where the immediately following the place where the procedure was calledprocedure was called

Page 6: COMPILER DESIGN

Execution of a procedure body is referred Execution of a procedure body is referred to as an activation of the procedure to as an activation of the procedure

The “lifetime” of an activation of a The “lifetime” of an activation of a procedure is the sequence of steps b/w procedure is the sequence of steps b/w the first and last steps in the execution of the first and last steps in the execution of the procedure body including the time the procedure body including the time spent for executionspent for execution

Lifetimes are either non-overlapping or Lifetimes are either non-overlapping or nestednested

Page 7: COMPILER DESIGN

A procedure is recursive if a new A procedure is recursive if a new activation can begin before an earlier activation can begin before an earlier activation of the same procedure has activation of the same procedure has endedended

An “activation tree” is used to depict the An “activation tree” is used to depict the way control enters and leaves activationsway control enters and leaves activations

Page 8: COMPILER DESIGN

In an activation tree:In an activation tree:

Each node represents an activation of a Each node represents an activation of a procedureprocedure

The root represents the activation of the The root represents the activation of the main programmain program

The node for a is the parent of the node The node for a is the parent of the node for b iff control flows from activation a to b for b iff control flows from activation a to b

The node for a is to the left of the node for The node for a is to the left of the node for b iff the lifetime of a occurs before the b iff the lifetime of a occurs before the lifetime of blifetime of b

Page 9: COMPILER DESIGN

Output suggesting the activations of proceduresOutput suggesting the activations of procedures enter readarrayenter readarray leave readarrayleave readarray enter quicksort(1,9)enter quicksort(1,9) enter partition(1,9)enter partition(1,9) leave partition(1,9)leave partition(1,9) enter quicksort(1,3)enter quicksort(1,3)

leave quicksort(1,3)leave quicksort(1,3) enter quicksort(5,9)enter quicksort(5,9)

leave quicksort(5,9)leave quicksort(5,9) leave quicksort(1,9)leave quicksort(1,9) execution terminatedexecution terminated

Page 10: COMPILER DESIGN