0% found this document useful (0 votes)
39 views8 pages

CD - Chapter - 7 (Run Time Environments)

The document discusses run-time environments in compiler design, focusing on stack allocation of space and activation records. It explains how stack frames store local variables, return addresses, and parameters, and details access to non-local data in nested procedures. Additionally, it covers storage allocation techniques, including static, stack, and heap allocation methods.

Uploaded by

Priyanshu Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views8 pages

CD - Chapter - 7 (Run Time Environments)

The document discusses run-time environments in compiler design, focusing on stack allocation of space and activation records. It explains how stack frames store local variables, return addresses, and parameters, and details access to non-local data in nested procedures. Additionally, it covers storage allocation techniques, including static, stack, and heap allocation methods.

Uploaded by

Priyanshu Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

COMPILER DESIGN

SUBJECT CODE:303105349
Ami sachin Shah, Assistant Professor
Computer Science & Engineering
CHAPTER-7
RUN TIME ENVIRONMENTS
Contents

• Stack allocation of space


• activation records Access to non-local data on the stack in the case of
procedures with and without nesting of procedures.
STACK ALLOCATION OF SPACE
What is a Run-Time Environment?
The run-time environment is the structure that supports the execution of a program.
It manages memory, handles function calls, and provides access to variables and resources.

Stack Allocation of Space


When a function is called, a "stack frame" or "activation record" is created.
This stack frame stores:
• Local variables
• Return address (where to go after the function finishes)
• Parameters passed to the function
• Saved registers (to restore previous state)
Activation Records

.
An activation record is a block of memory for a function call. It contains:

• Return address → Where to continue after the function returns.


• Control link → Pointer to the previous activation record.
• Access link → Pointer to access non-local variables (if nested
procedures).
• Parameters → Arguments passed to the function.
• Local variables → Variables declared inside the function.
Access to Non-Local Data

Without nested procedures: Functions only access their own variables or global variable
With nested procedures: Inner functions may need access to variables in outer
functions.
void outer() {
int x = 10;
void inner() {
printf("%d", x); // Accessing x from outer function
}
}
The access link in the stack frame points to the outer function’s frame, allowing inner to access x.
STORAGE ALLOCATION TECHNIQUES

Storage allocation at runtime is essential for managing memory efficiently. The main techniques include:
• Static Allocation:
•Memory is assigned before execution and remains fixed.
•Used for global variables and constants.
•Example: int x = 10; (allocated before execution).

• Stack Allocation:
Memory is allocated and deallocated dynamically in a stack (LIFO order).
Used for function calls, local variables, and activation records.
Example: A function call pushes data onto the stack, and when it returns, the data is popped.
STORAGE ALLOCATION TECHNIQUES

Heap Allocation:
•Memory is allocated dynamically at runtime and remains until manually freed.
•Used for dynamic data structures like linked lists and trees.
•Example: int *ptr = (int*)malloc(sizeof(int)); in C.

You might also like