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.
Code Generation Mooly Sagiv html:// Chapter 4.
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.
Cs164 Prof. Bodik, Fall Symbol Tables and Static Checks Lecture 14.
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.
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.
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.
. 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.
CS 153: Concepts of Compiler Design September 30 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
Semantic Analysis II Type Checking EECS 483 – Lecture 12 University of Michigan Wednesday, October 18, 2006.
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.
1 Languages and Compilers (SProg og Oversættere) Semantic Analysis.
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
An Attribute Grammar for Tiny
Chapter 1 Introduction.
-by Nisarg Vasavada (Compiled*)
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
课程名 编译原理 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
CMPE 152: Compiler Design December 5 Class Meeting
Introduction to Compiler Construction
CPSC 388 – Compiler Design and Construction
Compiler 薛智文 TH 6 7 8, DTH Spring.
Chapter 6 Intermediate-Code Generation
Lecture 15 (Notes by P. N. Hilfinger and R. Bodik)
Overview of Compilation The Compiler BACK End
Compilers B V Sai Aravind (11CS10008).
Compiler design.
Introduction to Compiler Construction
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 Module 02.2 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez

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.

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.

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.

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)  

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.

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

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.).

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

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