Advanced Topics in MNIT. Lecture 1 (27 Aug 2015) CADSL

Similar documents
Compiler Optimization Intermediate Representation

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

A simple syntax-directed

Compiling Regular Expressions COMP360

COMP455: COMPILER AND LANGUAGE DESIGN. Dr. Alaa Aljanaby University of Nizwa Spring 2013

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

Crafting a Compiler with C (II) Compiler V. S. Interpreter

LECTURE 3. Compiler Phases

Lexical Scanning COMP360

EDA180: Compiler Construc6on Context- free grammars. Görel Hedin Revised:

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

EDA180: Compiler Construc6on. Top- down parsing. Görel Hedin Revised: a

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

Formats of Translated Programs

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

Where we are. What makes a good IR? Intermediate Code. CS 4120 Introduction to Compilers

LECTURE NOTES ON COMPILER DESIGN P a g e 2

Computer Architecture

Principles of Programming Languages

Formal Languages and Compilers Lecture I: Introduction to Compilers

What do Compilers Produce?

COMPILER DESIGN LECTURE NOTES

Compiler Design (40-414)

Undergraduate Compilers in a Day

2068 (I) Attempt all questions.

A Simple Syntax-Directed Translator

CST-402(T): Language Processors

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Principles of Programming Languages

CS453 Compiler Construction

CA Compiler Construction

List of Figures. About the Authors. Acknowledgments

Theory and Compiling COMP360

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

COSE312: Compilers. Lecture 1 Overview of Compilers

Compilers and Interpreters

Ways to implement a language

CS 406/534 Compiler Construction Putting It All Together


CS 314 Principles of Programming Languages. Lecture 3

Related Course Objec6ves

History of Compilers The term

CS 314 Principles of Programming Languages

Compila(on /15a Lecture 6. Seman(c Analysis Noam Rinetzky

Working of the Compilers

The Structure of a Syntax-Directed Compiler

The Structure of a Syntax-Directed Compiler

CS5363 Final Review. cs5363 1

Fall Compiler Principles Lecture 6: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

CS 4201 Compilers 2014/2015 Handout: Lab 1

Front End. Hwansoo Han

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

CSE P 501 Compilers. Intermediate Representations Hal Perkins Spring UW CSE P 501 Spring 2018 G-1

CS415 Compilers Overview of the Course. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

Compilers and Code Optimization EDOARDO FUSELLA

Pioneering Compiler Design


Compiler, Assembler, and Linker

Introduction. Compilers and Interpreters

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

Compiler Code Generation COMP360

TDDD55 - Compilers and Interpreters Lesson 3

Compiler: Control Flow Optimization

An Overview of Compilation

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

Downloaded from Page 1. LR Parsing

CSE 401/M501 Compilers

CD Assignment I. 1. Explain the various phases of the compiler with a simple example.

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

Compilers. Lecture 2 Overview. (original slides by Sam

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

COMPILERS AND INTERPRETERS Lesson 4 TDDD16

CS415 Compilers. Lexical Analysis

Compiler Construction LECTURE # 1

The Structure of a Compiler

CS 61C: Great Ideas in Computer Architecture Func%ons and Numbers

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

Lexical Analysis. Introduction

Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer

Compiler Structure. Lexical. Scanning/ Screening. Analysis. Syntax. Parsing. Analysis. Semantic. Context Analysis. Analysis.

CS 415 Midterm Exam Spring SOLUTION

Static Semantics. Winter /3/ Hal Perkins & UW CSE I-1

Compilers. History of Compilers. A compiler allows programmers to ignore the machine-dependent details of programming.

Compilers. Compiler Construction Tutorial The Front-end

Compiling Techniques

1. The output of lexical analyser is a) A set of RE b) Syntax Tree c) Set of Tokens d) String Character

Program Analysis ( 软件源代码分析技术 ) ZHENG LI ( 李征 )

4. An interpreter is a program that

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Introduction to Java Programming

Compilers. Computer Science 431

Life Cycle of Source Program - Compiler Design

1. INTRODUCTION TO LANGUAGE PROCESSING The Language Processing System can be represented as shown figure below.

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

Introduction. CS 2210 Compiler Design Wonsun Ahn

Fall Compiler Principles Lecture 5: Intermediate Representation. Roman Manevich Ben-Gurion University of the Negev

Transcription:

Compiler Construction Virendra Singh Computer Architecture and Dependable Systems Lab Department of Electrical Engineering Indian Institute of Technology Bombay http://www.ee.iitb.ac.in/~viren/ E-mail: viren@ee.iitb.ac.in Advanced Topics in Computing @ MNIT Lecture 1 (27 Aug 2015)

Problem Solving: Main Steps 1. Problem defini/on 2. Algorithm design/ Algorithm specifica/on 3. Algorithm analysis 4. Implementa/on 5. Tes/ng 6. [Maintenance] 27 Aug 2015 virendra@mnit 2

From Source to Executable source program foo.c main() sub1() data Compiler sta;c library libc.a prin9 scanf gets fopen exit data... object modules foo.o main sub1 data Linkage Editor load module a.out main sub1 data prin9 exit data Load ;me (Run Time) Loader Machine memory? other programs... main sub1 data prin9 exit data other...... kernel (system calls) Dynamic library case not shown 27 Aug 2015 virendra@mnit 3

