The Procedure Abstraction

Size: px
Start display at page:

Download "The Procedure Abstraction"

Transcription

1 The Procedure Abstraction

2 Procedure Abstraction Begins Chapter 6 in EAC The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing procedures 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

3 The Procedure & Its Three Abstractions

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

5 The Procedure & Its Three Abstractions

6 The Procedure & Its Three Abstractions

7 The Procedure & Its Three Abstractions

8 The Procedure: Three Abstractions Control Abstraction Well defined entries & exits Mechanism to return control to caller Clean Name Space Clean slate for writing locally visible names Local names may obscure identical, non-local names Local names cannot be seen outside External Interface 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

9 The Procedure (Realist s View) Procedures are the key to building large systems Requires system-wide contract Conventions on memory layout, protection, resource allocation calling sequences, & error handling Must involve architecture (ISA), OS, & compiler Provides shared access to system-wide facilities Storage management, flow of control, interrupts Interface to input/output devices, protection facilities, timers, synchronization flags, counters, Establishes a private context Create private storage for each procedure invocation Encapsulate information about control flow & data abstractions

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

11 The Procedure (Realist s View) The procedure linkage convention Ensures that each procedure inherits a valid runtime environment and that the callers environment is restored on return The compiler must generate code to ensure this happens according to conventions established by the system

12 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 Call and return mechanisms may be a special instruction to save context at point of call Name space Nested scopes All these are established by a carefully-crafted system of mechanisms provided by compiler, runtime system, linker and loader, and OS

13 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 CISC672 students. We will emphasize the distinction between them.

14 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

15 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);...

16 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;

17 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;

18 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;

19 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

