COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 10, 10/30/2003 Prof. Roy Levow.

Slides:



Advertisements
Similar presentations
Target Code Generation
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
Intermediate Code Generation
Compilation 2011 Static Analysis Johnni Winther Michael I. Schwartzbach Aarhus University.
1 CS 201 Compiler Construction Machine Code Generation.
8. Code Generation. Generate executable code for a target machine that is a faithful representation of the semantics of the source code Depends not only.
Intermediate Representations Saumya Debray Dept. of Computer Science The University of Arizona Tucson, AZ
1 Compiler Construction Intermediate Code Generation.
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
Compiler construction in4020 – lecture 7 Koen Langendoen Delft University of Technology The Netherlands.
Program Representations. Representing programs Goals.
Compiler Construction Sohail Aslam Lecture IR Taxonomy IRs fall into three organizational categories 1.Graphical IRs encode the compiler’s knowledge.
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
CS412/413 Introduction to Compilers Radu Rugina Lecture 16: Efficient Translation to Low IR 25 Feb 02.
CPSC Compiler Tutorial 9 Review of Compiler.
Compiler construction in4020 – lecture 8 Koen Langendoen Delft University of Technology The Netherlands.
Code Generation Mooly Sagiv html:// Chapter 4.
Representing programs Goals. Representing programs Primary goals –analysis is easy and effective just a few cases to handle directly link related things.
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
Cse321, Programming Languages and Compilers 1 6/19/2015 Lecture #18, March 14, 2007 Syntax directed translations, Meanings of programs, Rules for writing.
Code Generation Simple Register Allocation Mooly Sagiv html:// Chapter
Prof. Bodik CS 164 Lecture 171 Register Allocation Lecture 19.
Code Generation for Basic Blocks Introduction Mooly Sagiv html:// Chapter
Annotating Abstract Syntax Tree Professor Yihjia Tsai Tamkang University.
Code Generation Mooly Sagiv html:// Chapter 4.
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
Compiler Summary Mooly Sagiv html://
Intermediate Code. Local Optimizations
Topic 6 -Code Generation Dr. William A. Maniatty Assistant Prof. Dept. of Computer Science University At Albany CSI 511 Programming Languages and Systems.
Improving Code Generation Honors Compilers April 16 th 2002.
Introduction to Code Generation Mooly Sagiv html:// Chapter 4.
Prof. Fateman CS164 Lecture 211 Local Optimizations Lecture 21.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
Code Generation Mooly Sagiv html:// Chapter 4.
4. Processing the intermediate code From: Chapter 4, Modern Compiler Design, by Dick Grunt et al.
1 Lecture 11: Semantic Analysis (Section ) CSCI 431 Programming Languages Fall 2002 A modification of slides developed by Felix Hernandez-Campos.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Syntax Directed Translation. Syntax directed translation Yacc can do a simple kind of syntax directed translation from an input sentence to C code We.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
CS412/413 Introduction to Compilers and Translators May 3, 1999 Lecture 34: Compiler-like Systems JIT bytecode interpreter src-to-src translator bytecode.
Compiler Chapter# 5 Intermediate code generation.
ISBN Chapter 3 Describing Semantics -Attribute Grammars -Dynamic Semantics.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 3, 09/11/2003 Prof. Roy Levow.
Chapter 7 Syntax-Directed Compilation (AST & Target Code) 1.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 6, 10/02/2003 Prof. Roy Levow.
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Chapter 2. Design of a Simple Compiler J. H. Wang Sep. 21, 2015.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 1, 08/28/03 Prof. Roy Levow.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
ISBN Chapter 3 Describing Semantics.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Winter Compilers Software Eng. Dept. – Ort Braude Compiling Assignments and Expressions Lecturer: Esti Stein brd4.ort.org.il/~esti2.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
PZ03CX Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03CX - Language semantics Programming Language Design.
Context-Sensitive Analysis
A Simple Syntax-Directed Translator
Compiler Construction
Target Code Generation
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow.
Presentation transcript:

COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 10, 10/30/2003 Prof. Roy Levow

Attribute Grammars: Manual Methods Attribute grammars and evaluators provide a useful framework for providing context to a program But the technology is not yet well developed And it can be difficult to use Thus, manual methods are frequently used

Manual Methods.2 Symbolic Interpretation –Uses interpreter approach on AST to compute attributes Data-flow Equations –More general technique based on set equations to reveal relationships among attributes

Symbolic Interpretation Control flow graph can be constructed by threading nodes of AST –Possibly adding nodes for simplicity –A threading rule is provided for each kind of node Then simulate run-time behavior of program Requires wide compiler

Flow Control & Threading

Flow Control & Threading.2

Flow Control & Threading.3

Flow Control & Threading.4

Symbolic Interpretation Attach a stack representation to each arrow in the control flow graph indicating the items that might be on the stack at that time in program execution with relevant attributes Cal also identify features such as uninitialized variables

Stack Representation of If

Symbolic Interpretation of If

Data Flow Equations –Used on well-structured programs –Used to evaluate properties of data values across a program Liveness (accessed later) Initialized before use –Describe condition leaving block in terms of condition on entry and effects of block

Data Flow Equations.2 Example –Can be used to check for uninitialized variables –Solve by setting conditions for entry to initial block and compute closure

Intermediate Code Intermediate Code is usually tree structured like the AST –But may be linear or have other forms Intermediate Code features –Expressions, including assignment –Routine class, Procedure headings, Returns –Conditional and unconditional jumps –Administrative activities

Intermediate Code.2 Assume wide compiler Traverse AST replacing language context structures with intermediate code instructions Produce is Intermediate Code Tree but is often still referred to as AST (Skipping 4.1 on Interpretation)

Code Generation Can be viewed as tree rewriting –In which tree branches are replaced by linear code –Working through threaded AST

Simple Code Generation Stack Machine Identify code for each node Replace node with corresponding code Emit code in bottom-up order

Example for Stack Machine

Example for Stack Machine.2

Example for Stack Machine.3

Emit Code for Stack Machine

Emitted Stack Machine Code Push_Local #b Mult_Top2 Push_Cosnt4 Push_Local #a Push_Local #c Mult_Top2 Subtr_Top2

Execution Profile for Stack Machine

Simple Code Generation Register Machine Need to assign computational values to registers –Normally start with unlimited number of registers in intermediate code and then handle actual limitations –Follow machine architecture for one or both operands in registers –May specify target register for result or not

Register Code for AST Nodes

Register Code Generation with Register Numbering

Generated Register Code

Register Code Generation When the number of registers is limited and more are needed than are available Spill values from registers to memory See example with 2 registers on next slide