Run-Time Storage Organization

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

1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
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.
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
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.
Chapter 10 Implementing Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Semantics of Call and Return The subprogram call and return.
Chapter 7: Runtime Environment –Run time memory organization. We need to use memory to store: –code –static data (global variables) –dynamic data objects.
ISBN Chapter 10 Implementing Subprograms.
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,
Run-Time Environments CS308 Compiler Theory1. 2 Run-Time Environments How do we allocate the space for the generated target code and the data object of.
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.
Basic Semantics Associating meaning with language entities.
Runtime Environments. Support of Execution  Activation Tree  Control Stack  Scope  Binding of Names –Data object (values in storage) –Environment.
ISBN Chapter 10 Implementing Subprograms.
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.
國立台灣大學 資訊工程學系 薛智文 98 Spring Run Time Environments (textbook ch# 7.1–7.3 )
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.
ISBN Chapter 10 Implementing Subprograms.
Implementing Subprograms
Subprograms - implementation. Calling a subprogram  transferring control to a subprogram: save conditions in calling program pass parameters allocate.
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
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 support Jakub Yaghob
Run-Time Environments Chapter 7
Implementing Subprograms Chapter 10
Implementing Subprograms
Implementing Subprograms
Subject Name Compiler Design Subject Code: 10CS63
Implementing Subprograms
Run-time organization
Run-Time Storage Organization
Introduction to Compilers Tim Teitelbaum
Run-Time Environments
CSC 253 Lecture 8.
Implementing Subprograms
Chapter 10: Implementing Subprograms Sangho Ha
Implementing Subprograms
CSC 253 Lecture 8.
Implementing Subprograms
Run-Time Environments
Implementing Subprograms
Topic 3-b Run-Time Environment
Topic 3-a Calling Convention 1/10/2019.
UNIT V Run Time Environments.
Languages and Compilers (SProg og Oversættere)
Run Time Environments 薛智文
Runtime Environments What is in the memory?.
Implementing Subprograms
Implementing Subprograms
Chapter 10 Def: The subprogram call and return operations of
Presentation transcript:

Run-Time Storage Organization Memory locations for code are determined at compile time. Locations of static data can also be Data objects allocated at run-time. (Activation Records) Other dynamically allocated data objects at run-time. (For example, malloc area in C). Code Static Data Stack Heap

Procedure Activations Each execution of a procedure is called as its activation. Lifetime of an activation of a procedure is the sequence of the steps between the first and the last steps in the execution of that procedure (including the other procedures called by that procedure). If a and b are procedure activations, then their lifetimes are either non-overlapping or are nested. If a procedure is recursive, a new activation can begin before an earlier activation of the same procedure has ended.

Activation Records Information needed by a single execution of a procedure is managed using a contiguous block of storage called activation record. An activation record is allocated when a procedure is entered, and it is de-allocated when that procedure exited. Size of each activation record can be determined at compile time (Although the actual location of the an activation record determined at run-time). Even though the procedure has a local variable and its size depends on a parameter, its size is determined at the run time.

Activation Records (cont.) The returned value of the called procedure is returned in this field to the calling procedure. In practice, we may use a machine register for the return value. The field for actual parameters is used by the calling procedure to supply parameters to the called procedure. The optional control link points to the activation record of the caller. The optional access link is used to refer to nonlocal data held in other activation records. The field for saved machine status holds information about the state of the machine before the procedure is called. The field of local data holds data that local to an execution of a procedure.. Temporary variables is stored in the field of temporaries. return value actual parameters optional control link optional access link saved machine status local data temporaries

Activation Records (Ex1) main p a: q b: program main; procedure p; var a:real; procedure q; var b:integer; … end q; … q; end p; procedure s; var c:integer; end s; … p; s; end main; stack main p s q

Activation Records for Recursive Procedures program main; procedure p; function q(a:integer):integer; begin if (a=1) then q:=1; else q:=a+q(a-1); end q; begin q(3); end p; begin p; end main; main p q(3) a: 3 q(2) a:2 q(1) a:1

Creation of An Activation Record Who allocates an activation record of a procedure? Some part of the activation record of a procedure is created by that procedure immediately after that procedure is entered. Some part is created by the caller of that procedure before that procedure is entered. Who deallocates? Callee de-allocates the part allocated by Callee. Caller de-allocates the part allocated by Caller.

Creation of An Activation Record (cont.) return value actual parameters optional control link optional access link saved machine status local data temporaries Caller’s Activation Record Caller’s Responsibility return value actual parameters optional control link optional access link saved machine status local data temporaries Callee’s Activation Record Callee’s Responsibility

Variable Length Data Variable length data is allocated after return value actual parameters optional control link optional access link saved machine status local data pointer a pointer b temporaries array a array b Variable length data is allocated after temporaries, and there is a link to from local data to that array.

Access to Nonlocal Names Scope rules of a language determine the treatment of references to nonlocal names. Scope Rules: Lexical Scope (Static Scope) Determines the declaration that applies to a name by examining the program text alone at compile-time. Most-closely nested rule is used. Pascal, C, .. Dynamic Scope Determines the declaration that applies to a name at run-time. Lisp, APL, ...

access links in activation records, or Non Local Names A procedure may access to a nonlocal name using: access links in activation records, or displays (an efficient way to access to nonlocal names)

Access Links Access Links main access link a: q(1) i,b: program main; d: program main; var a:int; procedure p; var d:int; a:=1; end p; procedure q(i:int); var b:int; procedure s; var c:int; call p; end s; if (i<>0) then q(i-1) else s; end q; q(1); end main; Access Links

Displays An array of pointers to activation records can be used to access activation records. This array is called as displays. For each level, there will be an array entry. 1: 2: 3: Current activation record at level 1 Current activation record at level 2 Current activation record at level 3

Accessing Nonlocal Variables main access link a: p b: q c: program main; var a:int; procedure p; var b:int; call q; procedure q(); var c:int; c:=a+b; end q; end p; call p; end main;

Accessing Nonlocal Variables using Display main Old D[1] a: p Old D[2] b: q Old D[3] c: program main; var a:int; procedure p; var b:int; call q; procedure q(); var c:int; c:=a+b; end q; end p; call p; end main; D[1] D[2] D[3]