20 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 (&, maybe, 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

21 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

22 The Procedure as a Name Space Why introduce lexical scoping? Provides a compile-time mechanism for binding variables Simplifies rules for naming & resolves conflicts Lets the programmer introduce local names How can the compiler keep track of all those names? The Problem At point p, which declaration of x is current? At run-time, where is x found? As parser goes in & out of scopes, how does it delete x? The Answer The compiler must model the name space Lexically scoped symbol tables (see 5.7.3)

23 Lexically-scoped Symbol Tables 5.7 in EaC The problem The compiler needs a distinct record for each declaration Nested lexical scopes admit duplicate declarations The interface insert(name, level ) creates record for name at level lookup(name, level ) returns pointer or index delete(level ) removes all names declared at level Many implementation schemes have been proposed We ll stay at the conceptual level Hash table implementation is tricky and detailed (see B.4) Symbol tables are compile-time structures the compiler use to resolve references to names. We ll see the corresponding run-time structures that are used to establish addressability later.

24 Example procedure p { int a, b, c procedure q { int v, b, x, w procedure r { int x, y, z. procedure s { int x, a, v r s q B0: { int a, b, c B1: { int v, b, x, w B2: { int x, y, z. B3: { int x, a, v

25 Lexically-scoped Symbol Tables High-level idea Create a new table for each scope Chain them together for lookup Sheaf of tables implementation insert() may need to create table it always inserts at current level lookup() walks chain of tables & returns first occurrence of name delete() throws away table for level p, if it is top table in the chain If the compiler must preserve the table (for, say, the debugger ), this idea is actually practical. Individual tables can be hash tables.

26 The Procedure as an External Interface OS needs a way to start the program s execution Programmer needs a way to indicate where it begins The main procedure in most languaages When user invokes grep at a command line OS finds the executable OS creates a process and arranges for it to run grep grep is code from the compiler, linked with run-time system Starts the run-time environment & calls main After main, it shuts down run-time environment & returns When grep needs system services It makes a system call, such as fopen() UNIX/Linux specific discussion

27 The Procedure as an External Interface OS needs a way to start the program s execution > grep foo hello.txt main function here foo and hello.txt here C o d e S G t l a & o t b i a c l H e a p 0 high grep running in memory S t a c k

28 The Procedure as an External Interface Grep may call fopen with hello.txt main function foo and hello.txt in main s activiation record S G S C t l H t o a & o e a d t b a c e i a p k c l 0 high grep running in memory on stack of ARs fopen main AR of fopen AR of main

29 Where Do All These Variables Go? Local Keep them in the procedure activation record or in a register Automatic lifetime matches procedure s lifetime Static File scope storage area affixed with file name Lifetime is entire execution Global One or more named global data areas One per variable, or per file, or per program, Lifetime is entire execution

30 Placing Run-time Data Structures Classic Organization C o d e S G t l a & o t b i a c l H e a p 0 high Single Logical Address Space S t a c k Code, static, & global data have known size Heap & stack both grow & shrink over time This is a virtual address space

31 How Does This Really Work? The Big Picture Compiler s view virtual address spaces C o d e S G t l a & o t b i a c l H e a p S t a c k C o d e S G t l a & o t b i a c l H e a p S t a c k C o d e S G t l a & o t b i a c l H e a p S t a c k... C o d e S G t l a & o t b i a c l H e a p S t a c k OS s view... 0 high Hardware s view Physical address space_

32 Where Do Local Variables Live? A Simplistic model Allocate a data area for each distinct scope Need a data area per invocation (or activation) of a scope We call this the scope s activation record The compiler can also store control information there! Top of Stack parameters register save area return value return address Second Function First Function local variables parameters register save area return value return address local variables

33 Variable-length Data B0: { int a, b int v(a), c, x int z, y(8). Arrays If size is fixed at compile time, store in fixed-length data area If size is variable, store descriptor in fixed length area, with pointer to variable length area Variable-length data area is assigned at the end of the fixed length area for block in which it is allocated a b v c x z y(8) v(a) Includes variable length data for all blocks in the procedure Variable-length data

34 Activation Record Basics TOS parameters register save area return value return address local variables Space for parameters to the current routine Saved register contents If function, space for return value Address to resume caller Space for local values & variables (including spills) One AR for each invocation of a procedure

35 Activation Record Details Where do activation records live? If lifetime of AR matches lifetime of invocation, AND If code normally executes a return Keep ARs on a stack C o d e S G t l a & o t b i a c l H e a p S t a c k If a procedure can outlive its caller, OR If it can return an object that can reference its execution state ARs must be kept in the heap If a procedure makes no calls AR can be allocated statically Efficiency prefers static, stack, then heap

36 Communicating Between Procedures Most languages provide a parameter passing mechanism Expression used at call site becomes variable in callee Two common binding mechanisms Call-by-reference passes a pointer to actual parameter Requires slot in the AR (for address of parameter) Multiple names with the same address? Call-by-value passes a copy of its value at time of call Requires slot in the AR Each name gets a unique location Arrays are mostly passed by reference, not value Can always use global variables call fee(x,x,x); (may have same value)

37 Procedure Linkages Standard procedure linkage procedure p prolog pre-call post-return epilog procedure q prolog epilog Procedure has standard prolog standard epilog Each call involves a pre-call sequence post-return sequence These are completely predictable from the call site depend on the number & type of the actual parameters

38 Procedure Linkages Pre-call Sequence Sets up callee s basic AR Helps preserve its own environment The Details Allocate space for the callee s AR except space for local variables Evaluates each parameter & stores value or address Saves return address, caller s ARP into callee s AR If access links are used Find appropriate lexical ancestor & copy into callee s AR Save any caller-save registers Save into space in caller s AR Jump to address of callee s prolog code

39 Procedure Linkages Post-return Sequence Finish restoring caller s environment Place any value back where it belongs The Details Copy return value from callee s AR, if necessary Free the callee s AR Restore any caller-save registers Restore any call-by-reference parameters to registers, if needed Also copy back call-by-value/result parameters Continue execution after the call

40 Procedure Linkages Prolog Code Finish setting up the callee s environment Preserve parts of the caller s environment that will be disturbed The Details Preserve any callee-save registers If display is being used Save display entry for current lexical level Store current ARP into display for current lexical level Allocate space for local data Easiest scenario is to extend the AR Find any static data areas referenced in the callee Handle any local variable initializations With heap allocated AR, may need to use a separate heap object for local variables

41 Procedure Linkages Epilog Code Wind up the business of the callee Start restoring the caller s environment The Details Store return value? No, this happens on the return statement Restore callee-save registers Free space for local data, if necessary (on the heap) Load return address from AR Restore caller s ARP Jump to the return address If ARs are stack allocated, this may not be necessary. (Caller can reset stacktop to its pre-call value.)

42 Storage for Blocks within a Single Procedure procedure A { int a, b, c B1: { int v, b, x, w B2: { int x, y, z. B3: { int x, a, v Fixed length data can always be at a constant offset from the beginning of a procedure In our example, the a declared at level 0 will always be the first data element, stored at byte 0 in the fixed-length data area The x declared at level 1 will always be the sixth data item, stored at byte 20 in the fixed data area The x declared at level 2 will always be the eighth data item, stored at byte 28 in the fixed data area But what about the a declared in the second block at level 2?

43 Storage for Blocks within a Single Procedure procedure A { int a, b, c B1: { int v, b, x, w B2: { int x, y, z. B3: { int x, a, v Could implement activation record for each block. Too expensive! Share storage for blocks that don t overlap B2 and B3 do not overlap When enter a block put local variables at TOS (top of stack) Offsets computed statically Blocks B2 and B3 share same offsets!

44 Activation Record Details How does the compiler find the variables? They are at known offsets from the AR pointer The static coordinate leads to a loadai operation Level specifies an ARP, offset is the constant Variable-length data If AR can be extended, put it after local variables Leave a pointer at a known offset from ARP Otherwise, put variable-length data on the heap Initializing local variables Must generate explicit code to store the values Among the procedure s first actions

45 Establishing Addressability Must create base addresses Global & static variables Construct a label by mangling names (i.e., &_fee) Local variables Convert to static data coordinate and use ARP + offset Local variables of other procedures Convert to static coordinates Find appropriate ARP Use that ARP + offset { Must find the right AR Need links to nameable ARs

46 Establishing Addressability Using access links Each AR has a pointer to AR of lexical ancestor Lexical ancestor need not be the caller AR P parameters register save area return value return address access link caller s ARP local variables parameters register save area return value return address access link caller s ARP local variables parameters register save area return value return address access link caller s ARP local variables Reference to <p,16> runs up access link chain to p Cost of access is proportional to lexical distance

47 Establishing Addressability Using access links SC Generated Code access link <2,8> loadai r 0, 8 r 2 <1,12> loadai r 0, -4 r 1 loadai r 1, 12 r 2 <0,16> loadai r 0, -4 r 1 loadai r 1, -4 r 1 loadai r 1, 16 r 2 access link access link access link Access & maintenance cost varies with level All accesses are relative to ARP (r 0 )

48 Back to Activation Records If activation records are stored on the stack Easy to extend simply bump top of stack pointer Caller & callee share responsibility Caller can push parameters, space for registers, return value slot, return address, addressability info, & its own ARP Callee can push space for local variables (fixed & variable size) If activation records are stored on the heap Hard to extend Caller passes everything it can in registers Callee allocates AR & stores register contents into it Extra parameters stored in caller s AR! Static is easy

49 What about Object-Oriented Languages?

50 What about Object-Oriented Languages? What is an OOL? A language that supports object-oriented programming How does an OOL differ from an Algol-like languages? Data-centric name scopes for values & functions Dynamic resolution of names to their implementations How do we compile OOLs? Need to define what we mean by an OOL Term is almost meaningless today Smalltalk to C++ to Java We will focus on Java and C++

51 Object-Oriented Languages An object is an abstract data type that encapsulates data, operations and internal state behind a simple, consistent interface. The Concept: x Data Code Data Code Elaborating the concepts: Each object needs local storage for its attributes Attributes are static (lifetime of object ) Access is through methods Some methods are public, others are private More complex linkage convention; locating them is complex Object s internal state leads to complex behavior y z Data Code

52 OOLs & the Procedure Abstraction What is the shape of an OOL s name space? Local storage in objects (beyond attributes) Some storage associated with methods Local values inside a method Static values with lifetimes beyond methods Methods shared among multiple objects In some OOLs, everything is an object. In others, variables coexist with objects & inside objects. Classes Objects with the same state are grouped into a class Same attributes, instance variables, & methods Class variables are static, shared among all objects of same class Allows programmer to write it down once Allows code reuse at both source & implementation level

53 Implementing Object-Oriented Languages So, what can an executing method see? The object s own attributes & private variables Smalltalk terminology: instance variables The attributes & private variables of the class that defines it Smalltalk terminology: class variables Any object defined in the global name space (or scope) Objects may contain other objects An executing method might reference any of these A final twist: Most OOLs support a hierarchical notion of inheritance Some OOLs support multiple inheritance More than one path through the inheritance hierarchy

54 Java Name Space Given a method M for an object O in a class C, M can see: Local variables declared within M (lexical scoping) All instance variables and class variables of the class C All public and protected variables of any superclass of C Any classes defined in the same package or in a package imported public class variables and instance variables of imported classes package class and instance variables in the package containing C Class declarations can be nested! These member declarations hide outer class declarations of the same name (lexical scoping) Accessibility: public, private, protected, package

55 Java Symbol Tables To compile code in method M for an object O within a class C, the compiler needs: Lexically scoped symbol table for block and class nesting Just like Algol-like language inner declarations hide outer declarations Chain of symbol tables for inheritance Need mechanism to find the class and instance variables of all superclasses Symbol tables for all global classes (package scope) Entries for all members with visibility Need to construct symbol table for imported packages

56 Java Symbol Tables To find the address associated with a variable reference in method M for an object O within a class C, the compiler must For an unqualified use (i.e., x): Search the scoped symbol table for the current method Search the chain of symbol tables for the class hierarchy Search global symbol table (current package and imported) In each case check visibility attribute of x For a qualified use (i.e.: Q.x): Search stack-structured global symbol table for class nesting for Q Check visibility attribute of x

57 Implementing Object-Oriented Languages Two critical issues in OOL implementation: Object representation Mapping a method invocation name to a method implementation These both are intimately related to the OOL s name space Object Representation Static, private storage for attributes & instance variables Heap allocate object records or instances Need consistent, fast access Known, constant offsets Provision for initialization in NEW x fee() fie() foe() count

58 OOL Storage Layout (Java) Class variables Static class storage accessible by global name (class C) Accessible via linkage symbol &_C Nested classes are handled like blocks in Algol-like Languages Method code put at fixed offset from start of class area Object Representation x Object storage is heap allocated Fields at fixed offsets from start of object storage Methods Code for methods is stored with the class Methods accessed by offsets from code vector Method local storage in object (no calls) or on stack fee() fie() foe() count

59 Dealing with Single Inheritance Use prefixing of storage Class Point { int x, y; self x y Class ColorPoint extends Point { Color c; self x y c Does casting work properly?

60 Implementing Object-Oriented Languages Mapping message names to methods Static mapping, known at compile-time Fixed offsets & indirect calls Dynamic mapping, unknown until run-time Look up name in class table of methods (Java, C++) (Smalltalk) Want uniform placement of standard services (NEW, PRINT, ) This is really a data-structures problem Build a table of function pointers Use a standard invocation sequence

61 Implementing Object-Oriented Languages With static, compile-time mapped classes Class A Class B fee() fie() x i j k band() bend() m a b c foe() bind() fum() y i j k bond() n a b c z i j k p a b c Message dispatch becomes an indirect call through a function table

62 Single Inheritance and Dynamic Dispatch Use prefixing of tables Class Point { self int x, y; public void draw(); public void d2o(); table x y draw d2o Point: draw Point: d20 self table draw ColorPoint:draw Class ColorPoint extends Point { Color c; public void draw(); public void rev(); x y c d2o rev ColorPoint: rev

The Procedure Abstraction Part I: Basics

The Procedure Abstraction Part I: Basics The Procedure Abstraction Part I: Basics Procedure Abstraction Begins Chapter 6 in EAC The compiler must deal with interface between compile time and run time Most of the tricky issues arise in implementing

More information

Optimizer. Defining and preserving the meaning of the program

Optimizer. Defining and preserving the meaning of the program Where are we? Well understood Engineering Source Code Front End IR Optimizer IR Back End Machine code Errors The latter half of a compiler contains more open problems, more challenges, and more gray areas

More information

The Procedure Abstraction Part I Basics

The Procedure Abstraction Part I Basics 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

More information

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

CS415 Compilers. Procedure Abstractions. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Procedure Abstractions These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Where are we? Well understood Engineering Source Code

More information

What about Object-Oriented Languages?

What about Object-Oriented Languages? What about Object-Oriented Languages? What is an OOL? A language that supports object-oriented programming How does an OOL differ from an ALL? (ALGOL-Like Language) Data-centric name scopes for values

More information

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

Procedure and Function Calls, Part II. Comp 412 COMP 412 FALL Chapter 6 in EaC2e. target code. source code Front End Optimizer Back End COMP 412 FALL 2017 Procedure and Function Calls, Part II Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

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

Run Time Environment. Activation Records Procedure Linkage Name Translation and Variable Access Run Time Environment Activation Records Procedure Linkage Name Translation and Variable Access Copyright 2015, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University

More information

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

Run Time Environment. Procedure Abstraction. The Procedure as a Control Abstraction. The Procedure as a Control Abstraction Procedure Abstraction Run Time Environment Records Procedure Linkage Name Translation and Variable Access Copyright 2010, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at

More information

CS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction

CS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction CS 406/534 Compiler Construction Intermediate Representation and Procedure Abstraction Prof. Li Xu Dept. of Computer Science UMass Lowell Fall 2004 Part of the course lecture notes are based on Prof. Keith

More information

Naming in OOLs and Storage Layout Comp 412

Naming in OOLs and Storage Layout Comp 412 COMP 412 FALL 2018 Naming in OOLs and Storage Layout Comp 412 source IR IR target Front End Optimizer Back End Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in

More information

Runtime Support for Algol-Like Languages Comp 412

Runtime Support for Algol-Like Languages Comp 412 COMP 412 FALL 2018 Runtime Support for Algol-Like Languages Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

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

Runtime Support for OOLs Object Records, Code Vectors, Inheritance Comp 412 COMP 412 FALL 2017 Runtime Support for OOLs Object Records, Code Vectors, Inheritance Comp 412 source IR Front End Optimizer Back End IR target Copyright 2017, Keith D. Cooper & Linda Torczon, all rights

More information

Object Oriented Languages. Hwansoo Han

Object Oriented Languages. Hwansoo Han Object Oriented Languages Hwansoo Han Object-Oriented Languages An object is an abstract data tpe Encapsulates data, operations and internal state behind a simple, consistent interface. z Data Code Data

More information

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

Separate compilation. Topic 6: Runtime Environments p.1/21. CS 526 Topic 6: Runtime Environments The linkage convention Runtime Environment The Procedure Abstraction and Separate Compilation Topics we will cover The procedure abstraction and linkage conventions Runtime storage convention Non-local data access (brief) These

More information

CSE 504: Compiler Design. Runtime Environments

CSE 504: Compiler Design. Runtime Environments Runtime Environments Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Procedure Abstractions Mechanisms to manage procedures and procedure calls from compiler s perspective Runtime Environment Choices

More information

Intermediate Representations & Symbol Tables

Intermediate Representations & Symbol Tables Intermediate Representations & Symbol Tables Copyright 2014, Pedro C. Diniz, all rights reserved. Students enrolled in the Compilers class at the University of Southern California have explicit permission

More information

Procedure and Object- Oriented Abstraction

Procedure and Object- Oriented Abstraction Procedure and Object- Oriented Abstraction Scope and storage management cs5363 1 Procedure abstractions Procedures are fundamental programming abstractions They are used to support dynamically nested blocks

More information

Arrays and Functions

Arrays and Functions COMP 506 Rice University Spring 2018 Arrays and Functions source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled

More information

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

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How? A Binding Question! Variables are bound (dynamically) to values Subprogram Activation! Those values must be stored somewhere! Therefore, variables must somehow be bound to memory locations! How? Function

More information

Code Shape Comp 412 COMP 412 FALL Chapters 4, 5, 6 & 7 in EaC2e. source code. IR IR target. code. Front End Optimizer Back End

Code Shape Comp 412 COMP 412 FALL Chapters 4, 5, 6 & 7 in EaC2e. source code. IR IR target. code. Front End Optimizer Back End COMP 412 FALL 2018 Code Shape Comp 412 source code IR IR target Front End Optimizer Back End code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at

More information

Run-time Environments

Run-time Environments Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction

More information

Run-time Environments

Run-time Environments Run-time Environments Status We have so far covered the front-end phases Lexical analysis Parsing Semantic analysis Next come the back-end phases Code generation Optimization Register allocation Instruction

More information

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

CSE 504. Expression evaluation. Expression Evaluation, Runtime Environments. One possible semantics: Problem: Expression evaluation CSE 504 Order of evaluation For the abstract syntax tree + + 5 Expression Evaluation, Runtime Environments + + x 3 2 4 the equivalent expression is (x + 3) + (2 + 4) + 5 1 2 (. Contd

More information

Concepts Introduced in Chapter 7

Concepts Introduced in Chapter 7 Concepts Introduced in Chapter 7 Storage Allocation Strategies Static Stack Heap Activation Records Access to Nonlocal Names Access links followed by Fig. 7.1 EECS 665 Compiler Construction 1 Activation

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Control Abstraction. Hwansoo Han

Control Abstraction. Hwansoo Han Control Abstraction Hwansoo Han Review of Static Allocation Static allocation strategies Code Global variables Own variables (live within an encapsulation - static in C) Explicit constants (including strings,

More information

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

Run-time Environments. Lecture 13. Prof. Alex Aiken Original Slides (Modified by Prof. Vijay Ganesh) Lecture 13 Run-time Environments Lecture 13 by Prof. Vijay Ganesh) Lecture 13 1 What have we covered so far? We have covered the front-end phases Lexical analysis (Lexer, regular expressions,...) Parsing (CFG, Top-down,

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 13: Names, Scopes and Bindings Zheng (Eddy) Zhang Rutgers University February 28, 2018 Review: Names, Scopes and Binding What s in a name? Each name means

More information

Scope, Functions, and Storage Management

Scope, Functions, and Storage Management Scope, Functions, and Storage Management Implementing Functions and Blocks cs3723 1 Simplified Machine Model (Compare To List Abstract Machine) Registers Code Data Program Counter (current instruction)

More information

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

Runtime management. CS Compiler Design. The procedure abstraction. The procedure abstraction. Runtime management. V. Runtime management CS3300 - Compiler Design Runtime management V Krishna Nandivada IIT Madras Copyright c 2001 by Antony L Hosking Permission to make digital or hard copies of part or all of this work

More information

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table SYMBOL TABLE: A symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating

More information

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

Today's Topics. CISC 458 Winter J.R. Cordy Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages 1 / 26 CSE 307: Principles of Programming Languages Names, Scopes, and Bindings R. Sekar 2 / 26 Topics Bindings 1. Bindings Bindings: Names and Attributes Names are a fundamental abstraction in languages

More information

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

CPS311 Lecture: Procedures Last revised 9/9/13. Objectives: CPS311 Lecture: Procedures Last revised 9/9/13 Objectives: 1. To introduce general issues that any architecture must address in terms of calling/returning from procedures, passing parameters (including

More information

CS 314 Principles of Programming Languages. Lecture 13

CS 314 Principles of Programming Languages. Lecture 13 CS 314 Principles of Programming Languages Lecture 13 Zheng Zhang Department of Computer Science Rutgers University Wednesday 19 th October, 2016 Zheng Zhang 1 CS@Rutgers University Class Information Reminder:

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction David Sinclair When procedure A calls procedure B, we name procedure A the caller and procedure B the callee. A Runtime Environment, also called an Activation Record, is

More information

CSE 504: Compiler Design. Intermediate Representations Symbol Table

CSE 504: Compiler Design. Intermediate Representations Symbol Table Intermediate Representations Symbol Table Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Intermediate Representations Graphical IRs Linear IRs Symbol Table Information in a Program Compiler manages

More information

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing

More information

The Software Stack: From Assembly Language to Machine Code

The Software Stack: From Assembly Language to Machine Code COMP 506 Rice University Spring 2018 The Software Stack: From Assembly Language to Machine Code source code IR Front End Optimizer Back End IR target code Somewhere Out Here Copyright 2018, Keith D. Cooper

More information

Implementing Subroutines. Outline [1]

Implementing Subroutines. Outline [1] Implementing Subroutines In Text: Chapter 9 Outline [1] General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested

More information

Run-time Environments - 2

Run-time Environments - 2 Run-time Environments - 2 Y.N. Srikant Computer Science and Automation Indian Institute of Science Bangalore 560 012 NPTEL Course on Principles of Compiler Design Outline of the Lecture n What is run-time

More information

The compilation process is driven by the syntactic structure of the program as discovered by the parser

The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic Analysis The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on its syntactic structure

More information

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

Example. program sort; var a : array[0..10] of integer; procedure readarray; : function partition (y, z :integer) :integer; var i, j,x, v :integer; : Runtime Environment Relationship between names and data objects (of target machine) Allocation & de-allocation is managed by run time support package Each execution of a procedure is an activation of the

More information

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?

More information

System Software Assignment 1 Runtime Support for Procedures

System Software Assignment 1 Runtime Support for Procedures System Software Assignment 1 Runtime Support for Procedures Exercise 1: Nested procedures Some programming languages like Oberon and Pascal support nested procedures. 1. Find a run-time structure for such

More information

Chapter 3:: Names, Scopes, and Bindings (cont.)

Chapter 3:: Names, Scopes, and Bindings (cont.) Chapter 3:: Names, Scopes, and Bindings (cont.) Programming Language Pragmatics Michael L. Scott Review What is a regular expression? What is a context-free grammar? What is BNF? What is a derivation?

More information

Symbol Tables. For compile-time efficiency, compilers often use a symbol table: associates lexical names (symbols) with their attributes

Symbol Tables. For compile-time efficiency, compilers often use a symbol table: associates lexical names (symbols) with their attributes For compile-time efficiency, compilers often use a symbol table: associates lexical names (symbols) with their attributes What items should be entered? variable names defined constants procedure and function

More information

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

12/4/18. Outline. Implementing Subprograms. Semantics of a subroutine call. Storage of Information. Semantics of a subroutine return Outline Implementing Subprograms In Text: Chapter 10 General semantics of calls and returns Implementing simple subroutines Call Stack Implementing subroutines with stackdynamic local variables Nested

More information

Chapter 3:: Names, Scopes, and Bindings (cont.)

Chapter 3:: Names, Scopes, and Bindings (cont.) Chapter 3:: Names, Scopes, and Bindings (cont.) Programming Language Pragmatics Michael L. Scott Review What is a regular expression? What is a context-free grammar? What is BNF? What is a derivation?

More information

Weeks 6&7: Procedures and Parameter Passing

Weeks 6&7: Procedures and Parameter Passing CS320 Principles of Programming Languages Weeks 6&7: Procedures and Parameter Passing Jingke Li Portland State University Fall 2017 PSU CS320 Fall 17 Weeks 6&7: Procedures and Parameter Passing 1 / 45

More information

Compilers and computer architecture: A realistic compiler to MIPS

Compilers and computer architecture: A realistic compiler to MIPS 1 / 1 Compilers and computer architecture: A realistic compiler to MIPS Martin Berger November 2017 Recall the function of compilers 2 / 1 3 / 1 Recall the structure of compilers Source program Lexical

More information

Symbol Table Information. Symbol Tables. Symbol table organization. Hash Tables. What kind of information might the compiler need?

Symbol Table Information. Symbol Tables. Symbol table organization. Hash Tables. What kind of information might the compiler need? Symbol Table Information For compile-time efficiency, compilers often use a symbol table: associates lexical names (symbols) with their attributes What items should be entered? variable names defined constants

More information

CMSC 430 Introduction to Compilers. Spring Code Generation

CMSC 430 Introduction to Compilers. Spring Code Generation CMSC 430 Introduction to Compilers Spring 2015 Code Generation Introduction Code generation is the process of moving from highest level IR down to machine code Usually takes place after data flow analysis

More information

Short Notes of CS201

Short Notes of CS201 #includes: Short Notes of CS201 The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with < and > if the file is a system

More information

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam

Compilers. Type checking. Yannis Smaragdakis, U. Athens (original slides by Sam Compilers Type checking Yannis Smaragdakis, U. Athens (original slides by Sam Guyer@Tufts) Summary of parsing Parsing A solid foundation: context-free grammars A simple parser: LL(1) A more powerful parser:

More information

CS201 - Introduction to Programming Glossary By

CS201 - Introduction to Programming Glossary By CS201 - Introduction to Programming Glossary By #include : The #include directive instructs the preprocessor to read and include a file into a source code file. The file name is typically enclosed with

More information

Run-Time Environments

Run-Time Environments CS308 Run-Time Environments Li Jiang Department of Computer Science and Engineering Shanghai Jiao Tong University Current Progress Source Language Lexical Analyzer Syntax Analyzer Semantic Analyzer Intermediate

More information

CIT Week13 Lecture

CIT Week13 Lecture CIT 3136 - Week13 Lecture Runtime Environments During execution, allocation must be maintained by the generated code that is compatible with the scope and lifetime rules of the language. Typically there

More information

Runtime Environments I. Basilio B. Fraguela

Runtime Environments I. Basilio B. Fraguela Runtime Environments I Basilio B. Fraguela Runtime System Responsibilities Allocation of storage for program data Sometimes also deallocation Garbage collection Management of data structures the compiled

More information

CS 4100 Block Structured Languages. Fixed vs Variable. Activation Record. Activation Records. State of an Activation

CS 4100 Block Structured Languages. Fixed vs Variable. Activation Record. Activation Records. State of an Activation Chapter 6: Implementation of Block-Structure CS 4100 Block Structured Languages From Principles of Programming Languages: Design, Evaluation, and Implementation (Third Edition), by Bruce J. MacLennan,

More information

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1

Compilers. 8. Run-time Support. Laszlo Böszörmenyi Compilers Run-time - 1 Compilers 8. Run-time Support Laszlo Böszörmenyi Compilers Run-time - 1 Run-Time Environment A compiler needs an abstract model of the runtime environment of the compiled code It must generate code for

More information

Compiler construction

Compiler construction Compiler construction Martin Steffen March 13, 2017 Contents 1 Abstract 1 1.1 Symbol tables. 1 1.1.1 Introduction 1 1.1.2 Symbol table design and interface.. 2 1.1.3 Implementing symbol tables 3 1.1.4

More information

Chapter 6 Introduction to Defining Classes

Chapter 6 Introduction to Defining Classes Introduction to Defining Classes Fundamentals of Java: AP Computer Science Essentials, 4th Edition 1 Objectives Design and implement a simple class from user requirements. Organize a program in terms of

More information

Compiler Design. Code Shaping. Hwansoo Han

Compiler Design. Code Shaping. Hwansoo Han Compiler Design Code Shaping Hwansoo Han Code Shape Definition All those nebulous properties of the code that impact performance & code quality Includes code, approach for different constructs, cost, storage

More information

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

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4020 July 5, 2007 14.00-15.30 This exam (8 pages) consists of 60 True/False

More information

Lecture08: Scope and Lexical Address

Lecture08: Scope and Lexical Address Lecture08: Scope and Lexical Address Free and Bound Variables (EOPL 1.3.1) Given an expression E, does a particular variable reference x appear free or bound in that expression? Definition: A variable

More information

Functions in MIPS. Functions in MIPS 1

Functions in MIPS. Functions in MIPS 1 Functions in MIPS We ll talk about the 3 steps in handling function calls: 1. The program s flow of control must be changed. 2. Arguments and return values are passed back and forth. 3. Local variables

More information

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

Compiler Theory. (Semantic Analysis and Run-Time Environments) Compiler Theory (Semantic Analysis and Run-Time Environments) 005 Semantic Actions A compiler must do more than recognise whether a sentence belongs to the language of a grammar it must do something useful

More information

Inheritance, Polymorphism and the Object Memory Model

Inheritance, Polymorphism and the Object Memory Model Inheritance, Polymorphism and the Object Memory Model 1 how objects are stored in memory at runtime? compiler - operations such as access to a member of an object are compiled runtime - implementation

More information

Compilation /15a Lecture 7. Activation Records Noam Rinetzky

Compilation /15a Lecture 7. Activation Records Noam Rinetzky Compilation 0368-3133 2014/15a Lecture 7 Activation Records Noam Rinetzky 1 Code generation for procedure calls (+ a few words on the runtime system) 2 Code generation for procedure calls Compile time

More information

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11

CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 11 CS 536 Spring 2015 1 Handling Overloaded Declarations Two approaches are popular: 1. Create a single symbol table

More information

Semantic Analysis and Type Checking

Semantic Analysis and Type Checking Semantic Analysis and Type Checking The compilation process is driven by the syntactic structure of the program as discovered by the parser Semantic routines: interpret meaning of the program based on

More information

Run-Time Data Structures

Run-Time Data Structures Run-Time Data Structures Static Structures For static structures, a fixed address is used throughout execution. This is the oldest and simplest memory organization. In current compilers, it is used for:

More information

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis? Anatomy of a Compiler Program (character stream) Lexical Analyzer (Scanner) Syntax Analyzer (Parser) Semantic Analysis Parse Tree Intermediate Code Generator Intermediate Code Optimizer Code Generator

More information

CSE 307: Principles of Programming Languages

CSE 307: Principles of Programming Languages CSE 307: Principles of Programming Languages Classes and Inheritance R. Sekar 1 / 52 Topics 1. OOP Introduction 2. Type & Subtype 3. Inheritance 4. Overloading and Overriding 2 / 52 Section 1 OOP Introduction

More information

Lecture 7: Binding Time and Storage

Lecture 7: Binding Time and Storage Lecture 7: Binding Time and Storage COMP 524 Programming Language Concepts Stephen Olivier February 5, 2009 Based on notes by A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts Goal of Lecture The

More information

Special Topics: Programming Languages

Special Topics: Programming Languages Lecture #17 0 V22.0490.001 Special Topics: Programming Languages B. Mishra New York University. Lecture # 17 Lecture #17 1 Slide 1 Runtime Representations Variable Names Environment L-values Scope, Extent

More information

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

Typical Runtime Layout. Tiger Runtime Environments. Example: Nested Functions. Activation Trees. code. Memory Layout Tiger Runtime Environments Compile-time environments are just symbol tables; they are used to assist static semantic analysis, code generation and code optimization. Run-time environments are about how

More information

16 Sharing Main Memory Segmentation and Paging

16 Sharing Main Memory Segmentation and Paging Operating Systems 64 16 Sharing Main Memory Segmentation and Paging Readings for this topic: Anderson/Dahlin Chapter 8 9; Siberschatz/Galvin Chapter 8 9 Simple uniprogramming with a single segment per

More information

Scope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule

Scope. CSC 4181 Compiler Construction. Static Scope. Static Scope Rules. Closest Nested Scope Rule Scope CSC 4181 Compiler Construction Scope and Symbol Table A scope is a textual region of the program in which a (name-to-object) binding is active. There are two types of scope: Static scope Dynamic

More information

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

CS 480 Fall Runtime Environments. Mike Lam, Professor. (a.k.a. procedure calls and heap management) CS 480 Fall 2015 Mike Lam, Professor Runtime Environments (a.k.a. procedure calls and heap management) Subprograms General characteristics Single entry point Caller is suspended while subprogram is executing

More information

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! CSCI312 Principles of Programming Languages! Scope Xu Liu ! 4.1 Syntactic Issues! 4.2 Variables! 4.3 Scope! 4.4 Symbol Table! 4.5 Resolving References! 4.6 Dynamic Scoping! 4.7 Visibility! 4.8 Overloading!

More information

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

Lecture 5. Announcements: Today: Finish up functions in MIPS Lecture 5 Announcements: Today: Finish up functions in MIPS 1 Control flow in C Invoking a function changes the control flow of a program twice. 1. Calling the function 2. Returning from the function In

More information

Chapter 9 :: Subroutines and Control Abstraction

Chapter 9 :: Subroutines and Control Abstraction Chapter 9 :: Subroutines and Control Abstraction Programming Language Pragmatics, Fourth Edition Michael L. Scott Copyright 2016 Elsevier 1 Chapter09_Subroutines_and_Control_Abstraction_4e - Tue November

More information

Chapter 3:: Names, Scopes, and Bindings

Chapter 3:: Names, Scopes, and Bindings Chapter 3:: Names, Scopes, and Bindings Programming Language Pragmatics Michael L. Scott Some more things about NFAs/DFAs We said that a regular expression can be: A character (base case) A concatenation

More information

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

Ch. 11: References & the Copy-Constructor. - continued - Ch. 11: References & the Copy-Constructor - continued - const references When a reference is made const, it means that the object it refers cannot be changed through that reference - it may be changed

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Implementing Subprograms

Implementing Subprograms 1 Implementing Subprograms CS 315 Programming Languages Pinar Duygulu Bilkent University CS315 Programming Languages Pinar Duygulu The General Semantics of Calls and Returns 2 The subprogram call and return

More information

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

Module 27 Switch-case statements and Run-time storage management Module 27 Switch-case statements and Run-time storage management In this module we will discuss the pending constructs in generating three-address code namely switch-case statements. We will also discuss

More information

Lecture 9: Procedures & Functions. CS 540 George Mason University

Lecture 9: Procedures & Functions. CS 540 George Mason University Lecture 9: Procedures & Functions CS 540 George Mason University Procedures/Functions Control Abstraction call/return semantics, parameters, recursion Controlled Namespace Scope (local/non-local), binding,

More information

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

Chapter 9. Def: The subprogram call and return operations of a language are together called its subprogram linkage Def: The subprogram call and return operations of a language are together called its subprogram linkage Implementing FORTRAN 77 Subprograms Call Semantics: 1. Save the execution status of the caller 2.

More information

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017

Programming Language Concepts Scoping. Janyl Jumadinova January 31, 2017 Programming Language Concepts Scoping Janyl Jumadinova January 31, 2017 Scope Rules A scope is a program section of maximal size in which no bindings change, or at least in which no re-declarations are

More information

Scope. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Scope. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill Scope Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. Referencing Environment

More information

2. Reachability in garbage collection is just an approximation of garbage.

2. Reachability in garbage collection is just an approximation of garbage. symbol tables were on the first exam of this particular year's exam. We did not discuss register allocation in this This exam has questions from previous CISC 471/672. particular year. Not all questions

More information

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing

More information

Subroutines and Control Abstraction. CSE 307 Principles of Programming Languages Stony Brook University

Subroutines and Control Abstraction. CSE 307 Principles of Programming Languages Stony Brook University Subroutines and Control Abstraction CSE 307 Principles of Programming Languages Stony Brook University http://www.cs.stonybrook.edu/~cse307 1 Subroutines Why use subroutines? Give a name to a task. We

More information

Code Generation. Lecture 12

Code Generation. Lecture 12 Code Generation Lecture 12 1 Lecture Outline Topic 1: Basic Code Generation The MIPS assembly language A simple source language Stack-machine implementation of the simple language Topic 2: Code Generation

More information

Absolute C++ Walter Savitch

Absolute C++ Walter Savitch Absolute C++ sixth edition Walter Savitch Global edition This page intentionally left blank Absolute C++, Global Edition Cover Title Page Copyright Page Preface Acknowledgments Brief Contents Contents

More information

Programming Languages: Lecture 12

Programming Languages: Lecture 12 1 Programming Languages: Lecture 12 Chapter 10: Implementing Subprograms Jinwoo Kim jwkim@jjay.cuny.edu Chapter 10 Topics 2 The General Semantics of Calls and Returns Implementing Simple Subprograms Implementing

More information

Implementing Procedure Calls

Implementing Procedure Calls 1 / 39 Implementing Procedure Calls February 18 22, 2013 2 / 39 Outline Intro to procedure calls Caller vs. callee Procedure call basics Calling conventions The stack Interacting with the stack Structure

More information