Compiler Construction. Introduction and overview. Görel Hedin. Reviderad 2013-
01-22. 2013. Compiler Construction 2013. F01-1 ...
Compiler Construction Introduction and overview G¨ orel Hedin Reviderad 2013-01-22
2013
Compiler Construction 2013
F01-1
Agenda
Course registration, structure, etc. Course overview
Compiler Construction 2013
F01-2
Course registration
You need to Confirm registration by signing the Registration Form
To unregister Email me
Compiler Construction 2013
F01-3
Prerequisites
Object-oriented programming and Java Algorithms and Data structures (recursion, trees, lists, hash tables, . . . )
Compiler Construction 2013
F01-4
Course information
Web page: http://cs.lth.se/eda180 will be updated during the course
Literature Course material, will be made available on the web site. Lectures, seminars, labs, project, articles Not handed out - print yourself.
Textbook A.W. Appel: Modern Compiler Implementation in Java, 2nd Edition, Cambridge University Press, 2002, ISBN: 0-521-82060-X. Available as an e-book via http://www.lub.lu.se/en/search/lubsearch.html
Compiler Construction 2013
F01-5
Course structure 14 lectures Tuesday 15-17, MA:020 Wednesday 10-12, E:A
5 seminars (give extra points on exam) Thursday 10-12, MA:026 Start this week
6 computer assignments / lab sessions (mandatory) Thursday 13-15 or Friday 10-12 (E:Hacke) Sign up by Thursday Jan 24 (see course web) Start next week Must be completed before exam and course project
Written exam, March 13 Course project, VT2
Compiler Construction 2013
F01-6
People helping with the course
Lectures: G¨ orel Hedin Emma S¨ oderberg
Guest lectures: Roger Henriksson (automatic memory management) Jonas Skeppstedt (code optimization)
Seminars Emma S¨ oderberg
Programming assignments and lab sessions Niklas Fors ¨ Jesper Oqvist
Compiler Construction 2013
F01-7
Seminars
Active participation gives extra points at the exam Before the seminar Try to solve the problems at home. Write down your solutions, bring them with you, be prepared to present them at the seminar.
At the seminar Mark the problems you are willing to present solutions for. The seminar leader selects some students to present their solutions. Discussion of the solutions.
At the written exam (Note! Only for exams this year) Your markings will give you a maximum of 10% extra points at the written exam.
Compiler Construction 2013
F01-8
Programming assignments / Lab sessions
Work in pairs Use the lecture break to form pairs! Make the preparations before each lab session. If you complete the assignment in advance, you must anyway go to the lab session to get it approved.
Compiler Construction 2013
F01-9
Examination
Exams take place Wednesday, March 13, 8-13, Sparta:D Friday, August 30, 8-13, Victoriastadion 1A (1 week advance registration required)
Prerequisites Completed programming assignments
Compiler Construction 2013
F01-10
Project
Standard project Design of a small procedural language Implementation of a compiler from source text to Intel assembly code
Work in pairs Deadlines Intermediate deadlines given later Final deadline for completed and approved project: May 3rd
Compiler Construction 2013
F01-11
Project outcome source code
compiler
assembly code
Compiler Construction 2013
F01-12
Project outcome source code
csum = a + b + 1;
compiler
assembly code
Compiler Construction 2013
movl a, %eax addl b, %eax addl $1, %eax movl %eax, csum
F01-12
What happens after compilation?
source code
assembler
object code
library object code
compiler linker assembly code
Compiler Construction 2013
machine code
loader
machine memory
F01-13
A closer look at the compiler source code
lexical analysis
intermediate code generation
syntactic analysis
optimization
semantic analysis
Compiler Construction 2013
machine code generation
machine code
F01-14
Intermediate representations source code
lexical analysis
intermediate code generation
tokens
intermediate code
syntactic analysis
attributed AST
optimization
AST
intermediate code
semantic analysis
machine code generation
analysis Compiler Construction 2013
machine code
synthesis F01-15
Front and back end source code
lexical analysis
intermediate code generation
syntactic analysis
optimization
semantic analysis front end Compiler Construction 2013
machine code generation
machine code
back end F01-16
Intermediate code
FrontEndL
intermediate code
BackEndIntel
Compiler Construction 2013
F01-17
Several front and back ends
FrontEndL
FrontEndC
FrontEndPL0
intermediate code
BackEndIntel
Compiler Construction 2013
BackEndMIPS
Interpreter
F01-18
Why?
It is more rational to implement m front ends + n back ends than m ∗ n compilers. Many optimizations are best performed on intermediate code. It may be easier to debug the front end using an interpreter than a target machine.
Compiler Construction 2013
F01-19
Compilation and Interpretation
A compiler translates a high level program to low level/machine code. An interpreter executes a high/low level program by calling one procedure for each program construct. An interpreter may use a JIT (“just in time”) compiler to compile all or parts of the the program into machine code during execution.
Compiler Construction 2013
F01-20
Program representations source code
lexical analysis
intermediate code generation
tokens
intermediate code
syntactic analysis
attributed AST
optimization
AST
intermediate code
semantic analysis
machine code generation
Compiler Construction 2013
machine code
F01-21
Lexical analysis (scanning)
Source text
Tokens
while (k