Compilers and RTE
Compilers and RTE
Run-Time Environments
Introduction
In previous chapters we have studied the phases
of a compiler:
Scanning
Parsing
Static semantic analysis
These stages
Runtime Environment
1.
2.
3.
2.
3.
4.
5.
Activation Trees
1.
2.
3.
4.
If a and b are procedure activations, then there life times are either nonoverlapping or are nested.
5.
We can use activation tree to depict the way control enters and leaves
activations.
In an activation tree
main()
main()
gcd(15,10)
g(2)
gcd(10,5)
f(1)
gcd(5,0)
g(1)
g(1)
Control Stacks
1.
The flow of control in a program corresponds to a depth-firsttraversal of the activation tree that starts at the root, visits a
node before its children, and recursively visits children at each
node in a left-to-right order.
2.
3.
The idea is to push the node for an activation onto the control
stack as the activation begins and pop the node when the
activation ends.
Thus the contents of the stack are related to paths to the root
of the activation tree.
4.
5.
Explicit
Implicit
3.
4.
5.
var i : integer
Any variable name starting with I is assumed to denote an integer (Fortran)
Binding of Names
1.
2.
3.
4.
Even if each name is declared once in a program, the same name may
denote different data objects at run time.
Data object corresponds to a storage location that can hold values.
The term environment refers to a function that maps a name to a storage
location.
The term state refers to a function that maps a storage location to the
value held there.
environment
name
5.
state
storage
value
with a name
x,
2.
Static Notation
Dynamic Counterpart
Definition of a procedure
Declaration of a name
Scope of a declaration
Lifetime of a binding
Storage Organization
1.
The compiler obtains a block of storage from the operating system for the
compiled program to run in.
2.
3.
In most compiled languages, it is not possible to make changes to the code area
during execution.
4.
The code area is fixed prior to the execution, and all code addresses are
computable at compile time.
5.
The size of the some data objects may also be known at compile time, and
these too can be placed in a statically determined area.
Code Memory
Entry point for procedure 1
Entry point for procedure 2
Code for
Procedure 1
Code for
Procedure 2
.
.
Code for
Procedure n
Data Area
1.
Literal strings
Dynamic Memory
1. The memory area for the allocation of dynamic data can be
organized in many different ways.
2. A typical organization divides the dynamic memory into
stack area (LIFO protocol)
heap area
2.
3.
When control returns from the call, this activation can be restarted after
restoring the values of relevant registers and setting the program counter to
the point immediately after the call.
4.
Heap holds all other information like the data under program control i.e.
dynamic memory allocation.
By convention, stacks grow down. Heaps grow up.
5.
bookkeeping information
(return address)
local data
local temporaries
Actual parameter
Article 7.3
Self study
Best of luck
in the Exam