Runtime Environments in Compiler Design
Runtime Environments in Compiler Design
Activation Tree
The node for procedure ‘x’ is the parent of node for procedure ‘y’ if
and only if the control flows from procedure x to procedure y.
main() {
Int n;
readarray();
quicksort(1,n);
}
quicksort(int m, int n) {
Int i= partition(m,n);
quicksort(m,i-1);
quicksort(i+1,n);
}
First main function as the root then main calls readarray and quicksort.
Quicksort in turn calls partition and quicksort again. The flow of control in
a program corresponds to a pre-order depth-first traversal of the
activation tree which starts at the root.
Control stack or runtime stack is used to keep track of the live procedure
activations i.e the procedures whose execution have not been completed.
A procedure name is pushed on to the stack when it is called (activation
begins) and it is popped when it returns (activation ends). Information
needed by a single execution of a procedure is managed using an
activation record or frame. When a procedure is called, an activation
record is pushed into the stack and as soon as the control returns to the
caller function the activation record is popped.
A general activation record consists of the following things:
Local variables: hold the data that is local to the execution of the
procedure.
Actual parameters
Control stack for the above quicksort example:
The names are bound with the storage at compiler time only and hence
every time procedure is invoked its names are bound to the same storage
location only So values of local names can be retained across activations
of a procedure. Here compiler can decide where the activation records go
with respect to the target code and can also fill the addresses in the target
code for the data it operates on.
Recursion is supported.
Basic terminology :
R- value: The value of an expression is called its r-value. The value
contained in a single variable also becomes an r-value if its appear
on the right side of the assignment operator. R-value can always be
assigned to some other variable.
C++
Explain
#include <iostream>
{
/* A hybrid between call-by-value and call-by-reference
copy_b = b;
copy_a = copy_b;
copy_b = temp;
b = copy_b;
int main()
swap(a, b);
return 0;
Disadvantages: