The Procedure Abstraction Part I Basics

Similar documents
The Procedure Abstraction Part I: Basics

CS415 Compilers. Procedure Abstractions. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

The Procedure Abstraction

Optimizer. Defining and preserving the meaning of the program

CS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction

Run Time Environment. Activation Records Procedure Linkage Name Translation and Variable Access

Intermediate Representations & Symbol Tables

Procedure and Function Calls, Part II. Comp 412 COMP 412 FALL Chapter 6 in EaC2e. target code. source code Front End Optimizer Back End

CSE 504: Compiler Design. Runtime Environments

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention

Naming in OOLs and Storage Layout Comp 412

Implementing Subroutines. Outline [1]

Runtime Support for Algol-Like Languages Comp 412

Procedure and Object- Oriented Abstraction

Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction

Functions in MIPS. Functions in MIPS 1

Concepts Introduced in Chapter 7

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?

CA Compiler Construction

Arrays and Functions

CS356: Discussion #6 Assembly Procedures and Arrays. Marco Paolieri

Runtime management. CS Compiler Design. The procedure abstraction. The procedure abstraction. Runtime management. V.

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return

Chapter 10. Implementing Subprograms ISBN

What about Object-Oriented Languages?

Implementing Subprograms

Lecture 5. Announcements: Today: Finish up functions in MIPS

Scope, Functions, and Storage Management

System Software Assignment 1 Runtime Support for Procedures

Storage in Programs. largest. address. address

This section provides some reminders and some terminology with which you might not be familiar.

CS 480 Fall Runtime Environments. Mike Lam, Professor. (a.k.a. procedure calls and heap management)

Runtime Support for OOLs Object Records, Code Vectors, Inheritance Comp 412

1 Lexical Considerations

CS 314 Principles of Programming Languages. Lecture 13

Programming Languages: Lecture 12

Short Notes of CS201

CS201 - Introduction to Programming Glossary By

Lectures 5. Announcements: Today: Oops in Strings/pointers (example from last time) Functions in MIPS

Runtime Environments I. Basilio B. Fraguela

Compilers and computer architecture: A realistic compiler to MIPS

Machine Language Instructions Introduction. Instructions Words of a language understood by machine. Instruction set Vocabulary of the machine

Programming at different levels

Today. Putting it all together

CPS311 Lecture: Procedures Last revised 9/9/13. Objectives:

Chapter 9. Def: The subprogram call and return operations of a language are together called its subprogram linkage

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem:

CSE 230 Intermediate Programming in C and C++ Functions

Control Abstraction. Hwansoo Han

G53CMP: Lecture 14. Run-Time Organisation I. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 14 p.1/37

Chapter 9 Subroutines and Control Abstraction. June 22, 2016

CSC 2400: Computer Systems. Using the Stack for Function Calls

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13

Computer Programming

Example. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; :

This Lecture. G53CMP: Lecture 14 Run-Time Organisation I. Example: Lifetime (1) Storage Areas

Ch. 11: References & the Copy-Constructor. - continued -

Implementing Subprograms

Lexical Considerations

Subroutines. int main() { int i, j; i = 5; j = celtokel(i); i = j; return 0;}

The Software Stack: From Assembly Language to Machine Code

Module 27 Switch-case statements and Run-time storage management

Typical Runtime Layout. Tiger Runtime Environments. Example: Nested Functions. Activation Trees. code. Memory Layout

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Run-Time Data Structures

Run-time Environments

Run-time Environments

Introduction to Programming Using Java (98-388)

Implementing Procedure Calls

Chapter 10 Implementing Subprograms

Code Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.

We can emit stack-machine-style code for expressions via recursion

10. Abstract Data Types

CS510 Operating System Foundations. Jonathan Walpole

Stack Frames. September 2, Indiana University. Geoffrey Brown, Bryce Himebaugh 2015 September 2, / 15

Chapter 6 Introduction to Defining Classes

Implementing Subprograms

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

Code Generation. Lecture 12

Examining the Code. [Reading assignment: Chapter 6, pp ]

