Compilation 2013 Translation to IR
|
|
- Sharon Hood
- 6 years ago
- Views:
Transcription
1 Compilation 2013 Erik Ernst Aarhus University
2 Intermediate Representation Translation source/target uses IR as a bridge Simplification: n+m combinations, not n m Java SML Pascal C C++ SPARC MIPS Pentium Alpha 2
3 Intermediate Representation Translation source/target uses IR as a bridge Simplification: n+m combinations, not n m Java SML Pascal C C++ IR SPARC MIPS Pentium Alpha 3
4 Intermediate Representation Translation source/target uses IR as a bridge Simplification: n+m combinations, not n m Even more important: Divide and conquer Trade-off, consider: near-source near-target Java SML Pascal C C++ IR SPARC MIPS Pentium Alpha 4
5 Role of IR in Translation Compiler frontend: Translate source to IR, enforce wellformedness Compiler backend: Translate IR to assembly, often optimizing IR should be near both, still independent of source language and of machine details Source, Target: Incongruent complexity IR: clear, simple! IR 5
6 Tiger Compiler IR A simple tree expression language: signature TREE = sig type label = Temp.label datatype stm = MOVE of exp * exp EXP of exp JUMP of exp * label list CJUMP of relop * exp * exp * label * label SEQ of stm * stm LABEL of label and exp = CONST of int NAME of label TEMP of Temp.temp BINOP of binop * exp * exp MEM of exp CALL of exp * exp list ESEQ of stm * exp and binop = PLUS MINUS MUL DIV AND OR LSHIFT RSHIFT ARSHIFT XOR and relop = EQ NE LT GT LE GE ULT ULE UGT UGE... end 6
7 Surprising Bits IR allows calling, but not defining routines! Why is stm =.. EXP of exp.. useful? Why is relop =.. ULT.. useful? 7
8 Translation into IR Core part of compilation! Tempting starting point: Each Absyn.exp translates into a Tree.exp Not optimal no need to manage unit values, maybe not even boolean values.. Important idea: Encode tiny-domain values into the program counter 8
9 Expression Kinds Partition tree expressions into 3 kinds: Statements (Nx): no result, arbitrary effects Expressions (Ex): delivers general-form result Choices (Cx): represents tiny-domain value by behavior NB: customizable, will receive the labels later Some flexibility: Can transform these forms datatype exp = Ex of Tree.exp Nx of Tree.stm Cx of Temp.label * Temp.label -> Tree.stm 9
10 Tree Example & Issue Consider a>b c<d, translated into this: Cx (fn (t,f) => SEQ ( CJUMP (GT, translate(a), translate(b), t, z), SEQ ( LABEL z, CJUMP ( LT, translate(c), translate(d), t, f)))) Label z is fresh: Completely relation-oriented Whole expression returned by translate, type problem? 10
11 Unwrapping Translate.exp Almost all combinations plausible: May have Ex, need Cx, or vice versa Introduce unwrapping functions: val unex: exp -> Tree.exp val unnx: exp -> Tree.stm val uncx: exp -> (Temp.label * Temp.label -> Tree.stm) Similar to pattern matching, but tries to work even on values that do not match 11
12 Example Unwrapper Destruct as (Ex _) from given Translate.exp fun unex (Ex e) = e unex (Cx genstm) = let val r = Temp.newtemp () val t = Temp.newLabel "unex_t" val f = Temp.newLabel "unex_f" in T.ESEQ ( seq [ T.MOVE (T.TEMP r, T.CONST 1), genstm (t, f), T.LABEL f, T.MOVE (T.TEMP r, T.CONST 0), T.LABEL t], T.TEMP r) end unex (Nx s) = T.ESEQ (s, T.CONST 0) 12
13 Translating a Simple Variable For local InFrame(k) variable: MEM (BINOP (PLUS, TEMP fp, CONST k)) NB: No reference to size, works only with all-scalar setup In Translate: val simplevar: access * level -> exp 13
14 Translating a Simple Variable For local InFrame(k) variable: MEM (BINOP (PLUS, TEMP fp, CONST k)) Note important principle: MEM used for both read and write: Depends on context Works because of special discipline.. 14
15 Translating a Simple Variable Consider non-local InFrame(k) variable: Must navigate via static link until correct level found NB: Use unit ref trick as usual to enable level comparison 15
16 Tiger L-Value Management Basic concepts: L-Value: May be LHS & on RHS of assignment R-Value: Only RHS of assignment Consider: Cannot assign to 7 L-Value: Should be the address Issue: How about registers? Trick: Use MEM for both value & address! Left child of MOVE: write; otherwise read 16
17 Using a Translated Simple Variable Dual use of MEM (..): Has no meaning of its own, but one in MOVE (MEM (..),..)and another meaning elsewhere 17
18 Information Management Intended disciplin in module structure: Frame, Temp machine dependent Translate uses Frame and Temp Semant never uses Frame nor Temp directly! Semant Recall structure: Translate Frame Temp 18
19 Record and Array Assignments Arrays: Reference semantics let in end type intarray = array of int var a := intarray [12] of 0 var b := intarray [12] of 7 a := b What is now a[5]? Is there a memory leak? Record assignments: Reference semantics, too 19
20 Variable Sizes General issue: C struct, Pascal array,... Arbitrary size possible for variables Assignment:.. depends.. (typical: bit-copy) Tiger variables: All scalar (word-sized) Many simplifications follow: Array element, record field lookup; local variable allocation/access;... Semantics affected! cf. array assignment 20
21 Array Element Lookup General approach to read a[i]: MEM (address(a) + (i-lower_bound)*elm_size) Tiger, taking index out of bounds into account let in end type arrtype = array of int var arr := arrtype [10] of 7 arr[3] 21
22 Conditionals Very good example for Ex/unEx etc. Cases needed: Consider unex in Cx fun ifthenelse2ir (test, thenexp, elseexp) = let val test' = uncx test val labelthen = Temp.newLabel "if_then" val labelelse = Temp.newLabel "if_else" val labeljoin = Temp.newLabel "if_join" in case (test', thenexp, elseexp) of (_, Cx _, Cx _) => Cx (fn (t, f) => seq [ test' (labelthen, labelelse), T.LABEL labelthen, uncx thenexp (t, f), T.LABEL labelelse, uncx elseexp (t, f)]) (_, Ex _, Cx _) => Cx (fn (t, f) => seq [ test' (labelthen, labelelse), T.LABEL labelthen, uncx thenexp (t, f), T.LABEL labelelse, uncx elseexp (t, f)])... end 22
23 Array and Record Creation Lifetime: Not limited by execution time for creating function Must use heap allocation (GC welcome!); use runtime.o Note var arr := arrtype [12] of x sets every element to x Surprising? Useful? 23
24 Using C Functions in runtime.c Ex, creating array with arguments a, b: CALL (NAME (Temp.namedlabel ("initarray")), [a,b]) May need underscore in names etc.: externalcall: string * Tree.exp list -> Tree.exp int *initarray(int size, int init) { int i; int *a = (int *)malloc((size+1)*sizeof(int)); a[0] = size; for (i = 1; i < size; i++) a[i] = init; return (a+1); } 24
25 While Obvious pseudo-code template will work transexp, transdec gets extra break argument: A label to jump to when breaking For-loop similar, except for maxint corner case # Pseudo-code template: test: if not(condition) goto done body goto test done: 25
26 Calling Functions Typical invocation: CALL (NAME mylabel, [ static_link, arg1, arg2,.., argk]) let in end function f(n: int): int = 42 f(10) 26
27 Declarations Why make changes here?! Variable declaration initialization expression requires running code transdec now also returns exp list, containing var init code, executed before let-body Function declarations do not contribute 27
28 Declarations Serious matter: Completing functions with prologue, body, epilogue (procentryexit1): 1. Pseudo-instructions starting function (segment, debug info,..) 2. Label: function name 3. Allocate frame: SP := SP - framesize 4. Copy escaping arguments into frame, others into registers 5. Store calleesave registers 6. BODY 7. RV :=.. (result so far) 8. Restore calleesave registers 9. Deallocate frame: SP := SP + framesize 10. return instruction 11. Pseudo-instructions to finish function (e.g., size) 28
29 Fragments Used to gather translated code for functions datatype frag = PROC of {body: Tree.stm, frame: frame} STRING of Temp.label * string Gathered using side-effects, use getresult to fetch them all before generating asm code 29
30 Summary Tough IR requirements: simple, independent, between target/source (n+m vs. n m cost) For Tiger: Simple tree language Kinds of expressions: Ex, Nx, Cx, with un.. Simple variable access contains all static link stuff L-Values: scalar, using MEM-both-r&w trick Conditionals: Important to preserve Cx/Ex Loops, break Function calls Declarations: init code; procentryexit1 30
7 Translation to Intermediate Code
7 Translation to Intermediate Code ( 7. Translation to Intermediate Code, p. 150) This chpater marks the transition from the source program analysis phase to the target program synthesis phase. All static
More informationTopic 7: Intermediate Representations
Topic 7: Intermediate Representations COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 2 Intermediate Representations 3 Intermediate Representations 4 Intermediate Representations
More informationAnnouncements. Project 2: released due this sunday! Midterm date is now set: check newsgroup / website. Chapter 7: Translation to IR
Announcements Project 2: released due this sunday! Midterm date is now set: check newsgroup / website. 1 Translation to Intermediate Code (Chapter 7) This stage converts an AST into an intermediate representation.
More informationIntermediate Code Generation. Intermediate Representations (IR) Case Study : itree. itree Statements and Expressions
Intermediate Code Generation Translating the abstract syntax into the intermediate representation. report all lexical & syntactic errors report all semantic errors Intermediate Representations (IR) What
More informationItree Stmts and Exprs. Back-End Code Generation. Summary: IR -> Machine Code. Side-Effects
Back-End Code Generation Given a list of itree fragments, how to generate the corresponding assembly code? datatype frag = PROC of {name : Tree.label, function name body : Tree.stm, function body itree
More informationWhere we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers
Where we are CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 13: Intermediate Code 25 Sep 09 Source code (character stream) Token stream Abstract syntax tree Abstract syntax tree
More informationCPSC 411, Fall 2010 Midterm Examination
CPSC 411, Fall 2010 Midterm Examination. Page 1 of 11 CPSC 411, Fall 2010 Midterm Examination Name: Q1: 10 Q2: 15 Q3: 15 Q4: 10 Q5: 10 60 Please do not open this exam until you are told to do so. But please
More informationCompilation 2013 Basic Blocks and Traces
Compilation 2013 Basic Blocks and Traces Erik Ernst Aarhus University IR = Intermediate IR does not match either end perfectly Source: Translation non-trivial, e.g., using the static link Target: & CALL
More informationCPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia
CPSC 411, 2015W Term 2 Midterm Exam Date: February 25, 2016; Instructor: Ron Garcia This is a closed book exam; no notes; no calculators. Answer in the space provided. There are 8 questions on 14 pages,
More informationTypical 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 informationAdministration. Today
Announcements Administration Office hour today changed to 3:30 4:30 Class is cancelled next Monday I have to attend a Senate Curriculum Committee meeting Project Build a Functions compiler from the Expressions
More informationCompilation 2014 Activation Records
Compilation 2014 Activation Records Aslan Askarov aslan@cs.au.dk Revised from slides by E. Ernst (Abstract) computer organization Program memory code segment contains program text data segment contains
More informationIntermediate Representations
Intermediate Representations Akim Demaille Étienne Renault Roland Levillain first.last@lrde.epita.fr EPITA École Pour l Informatique et les Techniques Avancées April 18, 2017 Intermediate Representations
More informationTranslation. From ASTs to IR trees
Translation From ASTs to IR trees Copyright c 2010 by Antony L. Hosking. Permission to make digital or hard copies of part or all of this work for personal or classroom use is granted without fee provided
More informationIR trees: Statements. IR trees: Expressions. Translating MiniJava. Kinds of expressions. Local variables: Allocate as a temporary t
IR trees: Expressions CONST Integer constant i i NAME Symbolic constant n [a code label] n TEMP Temporary t [one of any number of registers ] t BINOP Application of binary operator: e 1 e 2 ADD, SUB, MUL,
More informationCompiler Construction 2009/2010: Intermediate Representation
Compiler Construction 2009/2010: Intermediate Representation Annette Bieniusa November 24, 2009 Outline 1 Contexts 2 Canonical Trees Using Expressions in different Contexts Compare the translation for
More informationLECTURE 19. Subroutines and Parameter Passing
LECTURE 19 Subroutines and Parameter Passing ABSTRACTION Recall: Abstraction is the process by which we can hide larger or more complex code fragments behind a simple name. Data abstraction: hide data
More informationLanguages and Compiler Design II IR Code Generation I
Languages and Compiler Design II IR Code Generation I Material provided by Prof. Jingke Li Stolen with pride and modified by Herb Mayer PSU Spring 2010 rev.: 4/16/2010 PSU CS322 HM 1 Agenda Grammar G1
More informationIntermediate Code Generation
Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target
More informationCompilation 2013 Semantic Analysis
Compilation 2013 Semantic Analysis Erik Ernst Aarhus University Semantic Analysis The meaning of a program: Above the contextfree level Use general programming to compute well-formedness representation
More informationLecture 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 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 informationLanguage of the Machine Recursive functions
EECS 322 Computer Architecture Language of the Machine Recursive functions Instructor: Francis G. Wolff wolff@eecs.cwru.edu Case Western Reserve University This presentation uses powerpoint animation:
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 informationG Programming Languages - Fall 2012
G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level
More information(Not Quite) Minijava
(Not Quite) Minijava CMCS22620, Spring 2004 April 5, 2004 1 Syntax program mainclass classdecl mainclass class identifier { public static void main ( String [] identifier ) block } classdecl class identifier
More informationCompilation 2014 Code Generation Issues
Compilation 2014 Code Generation Issues Aslan Askarov aslan@cs.au.dk Based on slides by E. Ernst Administrativia November 28 guest lecture by Filip Sieczkowski (AU) Memory Models December 12 guest lecture
More informationCompilation 2014 Activation Records (Part 1)
Compilation 2014 Activation Records (Part 1) Aslan Askarov aslan@cs.au.dk Revised from slides by E. Ernst (Abstract) computer organization Program memory code segment contains program text data segment
More informationSee P&H 2.8 and 2.12, and A.5-6. Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University
See P&H 2.8 and 2.12, and A.5-6 Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University Upcoming agenda PA1 due yesterday PA2 available and discussed during lab section this week
More informationThe Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.
The Compiler So Far CSC 4181 Compiler Construction Scanner - Lexical analysis Detects inputs with illegal tokens e.g.: main 5 (); Parser - Syntactic analysis Detects inputs with ill-formed parse trees
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 Internals. Reminders. Course infrastructure. Registering for the course
Compiler Internals 15-745 Optimizing Compilers Spring 2006 Peter Lee Reminders Get on the course mailing list Check out the web site http://www.cs.cmu.edu/afs/cs/ academic/class/15745-s06/web subscribe
More informationCS 61c: Great Ideas in Computer Architecture
MIPS Functions July 1, 2014 Review I RISC Design Principles Smaller is faster: 32 registers, fewer instructions Keep it simple: rigid syntax, fixed instruction length MIPS Registers: $s0-$s7,$t0-$t9, $0
More informationConnecting Definition and Use? Tiger Semantic Analysis. Symbol Tables. Symbol Tables (cont d)
Tiger source program Tiger Semantic Analysis lexical analyzer report all lexical errors token get next token parser construct variable deinitions to their uses report all syntactic errors absyn checks
More informationCompilation /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 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 informationIntermediate Representations
Intermediate Representations A variety of intermediate representations are used in compilers Most common intermediate representations are: Abstract Syntax Tree Directed Acyclic Graph (DAG) Three-Address
More informationCSE341: Programming Languages Lecture 17 Implementing Languages Including Closures. Dan Grossman Autumn 2018
CSE341: Programming Languages Lecture 17 Implementing Languages Including Closures Dan Grossman Autumn 2018 Typical workflow concrete syntax (string) "(fn x => x + x) 4" Parsing Possible errors / warnings
More informationIntermediate 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 informationCMPT 379 Compilers. Anoop Sarkar. 11/13/07 1. TAC: Intermediate Representation. Language + Machine Independent TAC
CMPT 379 Compilers Anoop Sarkar http://www.cs.sfu.ca/~anoop 11/13/07 1 TAC: Intermediate Representation Language Specific Language + Machine Independent Machine Dependent Front End AST Intermediate Code
More informationCOS 320. Compiling Techniques
Topic 5: Types COS 320 Compiling Techniques Princeton University Spring 2016 Lennart Beringer 1 Types: potential benefits (I) 2 For programmers: help to eliminate common programming mistakes, particularly
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 informationCalling Conventions. Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University. See P&H 2.8 and 2.12
Calling Conventions Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 2.8 and 2.12 Goals for Today Calling Convention for Procedure Calls Enable code to be reused by allowing
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 informationChap. 8 :: Subroutines and Control Abstraction
Chap. 8 :: Subroutines and Control Abstraction Michael L. Scott Programming Language Theory 2015, kkman@sangji.ac.kr 1 Review Of Stack Layout Allocation strategies Static Code Globals Own variables Explicit
More informationCS153: Compilers Lecture 8: Compiling Calls
CS153: Compilers Lecture 8: Compiling Calls Stephen Chong https://www.seas.harvard.edu/courses/cs153 Announcements Project 2 out Due Thu Oct 4 (7 days) Project 3 out Due Tuesday Oct 9 (12 days) Reminder:
More informationWe ve written these as a grammar, but the grammar also stands for an abstract syntax tree representation of the IR.
CS 4120 Lecture 14 Syntax-directed translation 26 September 2011 Lecturer: Andrew Myers We want to translate from a high-level programming into an intermediate representation (IR). This lecture introduces
More informationAnne Bracy CS 3410 Computer Science Cornell University
Anne Bracy CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, McKee, and Sirer. See P&H 2.8 and 2.12, and
More informationCompilers CS S-07 Building Abstract Assembly
Compilers CS414-2017S-07 Building Abstract Assembly David Galles Department of Computer Science University of San Francisco 07-0: Abstract Assembly Trees Once we have analyzed the AST, we can start to
More information6. Names, Scopes, and Bindings
Copyright (C) R.A. van Engelen, FSU Department of Computer Science, 2000-2004 6. Names, Scopes, and Bindings Overview Names Binding time Object lifetime Object storage management Static allocation Stack
More informationCSE 4251: Compiler Construction
CSE 4251: Compiler Construction Ryan Stansifer Department of Computer Sciences Florida Institute of Technology Melbourne, Florida USA 32901 http://www.cs.fit.edu/~ryan/ computer-presentation edition April
More informationCMa simple C Abstract Machine
CMa simple C Abstract Machine CMa architecture An abstract machine has set of instructions which can be executed in an abstract hardware. The abstract hardware may be seen as a collection of certain data
More informationImplementing 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 informationCompilers and Code Optimization EDOARDO FUSELLA
Compilers and Code Optimization EDOARDO FUSELLA Contents Data memory layout Instruction selection Register allocation Data memory layout Memory Hierarchy Capacity vs access speed Main memory Classes of
More informationregsim.scm ~/umb/cs450/ch5.base/ 1 11/11/13
1 File: regsim.scm Register machine simulator from section 5.2 of STRUCTURE AND INTERPRETATION OF COMPUTER PROGRAMS This file can be loaded into Scheme as a whole. Then you can define and simulate 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 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 informationINF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION. Instructors: Crista Lopes Copyright Instructors.
INF 212 ANALYSIS OF PROG. LANGS FUNCTION COMPOSITION Instructors: Crista Lopes Copyright Instructors. Topics Recursion Higher-order functions Continuation-Passing Style Monads (take 1) Identity Monad Maybe
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 informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a
More information1 Lexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-16/cc/ Recap: Static Data Structures Outline of Lecture 18 Recap:
More informationHakim Weatherspoon CS 3410 Computer Science Cornell University
Hakim Weatherspoon CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, McKee, and Sirer. compute jump/branch
More informationTypes II. Hwansoo Han
Types II Hwansoo Han Arrays Most common and important composite data types Homogeneous elements, unlike records Fortran77 requires element type be scalar Elements can be any type (Fortran90, etc.) A mapping
More informationUndergraduate Compilers in a Day
Question of the Day Backpatching o.foo(); In Java, the address of foo() is often not known until runtime (due to dynamic class loading), so the method call requires a table lookup. After the first execution
More informationCPSC 213. Introduction to Computer Systems. Static Control Flow. Unit 1d
CPSC 213 Introduction to Computer Systems Unit 1d Static Control Flow 1 Reading Companion 2.7.1-2.7.3, 2.7.5-2.7.6 Textbook 3.6.1-3.6.5 2 Control Flow The flow of control is the sequence of instruction
More informationPrinciples of Compiler Design
Principles of Compiler Design Intermediate Representation Compiler Lexical Analysis Syntax Analysis Semantic Analysis Source Program Token stream Abstract Syntax tree Unambiguous Program representation
More informationCS A331 Programming Language Concepts
CS A331 Programming Language Concepts Lecture 9 Subroutines March 17, 2014 Sam Siewert Purpose of a Subroutine Control Abstraction perform a well defined operation E.g. transform a color image into a graymap
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ws-1819/cc/ Generation of Intermediate Code Outline of Lecture 15
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 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 informationAnne Bracy CS 3410 Computer Science Cornell University
Anne Bracy CS 3410 Computer Science Cornell University The slides are the product of many rounds of teaching CS 3410 by Professors Weatherspoon, Bala, Bracy, McKee, and Sirer. compute jump/branch targets
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 informationPractical Malware Analysis
Practical Malware Analysis Ch 4: A Crash Course in x86 Disassembly Revised 1-16-7 Basic Techniques Basic static analysis Looks at malware from the outside Basic dynamic analysis Only shows you how the
More informationTranslation to Intermediate Code. Chapter 7
Translation to Intermediate Code Chapter 7 1 Introduction The front end of a compiler parses the input program and creates Abstract Syntax Tree The back end is responsible to create Machine Code It is
More informationCalling Conventions. See P&H 2.8 and Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University
Calling Conventions See P&H 2.8 and 2.12 Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University Goals for Today Review: Calling Conventions call a routine (i.e. transfer control to
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 informationAttributes of Variable. Lecture 13: Run-Time Storage Management. Lifetime. Value & Location
Attributes of Variable Lecture 13 Run-Time Storage Management CSC 131 Kim Bruce Scope Lifetime Location Value Done! Lifetime Value & Location FORTRAN - all allocated statically - Stack-based (C/C++/Java/Pascal/...)
More informationIntermediate Representa.on
IR Intermediate Representa.on CMPT 379: Compilers Instructor: Anoop Sarkar anoopsarkar.github.io/compilers-class Intermediate Representation Language Specific Language + Machine Independent Machine Dependent
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 informationControl in Sequential Languages
CS 242 2012 Control in Sequential Languages Reading: Chapter 8, Sections 8.1 8.3 (only) Section 7.3 of The Haskell 98 Report, Exception Handling in the I/O Monad, http://www.haskell.org/onlinelibrary/io-13.html
More informationLexical Considerations
Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler
More informationProgramming Language Processor Theory
Programming Language Processor Theory Munehiro Takimoto Course Descriptions Method of Evaluation: made through your technical reports Purposes: understanding various theories and implementations of modern
More informationData Abstraction. Hwansoo Han
Data Abstraction Hwansoo Han Data Abstraction Data abstraction s roots can be found in Simula67 An abstract data type (ADT) is defined In terms of the operations that it supports (i.e., that can be performed
More informationCMSC 611: Advanced Computer Architecture
CMSC 611: Advanced Computer Architecture Compilers Some material adapted from Mohamed Younis, UMBC CMSC 611 Spr 2003 course slides Some material adapted from Hennessy & Patterson / 2003 Elsevier Science
More informationAgenda. CSE P 501 Compilers. Big Picture. Compiler Organization. Intermediate Representations. IR for Code Generation. CSE P 501 Au05 N-1
Agenda CSE P 501 Compilers Instruction Selection Hal Perkins Autumn 2005 Compiler back-end organization Low-level intermediate representations Trees Linear Instruction selection algorithms Tree pattern
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 informationCS 360 Programming Languages Interpreters
CS 360 Programming Languages Interpreters Implementing PLs Most of the course is learning fundamental concepts for using and understanding PLs. Syntax vs. semantics vs. idioms. Powerful constructs like
More informationControl 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 informationProf. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University. See P&H 2.8 and 2.12, and A.
Prof. Kavita Bala and Prof. Hakim Weatherspoon CS 3410, Spring 2014 Computer Science Cornell University See P&H 2.8 and 2.12, and A.5 6 compute jump/branch targets memory PC +4 new pc Instruction Fetch
More informationECE 2035 Programming HW/SW Systems Spring problems, 6 pages Exam Two 11 March Your Name (please print) total
Instructions: This is a closed book, closed note exam. Calculators are not permitted. If you have a question, raise your hand and I will come to you. Please work the exam in pencil and do not separate
More informationRuntime 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 informationChapter 8 :: Subroutines and Control Abstraction. Final Test. Final Test Review Tomorrow
Chapter 8 :: Subroutines and Control Abstraction Programming Language Pragmatics Michael L. Scott Administrative Notes Final Test Thursday, August 3 2006 at 11:30am No lecture before or after the mid-term
More informationLecture Code Generation for WLM
Lecture 17+18 Code Generation for WLM CS 241: Foundations of Sequential Programs Winter 2018 Troy Vasiga et al University of Waterloo 1 Code Generation (A9/A10) Input: Output: Number of different outputs:
More informationPrinciples of Programming Languages
Principles of Programming Languages Lecture 06 Implementation of Block Structured Languages 1 Activations and Environment Aspects of Subroutines: Static vs Dynamic! Static subroutine: code (``reentrant
More informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Generation of Intermediate Code Conceptual Structure of
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 informationFall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev
Fall 2015-2016 Compiler Principles Lecture 6: Intermediate Representation Roman Manevich Ben-Gurion University of the Negev Tentative syllabus Front End Intermediate Representation Optimizations Code Generation
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 informationCompiler Construction
Compiler Construction Thomas Noll Software Modeling and Verification Group RWTH Aachen University https://moves.rwth-aachen.de/teaching/ss-17/cc/ Generation of Intermediate Code Outline of Lecture 15 Generation
More information