Ch1_Introduction
Ch1_Introduction
Introduction to compiler
design
I
deally:
Source Compiler Executab
le
code
Output
Input Executable data
Source
Output
data
code Interpreter data
Input data
i.e
.
Linkers - a computer
program that takes one or
more object files generated by
compilers or assemblers and
combines them into a single
executable program.
preprocessor
modified source program
compiler
target assembly program
assembler
relocatable machine code
linker/loader Library
files
target machine code
languages
Chapter – 1 : Introduction to Compiler Design 19 Bahir Dar Institute of Technology
Why Study
Become a better programmer
Compilers?
Insight into interaction between languages, compilers, and
hardware
Compiler techniques are everywhere
Parsing (little languages, interpreters, HTML)
Database engines, query languages
Text processing
Fascinating blend of theory and engineering
Direct applications of theory to practice
Parsing, scanning, static analysis
Resource allocation, “optimization”, etc.
You might even write a compiler some day!
Chapter – 1 : Introduction to Compiler Design 20 Bahir Dar Institute of Technology
Grouping of Phases into Passes /Parts of compilation
Compiler is not a single box that maps a source program into a target
program.
There are two parts to this mapping: analysis and synthesis
• Analysis (front part) [Lexical, Syntax, and Semantic analysis]
• breaks up the source program into constituent pieces
• Creates an intermediate representation of the source program
• Reports any error detected
• Stores source program info in a data structure called a symbol table
• Machine Independent/Language Dependent. b/c they depend
primarily on the source language
• Synthesis (Back part)[Code Generation + Code
Optimization]
• constructs the desired target program from the
intermediate representation and the information in the
symbol table.
• Machine Dependent. b/c they depend on the target
machine/Language independent
Compilation process operates as a sequence of phases,
• –each
Chapter 1 : Introduction to Compilerone
of which transforms Design 21
representation of the
Bahir Darsource program
Institute of Technology
The Phases of a
Compiler…
code only.
Just-in-time Compiler
A compiler which converts the code into
machine code after the program starts execution.
Retargetable Compiler
A compiler that can be easily modified to
compile a source code for different CPU
architectures.
Parallelizing Compiler
A Compiler capable of compiling a code in parallel
computer architecture.
Chapter – 1 : Introduction to Compiler Design 36 Bahir Dar Institute of Technology
Types of compiler
One pass Compiler
The compiler which completes whole compilation