Lecture 26 Epilogue: Or Everything else you Wanted to Know about Compilers (more accurately Everything else I wanted you to Know) Topics Getreg – Error.

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

Target Code Generation
Semantics Static semantics Dynamic semantics attribute grammars
Intermediate Code Generation
Compiler Construction Sohail Aslam Lecture ExampleExample a = b + c t1 = a * a b = t1 + a c = t1 * b t2 = c + b a = t2 + t2.
1 CS 201 Compiler Construction Machine Code Generation.
Chapter 5 Syntax-Directed Translation. Translation of languages guided by context-free grammars. Attach attributes to the grammar symbols. Values of the.
A simple register allocation optimization scheme.
8 Intermediate code generation
1 Compiler Construction Intermediate Code Generation.
1 Error detection in LR parsing Errors are discovered when a slot in the action table is blank. Canonical LR(1) parsers detect and report the error as.
Lecture 11 – Code Generation Eran Yahav 1 Reference: Dragon 8. MCD
Intermediate Code Generation Professor Yihjia Tsai Tamkang University.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Lecture 23 Basic Blocks Topics Code Generation Readings: 9 April 17, 2006 CSCE 531 Compiler Construction.
Compiler Summary Mooly Sagiv html://
Lecture 25 Generating Code for Basic Blocks Topics Code Generation Readings: April 19, 2006 CSCE 531 Compiler Construction.
Improving Code Generation Honors Compilers April 16 th 2002.
Improving code generation. Better code generation requires greater context Over expressions: optimal ordering of subtrees Over basic blocks: Common subexpression.
Lecture 22 Code Generation Topics Arrays Code Generation Readings: 9 April 10, 2006 CSCE 531 Compiler Construction.
Compiler Construction A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University Second Semester 2008/2009.
Abstract Syntax Trees Lecture 14 Wed, Mar 3, 2004.
Chapter 5 Syntax-Directed Translation Section 0 Approaches to implement Syntax-Directed Translation 1、Basic idea Guided by context-free grammar (Translating.
Topic #5: Translations EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Syntax-Directed Translation
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
Semantic Analysis1 Checking what parsers cannot.
COP4020 Programming Languages Semantics Prof. Xin Yuan.
Lesson 11 CDT301 – Compiler Theory, Spring 2011 Teacher: Linus Källberg.
1 Code Generation Part II Chapter 8 (1 st ed. Ch.9) COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University,
Compiler Chapter# 5 Intermediate code generation.
1 Code Generation Part II Chapter 9 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005.
Chapter 7 Syntax-Directed Compilation (AST & Target Code) 1.
Joey Paquet, 2000, Lecture 10 Introduction to Code Generation and Intermediate Representations.
Introduction to Code Generation and Intermediate Representations
Semantic Analysis CPSC 388 Ellen Walker Hiram College.
1 Code Generation. 2 Position of a Code Generator in the Compiler Model Front-End Code Optimizer Source program Symbol Table Lexical error Syntax error.
Review: Syntax directed translation. –Translation is done according to the parse tree. Each production (when used in the parsing) is a sub- structure of.
Computer Architecture CSE 3322 Lecture 3 Assignment: 2.4.1, 2.4.4, 2.6.1, , Due 2/3/09 Read 2.8.
Compilers Modern Compiler Design
1 Syntax-Directed Translation Part I Chapter 5 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007.
Language Implementation Overview John Keyser Spring 2016.
Chapter 8: Semantic Analyzer1 Compiler Designs and Constructions Chapter 8: Semantic Analyzer Objectives: Syntax-Directed Translation Type Checking Dr.
1 CSC103: Introduction to Computer and Programming Lecture No 17.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 10 Ahmed Ezzat.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
CSE 420 Lecture Program is lexically well-formed: ▫Identifiers have valid names. ▫Strings are properly terminated. ▫No stray characters. Program.
Windows Programming Lecture 03. Pointers and Arrays.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture Ahmed Ezzat.
Code Generation Part I Chapter 8 (1st ed. Ch.9)
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Chapter4 Syntax-Directed Translation Introduction : 1.In the lexical analysis step, each token has its attribute , e.g., the attribute of an id is a pointer.
Chapter 8 Code Generation
Semantic analysis Jakub Yaghob
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Syntax-Directed Translation Part I
Compiler Construction
Intermediate Code Generation
CS 3304 Comparative Languages
Syntax-Directed Translation Part I
Chapter 6 Intermediate-Code Generation
EECE.3170 Microprocessor Systems Design I
COMPILER DESIGN 11CS30013 & 11CS30014 Group October 2013
EECE.3170 Microprocessor Systems Design I
TARGET CODE -Next Usage
Syntax-Directed Translation Part I
Compiler Construction
Code Generation Part II
Syntax-Directed Translation Part I
Review: What is an activation record?
Presentation transcript:

Lecture 26 Epilogue: Or Everything else you Wanted to Know about Compilers (more accurately Everything else I wanted you to Know) Topics Getreg – Error recovery in YACC/Bison Inherited AttributesReadings: April 24, 2006 CSCE 531 Compiler Construction

– 2 – CSCE 531 Spring 2006 Overview Last Time – Lec25 slides 1-18 Questions on Project 5 Code Generation for Basic Blocks Register Allocation Today’s Lecture Getreg Optimizations Peephole optimization Error Recovery Next Time: Exam Thursday April 2:00 in SWGN 2A27 References: Code generation Code generation Error recovery: p 264, p Error recovery: p 264, p Inherited Attributes Inherited Attributes

– 3 – CSCE 531 Spring 2006 GetReg Getreg called for “x := y op z” returns L a good location for the result  If y is in a register that holds no other values, and Y is not live and has no next-use after this statement Then return the register for y for the value of L Update the address and register descriptions  Else return an empty register if there is one.  Else, if x has a next use in the block or op is an operator that requires a register (e.g., array indexing), then find an occupied register R and store the value(s) it contains in memory (mov R, mem)  If x has no next use in the block select the memory location for x as the value for L.

– 4 – CSCE 531 Spring 2006 Example 9.5 and Figure 9.10 Example 9.5 d := (a-b) + (a-c) + (a-c) Yields three address code T1 := a-b T2 := a-c T3 := T1 +T2 T4 := T3 + T2 d := T4 Statements Code Generated Register Descriptor Address Descriptor regs empty T1 := a-b MOV a, R0 SUB b, R0 R0: T1 T1 in R0 T2 := a-c MOV a, R1 SUB b, R1 R0: T1 R1: T2 T1 in R0 T2 in R1 T3:=T1+T2 ADD R1,R0 R0: T3 R1: T2 T3 in R0 T2 in R1 T4:=T3+T2 ADD R1,R0 R0: T4 R1: T2 T4 in R0 T2 in R1 d := T4 … R0: d R1: T2 d in R0 T2 in R1 MOV R0,d R0: d R1: T2 d in R0 and memory

– 5 – CSCE 531 Spring 2006 Generating Code for other Stat.Types Array indexing Array indexing Pointer assignments Pointer assignments Conditional Conditional

– 6 – CSCE 531 Spring 2006 Register Allocation and Assignment

– 7 – CSCE 531 Spring 2006 Register Assignment for Inner Loops

– 8 – CSCE 531 Spring 2006 Register Assignment for Outer Loops

– 9 – CSCE 531 Spring 2006 Register Assignment by Graph Coloring

– 10 – CSCE 531 Spring 2006 Register Assignment in C Register directive – allows the programmer to suggest to the compiler that a variable be put in a register Register directive – allows the programmer to suggest to the compiler that a variable be put in a register

– 11 – CSCE 531 Spring 2006 DAGs – Directed Acyclic Graphs Figure 9.16 – Dag for inner product code

– 12 – CSCE 531 Spring 2006 Peephole Optimization

– 13 – CSCE 531 Spring 2006 Inherited Attributes An attribute that “inherits” a value from its parent or a sibling in the parse tree.

– 14 – CSCE 531 Spring 2006 L attributed Definitions A syntax directed translation id L-attributeds if each inherited attribute of X j, 1 <= j <= n on the right hand side of A  X 1 X 2 … X j … X n depends only on  The attributes of the symbols X 1 X 2 … X j-1 depends to the left of X j-1 in the production and  The inherited attributes of A.

– 15 – CSCE 531 Spring 2006 Declarations and Types Consider D  T {L.inherited := T.type} L T  int{T.type := integer} T  real{T.type := real} L  {L 1.inherited := L.inherited} L 1 ‘,’ id{ addtype(id.place, L.inherited); } L 1 ‘,’ id{ addtype(id.place, L.inherited); } L  id{ addtype(id.place, L.inherited); }

– 16 – CSCE 531 Spring 2006 Bottom-Up Evaluation of Inherited Attributes Section 5.6 If we know where it is on the stack, we can access it.

– 17 – CSCE 531 Spring 2006 Exam Handout