MIPS Programming. A basic rule is: try to be mechanical (that is, don't be "tricky") when you translate high-level code into assembler code.

CASE (Computer-Aided Software Engineering)

Chapter 4 Defining Classes I

3. Process Management in xv6

Today's Topics. CISC 458 Winter J.R. Cordy

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

SISTEMI EMBEDDED. Stack, Subroutine, Parameter Passing C Storage Classes and Scope. Federico Baronti Last version:

COMPILER DESIGN - RUN-TIME ENVIRONMENT

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Lecture 6: Assembly Programs

3.Constructors and Destructors. Develop cpp program to implement constructor and destructor.

Functions and Procedures

Lexical Considerations

Process Concepts. CSC400 - Operating Systems. 3. Process Concepts. J. Sumey

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Informal Semantics of Data. semantic specification names (identifiers) attributes binding declarations scope rules visibility

Generation. representation to the machine

Course Administration

Weeks 6&7: Procedures and Parameter Passing

CSC 2400: Computing Systems. X86 Assembly: Function Calls"

Transcription:

The Procedure Abstraction Part I Basics

Procedure Abstraction The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing procedures Procedures are the key to building large systems

Procedure Abstraction Issues Compile-time versus run-time behavior Finding storage for EVERYTHING and mapping names to addresses Generating code to compute addresses Interfaces with other programs, other languages, and the OS Efficiency of implementation

Where are we? Well understood Engineering Source Code Front End IR Middle End IR Back End Machine code Errors Contains more open problems and more challenges This is compilation, as opposed to parsing or translation Implementing promised behavior What defines the meaning of the program Managing target machine resources Registers, memory, issue slots, locality, power, These issues determine the quality of the compiler

The Procedure & Its Three Abstractions

The Procedure as a Name Space There is a strict constraints that each procedure must adhere to!

The Procedure: Three Abstractions

The Procedure: Three Abstractions 1. Name Environment Clean slate for writing locally visible names Local names may obscure identical, non-local names Local names cannot be seen outside

The Procedure: Three Abstractions

The Procedure: Three Abstractions 2. Control History Well defined entries & exits Mechanism to return control to caller

The Procedure: Three Abstractions

The Procedure: Three Abstractions 3. System Services Access is by procedure name & parameters Clear protection for both caller & callee Invoked procedure can ignore calling context Procedures permit a critical separation of concerns

The Procedure (Realist s View) Establishes a private context Create private storage for each procedure invocation Encapsulate information about control flow & data abstractions

The Procedure (Realist s View) Provides shared access to system-wide facilities Storage management, flow of control, interrupts Interface to input/output devices, protection facilities, timers, synchronization flags, counters,

The Procedure (Realist s View) Requires system-wide contract Conventions on memory layout, protection, resource allocation calling sequences, & error handling Must involve architecture ISA, OS, & compiler

The Procedure (Realist s View) Procedures allow us to use separate compilation Separate compilation allows us to build nontrivial programs Keeps compile times reasonable Lets multiple programmers collaborate Requires independent procedures Without separate compilation, we would not build large systems

The Procedure (Realist s View) The procedure linkage convention Agreement between compiler and OS on actions taken when a procedure/function is called. Ensures each procedure inherits valid run-time environment and that the caller s environment is restored on return Compiler generates code to ensure this happens according to agreement established by the system

The Procedure (More Abstract View) A procedure is an abstract structure constructed via software Underlying hardware directly supports little of the abstraction it understands bits, bytes, integers, reals, and addresses, but not: Entries and exits Interfaces Name space Nested scopes All these are established by a carefully-crafted system of mechanisms provided by compiler, run-time system, linker and loader, and OS

Run Time versus Compile Time These concepts are often confusing to the newcomer Linkages execute at run time Code for the linkage is emitted at compile time The linkage is designed long before either of these Compile time versus run time can be confusing to students. We will emphasize the distinction between them.

The Procedure as a Control Abstraction Procedures have well-defined control-flow The Algol-60 (Algol-Like Languages = ALLs) procedure call Invoked at a call site, with some set of actual parameters Control returns to call site, immediately after invocation

The Procedure as a Control Abstraction Procedures have well-defined control-flow The Algol-60 procedure call Invoked at a call site, with some set of actual parameters Control returns to call site, immediately after invocation s = p(10,t,u); int p(a,b,c) int a, b, c; { int d; d = q(c,b);... }

The Procedure as a Control Abstraction Procedures have well-defined control-flow The Algol-60 procedure call Invoked at a call site, with some set of actual parameters Control returns to call site, immediately after invocation s = p(10,t,u); int p(a,b,c) int a, b, c; { int d; d = q(c,b);... } int q(x,y) int x,y; { return x + y; }

The Procedure as a Control Abstraction Procedures have well-defined control-flow The Algol-60 procedure call Invoked at a call site, with some set of actual parameters Control returns to call site, immediately after invocation s = p(10,t,u); int p(a,b,c) int a, b, c; { int d; d = q(c,b);... } int q(x,y) int x,y; { return x + y; }

The Procedure as a Control Abstraction Procedures have well-defined control-flow The Algol-60 procedure call Invoked at a call site, with some set of actual parameters Control returns to call site, immediately after invocation s = p(10,t,u); int p(a,b,c) int a, b, c; { int d; d = q(c,b);... } int q(x,y) int x,y; { return x + y; }

The Procedure as a Control Abstraction Procedures have well-defined control-flow The Algol-60 procedure call Invoked at a call site, with some set of actual parameters Control returns to call site, immediately after invocation s = p(10,t,u); int p(a,b,c) int a, b, c; { int d; d = q(c,b);... } int q(x,y) int x,y; { return x + y; } Most languages allow recursion

The Procedure as a Control Abstraction Implementing procedures with this behavior Requires code to save and restore a return address Must map actual parameters to formal parameters (c x, b y) Must create storage for local variables (&, maybe, parameters) p needs space for d, a, b, & c where does this space go in recursive invocations? s = p(10,t,u); int p(a,b,c) int a, b, c; { int d; d = q(c,b);... } int q(x,y) int x,y; { return x + y; } Compiler emits code that causes all this to happen at run time

The Procedure as a Control Abstraction Implementing procedures with this behavior Must preserve p s state while q executes Strategy: Create unique location for each procedure activation Can use a stack of memory blocks to hold local storage and return addresses s = p(10,t,u); int p(a,b,c) int a, b, c; { int d; d = q(c,b);... } int q(x,y) int x,y; { return x + y; } Compiler emits code that causes all this to happen at run time