Professional Documents
Culture Documents
BITS Pilani
Hyderabad Campus
BITS Pilani
Hyderabad Campus
Todays Agenda
General course information Objectives Reasons to take this course Course Logistics
Course outline
Overview of compiler phases
CS C362 Second Semester 2013-14 BITS Pilani, Hyderabad Campus
Office: B226
Email: arunam@hyderabad.bits-pilani.ac.in Chamber Consultation : Monday 4:00-5:00pm
Objectives
The goal of this course is to give a working knowledge of the basic techniques used in the implementation of modern programming languages. The course is centered around a substantial programming project: implementing front end compiler for a realistic language. Students successfully completing this course will be able to apply the theory and methods learned during the course to design and implement optimizing compilers for most programming languages.
CS C362 Second Semester 2013-14 BITS Pilani, Hyderabad Campus
Course Motivation
Why build compilers? Why study Compiler Design / Construction?
Books
Course Logistics
Grading Policy
5%
Quiz
Project
35%
20%
20% 20%
*Prescribed Text book, References and only Hand-Written Notes Permitted. Timeliness Assignments are to be completed in time with no postponements. Submissions 24 hours from deadline will have a penalty of 2 Marks per day.
CS C362 Second Semester 2013-14 BITS Pilani, Hyderabad Campus
Course Outline
Introduction to Compilers
Lexical Analysis
Syntax Analysis Semantic Analysis / Syntax Directed Translation Intermediate Code Generation Special aspects of compilers and runtime Code Optimization Code Generation
CS C362 Second Semester 2013-14 BITS Pilani, Hyderabad Campus
Why Compilers ?
Translator
Interest
Compiler construction is a microcosm of computer science.
Artificial intelligence Greedy algorithms Learning algorithms Algorithms Theory Graph algorithms Union-find dynamic programming DFAs for scanning Parser generators Lattice theory For analysis Inside a compiler, all these things come together
Systems
Architecture
Challenges
Building a compiler requires knowledge of
Abstract view
Source Code Compiler Errors
Target Code
Functions:
Program Translation
Program in L1 Translation
Program in L2
Compilation
Program in L1 Program in M2
Compilation
L1 Source Language M2 Target Language (machine lang. Or assembly lang.)
The compiled program M2 can be executed (if it is in machine language) this duration is referred to as run-time
The compilation duration is referred to as compile-time.
CS C362 Second Semester 2013-14 BITS Pilani, Hyderabad Campus
Separate Compilation
Module 1 in L1 Compilation Module 1 in A2 Assembly Module 2 in A2 Compilation Assembly Linking L1 Source Language Module 1 in M3
Module 2 in L1
Module 2 in M3
A2 Assembly Language
M3 Machine Language
Execution
Program in M3
Run-Time
Program in M3
L1 Source Language
A2 Assembly Language
M3 Machine Language
Program Compilation
Program in IL Program in L1 Compilation L1 Source Language M2 Target Language (of a machine architecture) IL Intermediate Language (Intermediate Representation) Example: gcc compiles C programs to (say) 80x86 programs. It uses trees as IL. Program in M2
Note: Having an IL stage modularizes the compiler; improves testing of compiler. End of Note.
CS C362 Second Semester 2013-14 BITS Pilani, Hyderabad Campus
Optimizes IRs Generates machine code from assembly code Optimizes the code using control-flow and data-flow analyses, register allocation, etc
CS C362 Second Semester 2013-14 BITS Pilani, Hyderabad Campus
Addressing Portability
Suppose you want to write compilers from m source languages to n computer platforms.
Virtual Machines
Sometimes IL is useful for other purposes:
It may be used as a target for many source languages; It may be used as a source for many target machines.
Virtual Machines
Interpretation
L1 Source Language M2 Target Language (of a machine architecture) VM Virtual machine (a machine capable of understanding an Intermediate Language program)
Virtual Machines
Virtual machines save compiler development effort:
Compilation
Program P coded in L1 Comp(L1,M2,M2) Program P coded in M2
Program P coded in C
gcc(x86,x86) = Comp(C,x86,x86)
gcc(x86,x86) = Comp(C,x86,x86)
Comp(L1,M2,M3)
Bootstrapping
A compiler is characterized by three languages:
Source Language (s) Target Language (T) Implementation Language (I)
A Compiler may run on one machine and produce code for another machine. (Cross Compiler) Suppose we write a cross compiler in S in implementation language I to generate code for machine N i.e we create SI N.
Summary
Course related stuff(Logistics, Motivation , Overview) Why Compilers? Compiler phases