UNIT V Run Time Environments.

Slides:



Advertisements
Similar presentations
CSI 3120, Implementing subprograms, page 1 Implementing subprograms The environment in block-structured languages The structure of the activation stack.
Advertisements

CSE 5317/4305 L7: Run-Time Storage Organization1 Run-Time Storage Organization Leonidas Fegaras.
Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Chapter 5 ( ) of Programming Languages by Ravi Sethi
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Chapter 9 Subprogram Control Consider program as a tree- –Each parent calls (transfers control to) child –Parent resumes when child completes –Copy rule.
ISBN Chapter 10 Implementing Subprograms.
1 Chapter 7: Runtime Environments. int * larger (int a, int b) { if (a > b) return &a; //wrong else return &b; //wrong } int * larger (int *a, int *b)
CS 536 Spring Run-time organization Lecture 19.
ISBN Chapter 10 Implementing Subprograms.
Runtime Environments Source language issues Storage organization
Run-Time Storage Organization
1 Pertemuan 20 Run-Time Environment Matakuliah: T0174 / Teknik Kompilasi Tahun: 2005 Versi: 1/6.
Run time vs. Compile time
Semantics of Calls and Returns
Chapter 9: Subprogram Control
Run-time Environment and Program Organization
1 CSCI 360 Survey Of Programming Languages 9 – Implementing Subprograms Spring, 2008 Doug L Hoffman, PhD.
Week 8-9b spring 2002CSCI337 Organization of Prog. Lang0 A Brief Recap Subprogram benefits, basic characteristics from names to their values  names can.
Presented by Dr Ioanna Dionysiou
7/13/20151 Topic 3: Run-Time Environment Memory Model Activation Record Call Convention Storage Allocation Runtime Stack and Heap Garbage Collection.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
Compiler Construction
CSc 453 Runtime Environments Saumya Debray The University of Arizona Tucson.
Chapter 5: Programming Languages and Constructs by Ravi Sethi Activation Records Dolores Zage.
Chapter 7 Runtime Environments. Relationships between names and data objects As execution proceeds, the same name can denote different data objects Procedures,
1 Copyright © 1998 by Addison Wesley Longman, Inc. Chapter 9 Def: The subprogram call and return operations of a language are together called its subprogram.
CPSC 388 – Compiler Design and Construction Runtime Environments.
1 Run-Time Environments. 2 Procedure Activation and Lifetime A procedure is activated when called The lifetime of an activation of a procedure is the.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms What actions must take place when subprograms are called and when they terminate? –calling a subprogram has several associated.
BİL 744 Derleyici Gerçekleştirimi (Compiler Design)1 Run-Time Environments How do we allocate the space for the generated target code and the data object.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
1 Chapter 10 © 2002 by Addison Wesley Longman, Inc The General Semantics of Calls and Returns - Def: The subprogram call and return operations of.
7. Runtime Environments Zhang Zhizheng
1 Run-Time Environments Chapter 7 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
RUNTIME ENVIRONMENT AND VARIABLE BINDINGS How to manage local variables.
10-1 Chapter 10: Implementing Subprograms The General Semantics of Calls and Returns Implementing “Simple” Subprograms Implementing Subprograms with Stack-Dynamic.
Implementing Subprograms
ISBN Chapter 10 Implementing Subprograms.
Runtime Environments Chapter 7. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
Run-Time Environments Presented By: Seema Gupta 09MCA102.
Code Generation Instruction Selection Higher level instruction -> Low level instruction Register Allocation Which register to assign to hold which items?
Implementing Subprograms
Chapter 10 : Implementing Subprograms
Run-Time Environments Chapter 7
Implementing Subprograms Chapter 10
Functions.
Implementing Subprograms
Subject Name Compiler Design Subject Code: 10CS63
Implementing Subprograms
Run-time organization
Run-Time Storage Organization
Run-Time Storage Organization
Run-Time Environments
Implementing Subprograms
Chapter 10: Implementing Subprograms Sangho Ha
Implementing Subprograms
Implementing Subprograms
Run-Time Environments
Implementing Subprograms
Topic 3-a Calling Convention 1/10/2019.
Languages and Compilers (SProg og Oversættere)
Run Time Environments 薛智文
Implementing Subprograms
Implementing Subprograms
Chapter 10 Def: The subprogram call and return operations of
Presentation transcript:

UNIT V Run Time Environments

Source Language Issues A program is made up of procedures. What are the differences between the source text of a procedure and its activation at run time? 3. A procedure definition is a declaration that associates an identifier with a statement. Identifier is a procedure name The statement is the procedure body Procedures that return values are called function in many languages. Formal and actual parameters int max(int x, int y) { ……..} ------- max(m,n)

Activation Trees Assumptions about flow of control among procedures during execution of a program: Control flows sequentially Each execution of a procedure starts at the beginning of the procedure body and eventually returns to the point immediately following the place where the procedure was called. Each execution of a procedure body is referred as an activation of the procedure. Lifetime of an activation of a procedure P is the sequence of steps between the first and last steps in the execution of the procedure body, including time spent executing procedures called by P, the procedures called by them and so on. If a and b are procedure activations, then there life times are either non-overlapping or are nested. A procedure is nested if a new activation can begin before an earlier activation of the same procedure has ended.

Activation Trees (cont.) We can use activation tree 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 the activation a to b, and The node for a is left of the the node for b iff the lifetime of a occurs before the lifetime of b.

Activation Trees -Example

Control Stacks The flow of control in a program corresponds to a depth-first-traversal 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. We can use a stack, called control stack to keep track of live procedure activations. 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. When node n is at the top of the control stack, the stack contains the nodes along the path from n to the root.

Control Stacks-Example

The Scope of a Declaration A declaration is a syntactic construct that associates the information with a name. Declaration may be Explicit var i : integer Implicit Any variable name starting with I is assumed to denote an integer (Fortran) The scope rules determine which declaration of a name applies when the name appears in the text of a program. The portion of the program to which a declaration applies is called scope of that declaration. An occurrence of a name in a procedure is said to be local to the procedure if it is in the scope of a declaration within the procedure, otherwise, the occurrence is said to be non-local.

Binding of Names name storage value environment state 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. Environments and states are different; an assignment changes the state but not the environment. name storage value environment state

Storage Organization Memory Layout

Activation Records

Storage allocation strategies Static allocation – allocates storage at compile time Stack allocation - manages run time storage as stack Heap allocation – allocates and de-allocates storage area as needed at runtime

1. Static allocation name storage value environment state Limitations 1. The size of the data object and constraints on its position in memory must be known at compile time. 2. Recursive procedures are restricted, because all activations of a procedure use the same bindings for local names. 3. Data structures cannot be created dynamically, since there is no mechanism for storage allocation at run time.

2. Stack allocation

The call sequence is: A return sequence is: The caller evaluates actuals. The caller stores a return address and the old value of top_sp into the callee’s activation record. The caller the increments top_sp to the position shown in figure(d). That is, top_sp is moved past the caller’s local data and temporaries and the callee’s parameter and status fields. The callee saves register values and other status information. The callee initializes its local data and begins execution. A return sequence is: The callee places a return value next to the activation record of the caller.  Using the information in the status field, the callee restores top_sp and other registers and branches to the return address in the caller’s code.  Although top_sp has been decremented, the caller can copy the returned value into its own activation record and use it to evaluate an expression.

3. Heap allocation The stack allocation strategy cannot be used if either of the following is possible: The values of local names must be retained when activation ends. A called activation outlives the caller.

3. Heap allocation- Activation Record

Parameter Passing Call by value Call by address Copy restore