Run-Time Storage Organization 66.648 Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.

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

Prof. Necula CS 164 Lecture 141 Run-time Environments Lecture 8.
Implementing Subprograms
(1) ICS 313: Programming Language Theory Chapter 10: Implementing Subprograms.
Chapter 10 Implementing Subprograms. Copyright © 2012 Addison- Wesley. All rights reserved. 1-2 Chapter 10 Topics The General Semantics of Calls and Returns.
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.
3/17/2008Prof. Hilfinger CS 164 Lecture 231 Run-time organization Lecture 23.
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
PZ09A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09A - Activation records Programming Language Design.
ISBN Chapter 10 Implementing Subprograms –Semantics of Calls and Returns –Implementing “Simple” Subprograms –Implementing Subprograms with.
1 CSCI 360 Survey Of Programming Languages 9 – Implementing Subprograms Spring, 2008 Doug L Hoffman, PhD.
1 Run time vs. Compile time The compiler must generate code to handle issues that arise at run time Representation of various data types Procedure linkage.
Chapter 10 Implementing Subprograms. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Semantics of Call and Return The subprogram call and return.
1 Contents. 2 Run-Time Storage Organization 3 Static Allocation In many early languages, notably assembly and FORTRAN, all storage allocation is static.
Chapter 8 :: Subroutines and Control Abstraction
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.
CS 2104 Prog. Lang. Concepts Subprograms
Runtime Environments Compiler Construction Chapter 7.
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,
CPSC 388 – Compiler Design and Construction Runtime Environments.
Basic Semantics Associating meaning with language entities.
COP4020 Programming Languages Subroutines and Parameter Passing Prof. Xin Yuan.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
Programming Languages and Paradigms Imperative Programming.
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.
Runtime Organization (Chapter 6) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
國立台灣大學 資訊工程學系 薛智文 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
PZ09A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ09A - Activation records Programming Language Design.
Subprograms - implementation. Calling a subprogram  transferring control to a subprogram: save conditions in calling program pass parameters allocate.
ISBN Chapter 10 Implementing Subprograms.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Operational Semantics (Slides mainly.
1 Compiler Construction Run-time Environments,. 2 Run-Time Environments (Chapter 7) Continued: Access to No-local Names.
ISBN Chapter 10 Implementing Subprograms.
LECTURE 19 Subroutines and Parameter Passing. ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments.
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.
Implementing Subprograms
Chapter 10 : Implementing Subprograms
Run-Time Environments Chapter 7
Implementing Subprograms Chapter 10
Implementing Subprograms
Run-time organization
Run-Time Storage Organization
Run-Time Storage Organization
Procedures (Functions)
Implementing Subprograms
Implementing Subprograms
UNIT V Run Time Environments.
Run-time environments
Implementing Subprograms
Presentation transcript:

Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic

Lecture Outline Run-Time Storage Organization Run-Time Storage Organization Examples Examples Administration Administration

Run-Time Storage Organization A program obtains a single contiguous block of storage (virtual memory) from the operating system at the start of program execution. The generated code assumes a subdivision of the storage into different areas/ Code -- this area contains the generated target code for all procedures in the program. The size of this can be determined statically by the compiler/linker.

Static Data Static Data-- this area contains global data objects whose size can be determined statically at compile time. Static variables are mapped to offsets in the static data area.

Stack Stack--runtime stack of activation records reflecting the stack structure of dynamic procedure calls and returns. An activation record contains the information needed by a single procedure call. Local variables are mapped to offsets in the activation record.

Heap Heap -- used to store all other program data (data that is dynamically sized or data with lifetime pattern that cannot be represented in the run- time stack). Heap data allocation incurs more overhead than static or stack data allocation.

Languages and Storage Organization Fortran - Static Pascal - Stack/heap C Stack/Heap

Public class X { public static void main(String argsv[]) { int n; n =10; System.out.println(fib(n));} int fib(int n) { if (n==0) return 1 else if (n==1) return 1 else return(fib(n-1)+fib(n-2)); }} Activation Record

Local variables offsets are calculated depending on its size. These offsets can be computed relative to the start of the stack frame, and can be used to specify the layout of local data in the stack frame. Local variables accesses get translated to negative-valued offsets on the stack pointer. Compile Time Layout of Local Data

An access to a lexically scoped nonlocal variable gets translated to. Level-count = k indicates that the variable can be found in the kth enclosing scope. Non-Local Variable

Variable/Field of Unknown Size How do we allocate storage for a variable/ field with statically unknown size e.g. an array or an adt (abstract Data Type). By allocating storage separately (on the heap or on top of the AR on the stack) and storing a pointer to the storage in the AR.

Other Basic Concepts in Runtime Structues Call Sequence -- instruction Sequences that allocates AR for callee procedures and fills in some of the fields. Return Sequence- instruction sequence that restores machine state so that caller procedure can continue execution. Lexical scope -- Nonlocal names are resolved via static nesting. Dynamic Scope: nonlocal names are resolved by inhering name bindings (following control links)

Example

Parameter Passing Call by value -- caller places r-value for actual parameter in the storage formal parameter. Call by reference -- caller places l-value for actual parameter in the storage for formal parameter. Call by value result -- caller places r-value for the actual parameter in the storage for formal parameter and also determines the l-value of the actual parameter. On return, the current r-value of the formal parameter is copied to the l-value of the actual parameter.

Example

Comments and Feedback Project 3 is out. Please start working. PLEASE do not wait for the due date to come. We are in chapter 8. Please read that chapter and read the relevant portion of Java. Please keep studying this material and work exercises.