0% found this document useful (0 votes)
79 views

Compiler Design: Run-Time Environments

This document discusses run-time environments and activation trees in compiler design. It explains that run-time support manages allocation and deallocation of data objects and determines data representation. Procedures are declared with an identifier and body. An example Pascal program sorts integers using procedures for reading arrays, partitioning arrays, and quicksorting. Activation trees depict the flow of control between procedure activations, with nodes for each activation and the relationships between them.

Uploaded by

shashwat2010
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
79 views

Compiler Design: Run-Time Environments

This document discusses run-time environments and activation trees in compiler design. It explains that run-time support manages allocation and deallocation of data objects and determines data representation. Procedures are declared with an identifier and body. An example Pascal program sorts integers using procedures for reading arrays, partitioning arrays, and quicksorting. Activation trees depict the flow of control between procedure activations, with nodes for each activation and the relationships between them.

Uploaded by

shashwat2010
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

COMPILER DESIGN

RUN-TIME
ENVIRONMENTS

Shashwat Shriparv
[email protected]
InfinitySoft
Run-time mainly deals with the actions that
must occur to implement the program

The allocation and deallocation of


data objects is managed by the
run-time support package
The representation of data
objects at run-time is determined
by its type
Source Language Issues
Procedures
A procedure definition is a declaration
that, in its simplest form, associates
an identifier with a statement.
identifier is the procedure name &
statement is the procedure body
A Pascal pgm for reading & sorting integers
program sort(input,output);
var a : array [0…10] of integer;

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

function partition (y, z: integer) : integer;


var i,j,x,v : integer;
begin…
end;

procedure quicksort (m,n : integer);


var i : integer;
begin
if( n > m) then begin
i := partition(m,n);
quicksort(m,i-1);
quicksort(i+1,n);
end
end;
begin
a[0] := -9999; a[10] := 9999;
readarray;
quicksort(1,9)
end
Activation Trees
Assumptions about the flow of control
among procedures during the execution of
a program:
Control flows sequentially
Each execution of a procedure starts at
the beginning of the procedure body and
eventually returns control to the point
immediately following the place where the
procedure was called
Execution of a procedure body is referred
to as an activation of the procedure
The “lifetime” of an activation of a
procedure is the sequence of steps b/w
the first and last steps in the execution of
the procedure body including the time
spent for execution
Lifetimes are either non-overlapping or
nested
A procedure is recursive if a new activation
can begin before an earlier activation of
the same procedure has ended
An “activation tree” is used to depict the
way control enters and leaves activations
In an activation tree:
Each node represents an activation of a
procedure
The root represents the activation of the
main program
The node for a is the parent of the node
for b iff control flows from activation a to b
The node for a is to the left of the node for
b iff the lifetime of a occurs before the
lifetime of b
Output suggesting the activations of procedures
enter readarray
leave readarray
enter quicksort(1,9)
enter partition(1,9)
leave partition(1,9)
enter quicksort(1,3)

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

leave quicksort(5,9)
leave quicksort(1,9)
execution terminated
Shashwat Shriparv
[email protected]
InfinitySoft

You might also like