The code generator must statically assign a location in the AR for each temporary add $a0 $t1 $a0 ; $a0 = e 1 + e 2 addiu $sp $sp 4 ; adjust $sp (!
|
|
- Virgil Oliver Powell
- 5 years ago
- Views:
Transcription
1 Lecture Outline Code Generation (II) Adapted from Lectures b Profs. Ale Aiken and George Necula (UCB) Allocating temporaries in the Activation Record Let s optimie cgen a little Code generation for OO languages Object memor laout Dnamic dispatch Parameter passing mechanisms call-b-value, call-b-reference, call-b-name CS78(Prasad) LCG CS78(Prasad) LCG Revie An Optimiation: Allocate Space for Temporaries in the Activation Record (AR) Topic I CS78(Prasad) LCG The stack machine has activation records and intermediate results interleaved on the stack AR These get put here hen e evaluate compound Temporaries eprs like e + e (hen e AR need to store value of e Temporaries hile evaluating e ) Advantage: Simple code generation Disadvantage: Slo code Storing/loading temporaries requires a store/load and $sp adjustment CS78(Prasad) LCG cgen(e ) ; eval e s $a ($sp) ; save its value addiu $sp $sp - ; adjust $sp (!) cgen(e ) ; eval e l $t ($sp) ; get e An Optimiation Idea: Predict ho $sp ill move at run time Do this prediction at compile time Move $sp to its limit, at the beginning The code generator must staticall assign a location in the AR for each temporar ; $a = e + e addiu $sp $sp ; adjust $sp (!) CS78(Prasad) LCG CS78(Prasad) LCG 6
2 Improved Code Old method cgen(e ) s $a ($sp) addiu $sp $sp - cgen(e ) l $t ($sp) addiu $sp $sp Ne idea cgen(e ) s $a?($fp) staticall allocate cgen(e ) l $t?($fp) Eample def add(,,,) = + ( + ( +.f())) What intermediate values are placed on the stack? Ho man slots are needed in the AR to hold these values? CS78(Prasad) LCG 7 CS78(Prasad) LCG 8 Ho man Stack Slots? Let NS(e) = # of slots needed to evaluate e Includes slots for arguments to methods E.g: NS(e + e ) Needs at least as man slots as NS(e ) Needs at least one slot to hold value of e, plus as man slots as NS(e ), i.e., + NS(e ) Space used for temporaries in e can be reused for temporaries in e CS78(Prasad) LCG 9 The Equations NS(e + e ) = ma(ns(e ), + NS(e )) NS(e -e ) = ma(ns(e ), + NS(e )) NS(if e = e then e else e ) = ma(ns(e ), + NS(e ), NS(e ), NS(e )) NS(f(e,,e n )) = ma(ns(e ), + NS(e ), + NS(e ),, (n-) + NS(e n ), n) NS(int) = NS(id) = Rule for f(e,, e n ): Each time e evaluate an argument, e put it on the stack. CS78(Prasad) LCG The Revised Activation Record Picture: Activation Record For a function definition f(,, n ) = e the AR has + NS(e) elements Return address Frame pointer NS(e) locations for intermediate results Note that f s arguments are no considered to be part of its caller s AR CS78(Prasad) LCG popped b callee FP FP increasing values of addresses n Old FP Return Addr. Temp NS(e) Temp direction of stack groth pushed b caller saved b callee (this diagram disagrees slightl ith earlier lecture: here, the callee saves FP)
3 Revised Code Generation Code generator must kno ho man slots are in use at each point Add a ne argument to code generator: the position of the net available slot The slots for temporar values are still used like a stack, but e predict usage at compile time This saves us from doing that ork at run time Allocate all needed slots at the start of method Improved Code Old method cgen(e ) s $a ($sp) addiu $sp $sp - cgen(e ) l $t ($sp) addiu $sp $sp Ne method cgen(e + e, ns) = cgen(e, ns) s $a ns($fp) static allocation cgen(e, ns- ) l $t ns($fp) compile-time prediction CS78(Prasad) LCG CS78(Prasad) LCG OO code generation and memor laout Code Generation for OO Languages Topic II Ho are objects represented in memor? Ho is dnamic dispatch implemented? OO Slogan: If C (child) is a subclass of P (parent), then an instance of class C can be used herever an instance of class P is epected This means that P s methods should ork ith an instance of class C (code reuse) CS78(Prasad) LCG CS78(Prasad) LCG 6 Object Representation class P : Int <- ; : String <- Hi ; : Int ; : Bool <- true; : String ; ; Wh method pointers? Wh the tag? self tag: P Hi P.f: return self [] true P.g: return self [] self To call f: dnamic dispatch l $t ($s) jalr $t case CS78(Prasad) LCG 7 Subclass Representation class P.. (same).. ; self class C inherits P P : Int <- 6; // ne : Int ; // override : Bool ; // ne ; C overridden Hi C.f: return self [6] true P.g: return self [] 6 C.h: return self [] inherited To call f: l $t ($s) CS78(Prasad) LCG jalr $t 8 Idea: Append ne fields 6 7
4 Subclasses (Cont.) The offset for an attribute is the same in an instance of a class and all of its subclasses An method for an A can be used on a subclass A Consider laout for A n < < A < A < A Header A attrs A attrs A attrs A object A object A object What about multiple inheritance? LCG 9 Simple Just append subclass fields Efficient Code can ignore dnamic tpe -- just act as if it is the static tpe Supports overriding of methods Just replace the appropriate dispatch pointers We implement tpe conformance (compile- time concept) ith representation conformance (run- time concept) CS78(Prasad) LCG An optimiation: Dispatch Tables Observation Consider instances of class C: C.h: return self [] C.f: return self [6] P.g: return self [] Ever instance of a given class has the same values for all of its method pointers Space optimiation: Put all method pointers for a given class into a common table, called the dispatch table Each instance has a pointer to the dispatch table CS78(Prasad) CS78(Prasad) LCG Picture ith Dispatch Table Subclassing Again Consider again instances of C: Objects are smaller Dispatch is sloer C.f: return self [] P.g: return self [] C.h: return self [] minor point: the offsets have changed since e removed the method ptrs CS78(Prasad) LCG P.f: return self [] call f: l $t ($s) l $t ($t) jalr $t tag: P P.g: return self [] C.f: return self [] C.h: return self []
5 Real COOL Object Laout Actuall, the first ords of Cool objects contain header information: Needed for garbage collector Class Tag Object Sie Dispatch Ptr Attribute Attribute Offset (in btes) 8 6 Parameter Passing Mechanisms Topic III CS78(Prasad) LCG CS78(Prasad) LCG 6 Parameter Passing Mechanisms There are man semantic issues in programming languages centering on hen values are computed, and the scopes of names Evaluation is heart of computation Names are most primitive abstraction mechanism We ll focus on parameter passing When are arguments of function calls evaluated? What are formal parameters bound to? CS78(Prasad) LCG 7 Call-b-value C uses call- callbvalue(int ) = + ; print(); int = ; print(); callbvalue(); print(); b- value everhere (ecept macros...) output: = = = s value does not change hen s value is changed CS78(Prasad) LCG 8 Call-b-reference Available in C++ ith the & tpe constructor callbref(int &) = + ; print(); int = ; print(); callbref(); print(); output: = = = s value changes hen s value is changed CS78(Prasad) LCG 9 Call-b-reference can be faked ith pointers C++: C: callbref(int &) = + ; print(); int = ; print(); callbref(); print(); fakecallbref(int *) * = * + ; print(*); must eplicitl take the address of a local variable int = ; print(); fakecallbref(&); print(); CS78(Prasad) LCG
6 Pointers to fake call-b-reference (cont.) It s not quite the same A pointer can be reassigned to point at something else; a C++ reference cannot The pointer itself as passed b value This is ho ou pass structures in C What about Java? Primitive tpes (int, boolean, etc.) are alas passed b value Objects are not quite -b-value nor -b-reference: If ou reassign an object reference, the caller s argument does not get reassigned (like -b-value) But if ou modif the object referred-to, the caller ill see that modification (like -b-reference) It s reall ordinar call-b-value ith pointers, but the pointers are not sntacticall obvious. COOL is the same a. CS78(Prasad) LCG CS78(Prasad) LCG Call-b-name Whole different ballgame: it s like passing the tet of the argument epression, unevaluated Also passes the environment, so free variables are still bound according to rules of static scoping The argument is not evaluated until it is actuall used, inside the callee. Might not get evaluated at all! Used in some functional languages (e.g. Haskell) CS78(Prasad) LCG Call-b-name eample (in C++-Etra ) callbname(int closure ) eval print(); print(); // => print( = +) int = ; print(); callbname( [[ = + ]] ); print(); closure code + environment (env has just here) both evals have side effects output: = = = = s value changes hen is evaluated CS78(Prasad) LCG
Code Generation & Parameter Passing
Code Generation & Parameter Passing Lecture Outline 1. Allocating temporaries in the activation record Let s optimize our code generator a bit 2. A deeper look into calling sequences Caller/Callee responsibilities
More informationCode Generation II. Code generation for OO languages. Object layout Dynamic dispatch. Parameter-passing mechanisms Allocating temporaries in the AR
Code Generation II Code generation for OO languages Object layout Dynamic dispatch Parameter-passing mechanisms Allocating temporaries in the AR Object Layout OO implementation = Stuff from last lecture
More informationLecture Outline. Topic 1: Basic Code Generation. Code Generation. Lecture 12. Topic 2: Code Generation for Objects. Simulating a Stack Machine
Lecture Outline Code Generation Lecture 12 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 informationCode Generation. Lecture 19
Code Generation Lecture 19 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 informationCode 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 informationThe remote testing experiment. It works! Code Generation. Lecture 12. Remote testing. From the cs164 newsgroup
The remote testing experiment. It works! Coverage - Score plot 0.9 Code Generation 0.7 0.6 Lecture 12 Coverage 0.5 0.4 0.3 Series1 Poly. (Series1) 0.2 0.1 0 0 10 20 30 40 50 Score CS 164 Lecture 14 Fall
More informationCode Generation Super Lectures
Code Generation Super Lectures Huge One-Slide Summary Assembly language is untyped, unstructured, low-level and imperative. In a load-store architecture, instructions operate on registers (which are like
More informationLecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Notation. The rules. Evaluation Rules So Far.
Lecture Outline Operational Semantics of Cool COOL operational semantics Motivation Adapted from Lectures by Profs. Alex Aiken and George Necula (UCB) Notation The rules CS781(Prasad) L24CG 1 CS781(Prasad)
More informationCOL728 Minor2 Exam Compiler Design Sem II, Answer all 5 questions Max. Marks: 20
COL728 Minor2 Exam Compiler Design Sem II, 2017-18 Answer all 5 questions Max. Marks: 20 1. Short questions a. Give an example of a program that is not a legal program if we assume static scoping, but
More informationThe Compiler So Far. Lexical analysis Detects inputs with illegal tokens. Overview of Semantic Analysis
The Compiler So Far Overview of Semantic Analysis Adapted from Lectures by Profs. Alex Aiken and George Necula (UCB) Lexical analysis Detects inputs with illegal tokens Parsing Detects inputs with ill-formed
More informationAnatomy 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 informationG 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 informationClasses. Compiling Methods. Code Generation for Objects. Implementing Objects. Methods. Fields
Classes Implementing Objects Components fields/instance variables values differ from to usuall mutable methods values shared b all s of a class usuall immutable component visibilit: public/private/protected
More informationFunctions in C. Memory Allocation in C. C to LC3 Code generation. Next.. Complete and submit C to LC3 code generation. How to handle function calls?
Memory Allocation in C Functions in C Global data pointer: R4 Global and static variables Specify positive offsets Frame pointer: Points to current code block Negative offset Stack Pointer: Top of stack
More informationWe can emit stack-machine-style code for expressions via recursion
Code Generation The Main Idea of Today s Lecture We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?
More informationCode Generation. The Main Idea of Today s Lecture. We can emit stack-machine-style code for expressions via recursion. Lecture Outline.
The Main Idea of Today s Lecture Code Generation We can emit stack-machine-style code for expressions via recursion (We will use MIPS assembly as our target language) 2 Lecture Outline What are stack machines?
More informationG 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 informationLecture Outline. Type systems and their expressiveness. Type Checking in COOL (II) Type checking with SELF_TYPE in COOL
Lecture Outline Type systems and their expressiveness Type Checking in COOL (II) Type checking with SELF_TYPE in COOL Error recovery in semantic analysis Adapted from Lectures by Profs. Alex Aiken and
More informationVariables and Bindings
Net: Variables Variables and Bindings Q: How to use variables in ML? Q: How to assign to a variable? # let = 2+2;; val : int = 4 let = e;; Bind the value of epression e to the variable Variables and Bindings
More informationCode Generation Super Lectures
Code Generation Super Lectures Huge One-Slide Summary Assembly language is untyped, unstructured, low-level and imperative. In a load-store architecture, instructions operate on registers (which are like
More informationCSE 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 informationScope, 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 informationProgramming Language Dilemma Fall 2002 Lecture 1 Introduction to Compilation. Compilation As Translation. Starting Point
Programming Language Dilemma 6.035 Fall 2002 Lecture 1 Introduction to Compilation Martin Rinard Laborator for Computer Science Massachusetts Institute of Technolog Stored program computer How to instruct
More informationCompilers 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 informationCompiler construction
This lecture Compiler construction Lecture 5: Project etensions Magnus Mreen Spring 2018 Chalmers Universit o Technolog Gothenburg Universit Some project etensions: Arras Pointers and structures Object-oriented
More informationWritten Assignment 5 Due??
Written Assignment 5 Due?? This assignment asks you to prepare written answers to questions on type checking. Each of the questions has a short answer. You may discuss this assignment with other students
More informationRun-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 informationThe Activation Record (AR)
The Activation Record (AR) [Notes adapted from R. Bodik] Code for function calls and function definitions depends on the layout of the activation record Very simple AR suffices for this language: The result
More informationGrade Weights. Language Design and Overview of COOL. CS143 Lecture 2. Programming Language Economics 101. Lecture Outline
Grade Weights Language Design and Overview of COOL CS143 Lecture 2 Project 0% I, II 10% each III, IV 1% each Midterm 1% Final 2% Written Assignments 10% 2.% each Prof. Aiken CS 143 Lecture 2 1 Prof. Aiken
More informationAnnouncements. CSCI 334: Principles of Programming Languages. Lecture 19: C++
Announcements CSCI 4: Principles of Programming Languages Lecture 19: C++ HW8 pro tip: the HW7 solutions have a complete, correct implementation of the CPS version of bubble sort in SML. All ou need to
More informationCS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Exam, Dec 6, 2011
CS 132 Compiler Construction, Fall 2011 Instructor: Jens Palsberg Multiple Choice Eam, Dec 6, 2011 ID Name This eam consists of 22 questions. Each question has four options, eactl one of which is correct,
More informationLecture Outline. COOL operational semantics. Operational Semantics of Cool. Motivation. Lecture 13. Notation. The rules. Evaluation Rules So Far
Lecture Outline Operational Semantics of Cool Lecture 13 COOL operational semantics Motivation Notation The rules Prof. Aiken CS 143 Lecture 13 1 Prof. Aiken CS 143 Lecture 13 2 Motivation We must specify
More informationTypical Compiler. Ahead- of- time compiler. Compilers... that target interpreters. Interpreter 12/9/15. compile time. run time
Ahead- of- time Tpical Compiler compile time C source C 86 assembl 86 assembler 86 machine Source Leical Analzer Snta Analzer Semantic Analzer Analsis Intermediate Code Generator Snthesis run time 86 machine
More informationRun-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 informationCS143 - Written Assignment 4 Reference Solutions
CS143 - Written Assignment 4 Reference Solutions 1. Consider the following program in Cool, representing a slightly over-engineered implementation which calculates the factorial of 3 using an operator
More informationRun-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 informationRun-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 informationNews. CSE 130: Programming Languages. Environments & Closures. Functions are first-class values. Recap: Functions as first-class values
CSE 130: Programming Languages Environments & Closures News PA 3 due THIS Friday (5/1) Midterm NEXT Friday (5/8) Ranjit Jhala UC San Diego Recap: Functions as first-class values Arguments, return values,
More informationMIPS Functions and the Runtime Stack
MIPS Functions and the Runtime Stack COE 301 Computer Organization Prof. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University of Petroleum and Minerals Presentation Outline
More informationSeparate 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 informationCS 403 Compiler Construction Lecture 8 Syntax Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] This Lecture
CS 403 Compiler Construction Lecture 8 Snta Tree and Intermediate Code Generation [Based on Chapter 6 of Aho2] 1 This Lecture 2 1 Remember: Phases of a Compiler This lecture: Intermediate Code This lecture:
More informationChapter 5: Procedural abstraction. Function procedures. Function procedures. Proper procedures and function procedures
Chapter 5: Procedural abstraction Proper procedures and function procedures Abstraction in programming enables distinction: What a program unit does How a program unit works This enables separation of
More informationInheritance, 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 informationSystem 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 informationBuilding up a language SICP Variations on a Scheme. Meval. The Core Evaluator. Eval. Apply. 2. syntax procedures. 1.
6.001 SICP Variations on a Scheme Scheme Evaluator A Grand Tour Techniques for language design: Interpretation: eval/appl Semantics vs. snta Sntactic transformations Building up a language... 3. 1. eval/appl
More informationTypical workflow. CSE341: Programming Languages. Lecture 17 Implementing Languages Including Closures. Reality more complicated
Typical workflow concrete synta (string) "(fn => + ) 4" Parsing CSE341: Programming Languages abstract synta (tree) Lecture 17 Implementing Languages Including Closures Function Constant + 4 Var Var Type
More informationSide note: Tail Recursion. Begin at the beginning. Side note: Tail Recursion. Base Types. Base Type: int. Base Type: int
Begin at the beginning Epressions (Synta) Compile-time Static Eec-time Dynamic Types Values (Semantics) 1. Programmer enters epression 2. ML checks if epression is well-typed Using a precise set of rules,
More informationTail Recursion: Factorial. Begin at the beginning. How does it execute? Tail recursion. Tail recursive factorial. Tail recursive factorial
Begin at the beginning Epressions (Synta) Compile-time Static Eec-time Dynamic Types Values (Semantics) 1. Programmer enters epression 2. ML checks if epression is well-typed Using a precise set of rules,
More informationProgramming Languages
CSE 130 : Fall 2008 Programmg Languages Lecture 4: Variables, Environments, Scope News PA 1 due Frida 5pm PA 2 out esterda (due net Fi) Fri) Ranjit Jhala UC San Diego Variables and Bdgs Q: How to use variables
More informationStructure of a Compiler. We looked at each stage in turn. Exceptions. Language Design and Implementation Issues
Structure of a Compiler Exceptions. Language Design and Implementation Issues Lecture 22 Prof. Bodik CS 164 Lecture 22 1 Source Lexer Parser Type checker Code Generator Executable Runtime System We looked
More informationWinter Compiler Construction T9 IR part 2 + Runtime organization. Announcements. Today. Know thy group s code
Winter 26-27 Compiler Construction T9 IR part 2 + Runtime organization Mool Sagiv and Roman Manevich School of Computer Science Tel-Aviv Universit Announcements What is epected in PA3 documentation (5
More informationWednesday, October 15, 14. Functions
Functions Terms void foo() { int a, b;... bar(a, b); void bar(int x, int y) {... foo is the caller bar is the callee a, b are the actual parameters to bar x, y are the formal parameters of bar Shorthand:
More informationCS2210: Compiler Construction. Runtime Environment
: The environment in which the program executes in at runtime Includes HW: Main memory, CPU,... Includes OS: Environment variables,... When a program is invoked The OS allocates memory for the program
More informationCS 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 informationCIT 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 informationCSC 2400: Computer Systems. Using the Stack for Function Calls
CSC 24: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing
More informationRecap. Recap. If-then-else expressions. If-then-else expressions. If-then-else expressions. If-then-else expressions
Recap Epressions (Synta) Compile-time Static Eec-time Dynamic Types (Semantics) Recap Integers: +,-,* floats: +,-,* Booleans: =,
More informationCA 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 informationCode Generation. Lecture 30
Code Generation Lecture 30 (based on slides by R. Bodik) 11/14/06 Prof. Hilfinger CS164 Lecture 30 1 Lecture Outline Stack machines The MIPS assembly language The x86 assembly language A simple source
More informationMemory Usage 0x7fffffff. stack. dynamic data. static data 0x Code Reserved 0x x A software convention
Subroutines Why we use subroutines more modular program (small routines, outside data passed in) more readable, easier to debug code reuse i.e. smaller code space Memory Usage A software convention stack
More informationECS 142 Project: Code generation hints
ECS 142 Project: Code generation hints Winter 2011 1 Overview This document provides hints for the code generation phase of the project. I have written this in a rather informal way. However, you should
More informationObject 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 informationOperational Semantics. One-Slide Summary. Lecture Outline
Operational Semantics #1 One-Slide Summary Operational semantics are a precise way of specifying how to evaluate a program. A formal semantics tells you what each expression means. Meaning depends on context:
More informationLecture Outline. Type systems and their expressiveness. Type Checking in COOL (II) Type checking with SELF_TYPE in COOL
Lecture Outline Type systems and their expressiveness Type Checking in COOL (II) Lecture 10 Type checking with SELF_TYPE in COOL Error recovery in semantic analysis Prof. Aiken CS 143 Lecture 10 1 Prof.
More informationLecture08: 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! 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 informationTopic 7: Activation Records
Topic 7: Activation Records Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Storage Organization Stack Free Memory Heap Static Code 2 ELF file format example Executable Object
More informationMidterm II CS164, Spring 2006
Midterm II CS164, Spring 2006 April 11, 2006 Please read all instructions (including these) carefully. Write your name, login, SID, and circle the section time. There are 10 pages in this exam and 4 questions,
More informationModule Mechanisms CS412/413. Modules + abstract types. Abstract types. Multiple Implementations. How to type-check?
CS412/413 Introduction to Compilers and Translators Andrew Mers Cornell Universit Lecture 19: ADT mechanisms 10 March 00 Module Mechanisms Last time: modules, was to implement ADTs Module collection of
More informationClasses. Code Generation for Objects. Compiling Methods. Dynamic Dispatch. The Need for Dispatching CS412/CS413
Classes CS4/CS43 Introduction to Comilers Tim Teitelbaum Lecture : Imlementing Objects 8 March 5 Comonents ields/instance variables values ma dier rom object to object usuall mutable methods values shared
More informationChapter 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 informationModule 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 informationLecture Outline. Code Generation. Lecture 30. Example of a Stack Machine Program. Stack Machines
Lecture Outline Code Generation Lecture 30 (based on slides by R. Bodik) Stack machines The MIPS assembly language The x86 assembly language A simple source language Stack-machine implementation of the
More informationRun-time Environment
Run-time Environment Prof. James L. Frankel Harvard University Version of 3:08 PM 20-Apr-2018 Copyright 2018, 2016, 2015 James L. Frankel. All rights reserved. Storage Organization Automatic objects are
More informationInheritance. Transitivity
Inheritance Classes can be organized in a hierarchical structure based on the concept of inheritance Inheritance The property that instances of a sub-class can access both data and behavior associated
More informationObject Oriented Programming: In this course we began an introduction to programming from an object-oriented approach.
CMSC 131: Chapter 28 Final Review: What you learned this semester The Big Picture Object Oriented Programming: In this course we began an introduction to programming from an object-oriented approach. Java
More informationImplementing Object-Oriented Languages. Implementing instance variable access. Implementing dynamic dispatching (virtual functions)
Implementing Object-Oriented Languages Implementing instance variable access Ke features: inheritance (possibl multiple) subtping & subtpe polmorphism message passing, dnamic binding, run-time tpe testing
More informationReview of Activation Frames. FP of caller Y X Return value A B C
Review of Activation Frames In general, activation frames are organized like this: HI LO Bookkeeping/preserved registers I/O parameters Locals and temps RA of caller FP of caller Y X Return value A B C
More informationCOMP 303 Computer Architecture Lecture 3. Comp 303 Computer Architecture
COMP 303 Computer Architecture Lecture 3 Comp 303 Computer Architecture 1 Supporting procedures in computer hardware The execution of a procedure Place parameters in a place where the procedure can access
More informationOperational Semantics of Cool
Operational Semantics of Cool Key Concepts semantics: the meaning of a program, what does program do? how the code is executed? operational semantics: high level code generation steps of calculating values
More informationChapter 13 Object Oriented Programming. Copyright 2006 The McGraw-Hill Companies, Inc.
Chapter 13 Object Oriented Programming Contents 13.1 Prelude: Abstract Data Types 13.2 The Object Model 13.4 Java 13.1 Prelude: Abstract Data Types Imperative programming paradigm Algorithms + Data Structures
More informationCS2210: Compiler Construction. Runtime Environment
: The environment in which the program executes in at runtime Includes HW: Main memory, CPU,... Includes OS: Environment variables,... Includes Runtime Libraries: C Runtime Library (libc),... When a program
More informationRun-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 informationProgramming Languages
CSE 130 : Fall 2008 Programming Languages Lecture 3: Epressions and Types Ranjit Jhala UC San Diego News PA 1 due (net) Fri 10/10 5pm PA 2 out today or tomorrow Office hours posted on Webpage: Held in
More informationSemantics (cont.) Symbol Table. Static Scope. Static Scope. Static Scope. CSE 3302 Programming Languages. Static vs. Dynamic Scope
-2-1 CSE 3302 Programming Languages Semantics (cont.) Smbol Table Smbol Table: maintain bindings. Can be viewed as functions that map names to their attributes. Names SmbolTable Attributes Chengkai Li,
More informationCSC 8400: Computer Systems. Using the Stack for Function Calls
CSC 84: Computer Systems Using the Stack for Function Calls Lecture Goals Challenges of supporting functions! Providing information for the called function Function arguments and local variables! Allowing
More informationM301: Software Systems & their Development. Unit 4: Inheritance, Composition and Polymorphism
Block 1: Introduction to Java Unit 4: Inheritance, Composition and Polymorphism Aims of the unit: Study and use the Java mechanisms that support reuse, in particular, inheritance and composition; Analyze
More informationPrinciples of Programming Languages
Ting Zhang Iowa State University Computer Science Department Lecture Note 16 October 26, 2010 Control Abstraction: Subroutines 1 / 26 Outline 1 Subroutines 2 Parameter Passing 3 Generic Subroutines 2 /
More informationCompilers. 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 informationCSE 401/M501 Compilers
CSE 401/M501 Compilers Code Shape II Objects & Classes Hal Perkins Autumn 2018 UW CSE 401/M501 Autumn 2018 L-1 Administrivia Semantics/type check due next Thur. 11/15 How s it going? Reminder: if you want
More informationCS-XXX: Graduate Programming Languages. Lecture 22 Class-Based Object-Oriented Programming. Dan Grossman 2012
CS-XXX: Graduate Programming Languages Lecture 22 Class-Based Object-Oriented Programming Dan Grossman 2012 PL Issues for OOP? OOP lets you: 1. Build some extensible software concisely 2. Exploit an intuitive
More informationIR Generation. May 13, Monday, May 13, 13
IR Generation May 13, 2013 Monday, May 13, 13 Monday, May 13, 13 Monday, May 13, 13 Midterm Results Grades already in Repeal policy Talk to TA by the end of the Tuesday reserve the right to regrade the
More informationCS143 Compilers - Written Assignment 4
CS143 Compilers - Written Assignment 4 Due Tuesday, June 5, 2018 at 11:59 PM This assignment covers code generation, operational semantics and optimization. You may discuss this assignment with other students
More informationCSE Lecture In Class Example Handout
CSE 30321 Lecture 07-09 In Class Example Handout Part A: A Simple, MIPS-based Procedure: Swap Procedure Example: Let s write the MIPS code for the following statement (and function call): if (A[i] > A
More informationG53CMP: Lecture 14. Run-Time Organisation I. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 14 p.1/37
G53CMP: Lecture 14 Run-Time Organisation I Henrik Nilsson University of Nottingham, UK G53CMP: Lecture 14 p.1/37 This Lecture One aspect of run-time organisation: stack-based storage allocation Lifetime
More informationThis Lecture. G53CMP: Lecture 14 Run-Time Organisation I. Example: Lifetime (1) Storage Areas
This Lecture G53CMP: Lecture 14 Run-Time Organisation I Henrik Nilsson University of Nottingham, UK One aspect of run-time organisation: stack-based storage allocation Lifetime and storage Basic stack
More informationProject Compiler. CS031 TA Help Session November 28, 2011
Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level
More informationProgramming Languages
CSE 130: Spring 2010 Programming Languages Lecture 3: Epressions and Types Ranjit Jhala UC San Diego A Problem fun -> +1 Can functions only have a single parameter? A Solution: Simultaneous Binding Parameter
More informationRun Time Environments
Run Time Environments ALSU Textbook Chapter 7.1 7.3 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Preliminaries During the execution of a program, the same name in the source
More informationProgramming Languages
Programming Languages Tevfik Koşar Lecture - XX April 4 th, 2006 1 Roadmap Subroutines Allocation Strategies Calling Sequences Parameter Passing Generic Subroutines Exception Handling Co-routines 2 1 Review
More information