Running Program on Processor Time Processor Performance = - - - - - - - - - - - - - - - Program Instructions Cycles = X X Program Instruction Time Cycle (code size) (CPI) (cycle time) Architecture - - > Implementa;on - - > Realiza;on Compiler Designer Processor Designer Chip Designer 27 Aug 2015 virendra@mnit 4

Iron Law Instruc/ons/Program Ø Instruc/ons executed, not sta/c code size Ø Determined by algorithm, compiler, ISA Cycles/Instruc/on Ø Determined by ISA and CPU organiza/on Ø Overlap among instruc/ons reduces this term Time/cycle Ø Determined by technology, organiza/on, clever circuit design 27 Aug 2015 virendra@mnit 5

What is a compiler? A program that reads a program wrisen in one language and translates it into another language. Source language Target language Tradi/onally, compilers go from high- level languages to low- level languages. 27 Aug 2015 virendra@mnit 6

Compilers Common compila/on tasks Language transla/on Error checking and report Performance improvement Fundamental compila/on principles ü The compiler must preserve the meaning of source program ü The compiler must improve the source program in some discernible way 27 Aug 2015 virendra@mnit 7

Compilers Evolution In the beginning, there was machine language Ugly wri/ng code, debugging Then came textual assembly s/ll used on DSPs High- level languages Fortran, Pascal, C, C++ Machine structures became too complex and so]ware management too difficult to con/nue with low- level languages 27 Aug 2015 virendra@mnit 8

Why are Compilers Important? Computer architecture Build processors that so]ware can be automa/cally mapped to efficiently Exploi/ng hardware features CAD tools Behavioral synthesis / C- to- gates tools are hardware compilers Use program analysis/op/miza/on to generate cheaper hardware So]ware developers How do I create a compiler? How does it map my code to the hardware 27 Aug 2015 virendra@mnit 9

Compiler Architecture In more detail: Intermediate Language Source Language Front End language specific Back End machine specific Target Language Separa/on of Concerns Retarge/ng 27 Aug 2015 virendra@mnit 10

Compiler Architecture Intermediate Language Intermediate Language Source language Scanner (lexical analysis) tokens Parser (syntax analysis) Syntactic structure Semantic Analysis (IC generator) Code Optimizer Code Generator Target language Symbol Table 27 Aug 2015 virendra@mnit 11

Translation of an assignment Translation of an assignment statement 27 Aug 2015 virendra@mnit 12

Lexical Analysis Character stream è token stream Recognize words of a language Theore/cal problem: specify and recognize paserns in strings Scanner as a prac/cal applica/on Regular expression, finite automata Tools that automa/cally generate scanners are commonly used Input: After scanning: index := start + step * 20 index := start + step * 20 identifier operator number 27 Aug 2015 virendra@mnit 13

Syntactical Analysis Token stream è syntax tree Recognize sentences of a language Grammars and parsers CFG Parsers can be automa/cally generated Top- down and bosom- up parsing Predic/ve parsing Driven process of compiler front- ends After scanning: index := start + step * 20 index After parsing: Assign ID := Exp ID start Exp + Exp Exp ID * Exp Num step 20 27 Aug 2015 virendra@mnit 14

Semantic Analysis The seman/c analyzer uses the syntax tree and the informa/on in the symbol table to check the source program for seman/c consistency with the language defini/on. Gathers type informa/on and saves it in either the syntax tree or the symbol table, for subsequent use during intermediate- code genera/on. An important part of seman/c analysis is type checking, where the compiler checks that each operator has matching operands. Ø For example, many programming language defini/ons require an array index to be an integer; the compiler must report an error if a floa/ng- point number is used to index an array. 27 Aug 2015 virendra@mnit 15

Semantic Analysis The language specifica/on may permit some type conversions called coercions. For example, a binary arithme/c operator may be applied to either a pair of integers or to a pair of floa/ng- point numbers. If the operator is applied to a floa/ng- point number and an integer, the compiler may convert or coerce the integer into a floa/ng- point number. 27 Aug 2015 virendra@mnit 16

Semantic Analysis Understand/annotate meaning of the program Syntax- directed transla/on Check seman/c errors Inconsistent variable defini/ons and uses Type systems Collect knowledge of the input program Symbol tables Scopes 27 Aug 2015 virendra@mnit 17

Compiler Architecture Intermediate Language Intermediate Language Source language Scanner (lexical analysis) tokens Parser (syntax analysis) Syntactic structure Semantic Analysis (IC generator) Code Optimizer Code Generator Target language Symbol Table 27 Aug 2015 virendra@mnit 18

General Structure of a Modern Compiler Source Program Lexical Analysis Scanner Context Symbol Table CFG Syntax Analysis Parser Front end Build high-level IR Semantic Analysis High-level IR to low-level IR conversion Controlflow/Dataflow Optimization Back end Assembly Code Code Generation Machine independent asm to machine dependent 27 Aug 2015 virendra@mnit 19

Multiple IRs Most compilers use 2 IRs: High- level IR (HIR): Language independent but closer to the language Low- level IR (LIR): Machine independent but closer to the machine A significant part of the compiler is both language and machine independent! C++ C Fortran AST optimize HIR optimize LIR optimize Pentium Java bytecode Itanium TI C5x ARM 27 Aug 2015 virendra@mnit 20

Thank You 27 Aug 2015 virendra@mnit 21