Storage Organization
Storage Organization
Activation Record
o Control stack is a run time stack which is used to keep track
of the live procedure activations i.e. it is used to find out the
procedures whose execution have not been completed.
o When it is called (activation begins) then the procedure
name will push on to the stack and when it returns
(activation ends) then it will popped.
o Activation record is used to manage the information needed
by a single execution of a procedure.
o An activation record is pushed into the stack when a
procedure is called and it is popped when the control returns
to the caller function.
Local Data: It holds the data that is local to the execution of the
procedure.
Storage Allocation
The different ways to allocate memory are:
Example:
1. fact (int n)
2. {
3. if (n<=1)
4. return 1;
5. else
6. return (n * fact(n-1));
7. }
8. fact (6)
Keep Watching
Implementation
The symbol table can be implemented in the unordered list if the
compiler is used to handle the small amount of data.
Operations
The symbol table provides the following operations:
Insert ()
o Insert () operation is more frequently used in the analysis
phase when the tokens are identified and names are stored
in the table.
o The insert() operation is used to insert the information in the
symbol table like the unique name occurring in the source
code.
o In the source code, the attribute for a symbol is the
information associated with that symbol. The information
contains the state, value, type and scope about the symbol.
o The insert () function takes the symbol and its value in the
form of argument.
For example:
1. int x;
lookup()
In the symbol table, lookup() operation is used to search a name.
It is used to determine:
1. lookup (symbol)
This format is varies according to the programming language.
1. int value=10;
2.
3. void sum_num()
4. {
5. int num_1;
6. int num_2;
7.
8. {
9. int num_3;
10. int num_4;
11. }
12.
13. int num_5;
14.
15. {
16. int_num 6;
17. int_num 7;
18. }
19. }
20.
21. Void sum_id
22. {
23. int id_1;
24. int id_2;
25.
26. {
27. int id_3;
28. int id_4;
29. }
30.
31. int num_5;
32. }
For example:
1. int x;
2. void f(int m) {
3. float x, y;
4. {
5. int i, j;
6. int u, v;
7. }
8. }
9. int g (int n)
10. {
11. bool t;
12. }
Fig: Symbol table organization that complies with static scope
information rules
STATIC ALLOCATION
That is, when control returns to a procedure the values of the locals are
the same as they were when control left the last time. From the type of a name,
the compiler decides the amount of storage for the name and decides where the
activation records go. At compile time, we can fill in the addresses at which the
target code can find the data it operates on.
Calling sequences:
link, and the machine status fieldsFixed length items are generally placed in
the middle. Such i the control link, the access
Items whose size may not be known early enough are placed at the end of
the activation
record. The most common example is dynamically sized array, where the
value of one of
the callee’s parameters determines the length of the array.
Ø Although top_sp has been decremented, the caller knows where the
return value is, relative to the current value of top_sp; the caller therefore
may use that value.
The run-time memory management system must deal frequently with the
allocation of space for objects, the sizes of which are not known at the compile
time, but which are local to a procedure and thus may be allocated on the stack.
The reason to prefer placing objects on the stack is that we avoid the expense of
garbage collecting their space. The same scheme works for objects of any type
if they are local to the procedure called and have a size that depends on the
parameters of the call.
HEAP ALLOCATION
Stack allocation strategy cannot be used if either of the following is possible :
1. The values of local names must be retained when an activation ends.
2. A called activation outlives the caller.