Overview of Compilation The Compiler BACK End

Slides:



Advertisements
Similar presentations
CPSC 388 – Compiler Design and Construction
Advertisements

Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
CPSC Compiler Tutorial 9 Review of Compiler.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
Compiler Construction1 A Compulsory Module for Students in Computer Science Department Faculty of IT / Al – Al Bayt University First Semester 2009/2010.
Compiler design Computer Science Rensselaer Polytechnic Lecture 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.
Compiled by Benjamin Muganzi 3.2 Functions and Purposes of Translators Computing 9691 Paper 3 1.
CPSC 388 – Compiler Design and Construction Lecture: MWF 11:00am-12:20pm, Room 106 Colton.
Compilation (Chapter 3) 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Introduction to Compiler Construction Robert van Engelen COP5621 Compiler Construction Copyright Robert.
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
1 Semantic Analysis Aaron Bloomfield CS 415 Fall 2005.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1 Languages and Compilers (SProg og Oversættere) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm Hutchinson.
1 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Introduction to Code Generation and Intermediate Representations
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Compilers: Overview/1 1 Compiler Structures Objective – –what are the main features (structures) in a compiler? , Semester 1,
. n COMPILERS n n AND n n INTERPRETERS. -Compilers nA compiler is a program thatt reads a program written in one language - the source language- and translates.
Programming Languages
Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability.
Compiler Introduction 1 Kavita Patel. Outlines 2  1.1 What Do Compilers Do?  1.2 The Structure of a Compiler  1.3 Compilation Process  1.4 Phases.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
What is a compiler? –A program that reads a program written in one language (source language) and translates it into an equivalent program in another language.
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
Language Implementation Overview John Keyser Spring 2016.
©SoftMoore ConsultingSlide 1 Structure of Compilers.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
CS510 Compiler Lecture 1. Sources Lecture Notes Book 1 : “Compiler construction principles and practice”, Kenneth C. Louden. Book 2 : “Compilers Principles,
Compiler Summary Lexical analysis—scanner – String of characters  token – Finite automata. Syntactical analysis – parser – Sequence of tokens –> language.
Open Source Compiler Construction (for the JVM)
Lecture 9 Symbol Table and Attributed Grammars
Intro to compilers Based on end of Ch. 1 and start of Ch. 2 of textbook, plus a few additional references.
Compiler Design (40-414) Main Text Book:
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
Introduction to Compiler Construction
CS 3304 Comparative Languages
Constructing Precedence Table
Compiler Construction (CS-636)
Overview of Compilation The Compiler Front End
Overview of Compilation The Compiler Front End
CS 363 – Chapter 1 What is a programming language? Kinds of languages
Overview of Compilation The Compiler BACK End
An Attribute Grammar for Tiny
Chapter 1 Introduction.
-by Nisarg Vasavada (Compiled*)
课程名 编译原理 Compiling Techniques
Chapter 1: Introduction to Compiling (Cont.)
Compiler Lecture 1 CS510.
Languages and Compilers (SProg og Oversættere)
CS 536 / Fall 2017 Introduction to programming languages and compilers
Introduction to Compiler Construction
CPSC 388 – Compiler Design and Construction
Compiler 薛智文 TH 6 7 8, DTH Spring.
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Compilers B V Sai Aravind (11CS10008).
Compiler 薛智文 TH 6 7 8, DTH Spring.
Compiler design.
Introduction to Compiler Construction
Compiler 薛智文 M 2 3 4, DTH Spring.
Compiler Structures 1. Overview Objective
Introduction to Compiler Construction
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow.
Presentation transcript:

Overview of Compilation The Compiler BACK End COP4620 – Programming Language Translators Dr. Manuel E. Bermudez Translators

PHASE 3: Contextual Constraint Analysis Analyze static semantics: Variables declared before they are used ? Assignment compatibility? e.g., a:=3 Operator type compatibility ? e.g., a+3 Do actual and formal parameter types match? e.g. int f(int n, char c) {…} ... f('x', 3); Enforcement of scope rules. Translators

Contextual Constraint Analysis Traverse the tree recursively Deduce type information at the bottom, Pass type information up the tree. Each node verifies the types below. Make use of a DECLARATION TABLE, to keep track of names and their meaning. Translators

Contextual Constraint Analysis Enter x into the DCLN table, with its type. Check type compatibility for x=5. x2 not declared! Verify type of ’>’ is boolean. Check type compatibility for ‘+’. Check type compatibility between x and int, for assignment. Translators

PHASE 4: code generation Goal: Convert syntax tree to target code. Target code could be: Machine language. Assembly language. Quadruples for a fictional machine: Label, opcode, operands (1 or 2)   Translators

Code Generation Tradeoffs: “gcc” generates assembly code. “javac” generates bytecodes, to be interpreted by the JVM. “gcc”: slow compilation, fast running code. “javac”: fast compilation, slow running code. Speed depends on implementation strategy, not the language ! Code Generation: Traverse the tree again. Translators

Code generation (stack machine) LOAD 5 STORE X LOAD X LOAD 10 BGT COND L1 L2 L1 LOAD X LOAD 1 BADD GOTO L3 L2 ... L3 Text Level 1 Text Level 2 Text Level 3 Translators

Code Optimization Reduce the size of the target program. Decrease the running time of the target. “Optimization” a misnomer. “Code improvement” ? Two types of optimization: Peephole optimization (local). Global optimization (improve loops, etc.). Translators

Code Optimization STORE X LOAD X is replaced with STND X BGT COND L1 L2 L1 LOAD X LOAD 1 BADD GOTO L3 L2 ... L3 LOAD 5 STORE X LOAD X is replaced with STND X STND: Store non-destructive Translators

Summary Parser Source Constrainer Code Generator Code Interpreter Screener Scanner Input Output Table Routines Error Routines Tokens Tree Translators