SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
Lecture Notes on
               Compiler Design: Overview

                        15-411: Compiler Design
                            Frank Pfenning

                               Lecture 1
                             August 24, 2009



1   Introduction
This course is a thorough introduction to compiler design, focusing on
more low-level and systems aspects rather than high-level questions such
as polymorphic type inference or separate compilation. You will be build-
ing several complete end-to-end compilers for successively more complex
languages, culminating in a mildly optimizing compiler for a safe variant
of the C programming language to x86-64 assembly language. For the last
project you will have the opportunity to optimize more aggressively, to im-
plement a garbage collector, or retarget the compiler to an abstract machine.
    In this overview we review the goals for this class and give a general
description of the structure of a compiler. Additional material can be found
in the optional textbook [App98, Chapter 1].


2   Goals
After this course you should know how a compiler works in some depth. In
particular, you should understand the structure of a compiler, and how the
source and target languages influence various choices in its design. It will
give you a new appreciation for programming language features and the
implementation challenges they pose, as well as for the actual hardware ar-
chitecture and the runtime system in which your generated code executes.
Understanding the details of typical compilation models will also make
you a more discerning programmer.

L ECTURE N OTES                                             A UGUST 24, 2009
L1.2                                            Compiler Design: Overview


    You will also understand some specific components of compiler tech-
nology, such as lexical analysis, grammars and parsing, type-checking, in-
termediate representations, static analysis, common optimizations, instruc-
tion selection, register allocation, code generation, and runtime organiza-
tion. The knowledge gained should be broad enough that if you are con-
fronted with the task of contributing to the implementation of a real com-
piler in the field, you should be able to do so confidently and quickly.
    For many of you, this will be the first time you have to write, main-
tain, and evolve a complex piece of software. You will have to program
for correctness, while keeping an eye on efficiency, both for the compiler
itself and for the code it generates. Because you will have to rewrite the
compiler from lab to lab, and also because you will be collaborating with a
partner, you will have to pay close attention to issues of modularity and in-
terfaces. Developing these software engineering and system building skills
are an important goal of this class, although we will rarely talk about them
explicitly.


3      Compiler Requirements
As we will be implementing several compilers, it is important to under-
stand which requirement compilers should satisfy. We discuss in each case
to what extent it is relevant to this course.

Correctness. Correctness is absolutely paramount. A buggy compiler is
next to useless in practice. Since we cannot formally prove the correctness
of your compilers, we use extensive testing. This testing is end-to-end, ver-
ifying the correctness of the generated code on sample inputs. We also ver-
ify that your compiler rejects programs as expected when the input is not
well-formed (lexically, syntactically, or with respect to the static semantics),
and that the generated code raises an exception as expected if the language
specification prescribes this. We go so far as to test that your generated
code fails to terminate (with a time-out) when the source program should
diverge.
    Emphasis on correctness means that we very carefully define the se-
mantics of the source language. The semantics of the target language is
given by the GNU assembler on the lab machines together with the seman-
tics of the actualy machine. Unlike C, we try to make sure that as little
as possible about the source language remains undefined. This is not just
for testability, but also good language design practice since an unambigu-

L ECTURE N OTES                                               A UGUST 24, 2009
Compiler Design: Overview                                                L1.3


ously defined language is portable. The only part we do not fully define
are precise resource constraints regarding the generated code (for example,
the amount of memory available).


Efficiency. In a production compiler, efficiency of the generated code and
also efficiency of the compiler itself are important considerations. In this
course, we set very lax targets for both, emphasizing correctness instead. In
one of the later labs in the course, you will have the opportunity to optimize
the generated code.
    The early emphasis on correctness has consequences for your approach
to the design of the implementation. Modularity and simplicity of the code
are important for two reasons: first, your code is much more likely to be
correct, and, second, you will be able to respond to changes in the source
language specification from lab to lab much more easily.


Interoperability. Programs do not run in isolation, but are linked with
library code before they are executed, or will be called as a library from
other code. This puts some additional requirements on the compiler, which
must respect certain interface specifications.
    Your generated code will be required to execute correctly in the environ-
ment on the lab machines. This means that you will have to respect calling
conventions early on (for example, properly save callee-save registers) and
data layout conventions later, when your code will be calling library func-
tions. You will have to carefully study the ABI specification [MHJM09] as
it applies to C and our target architecture.


Usability. A compiler interacts with the programmer primarily when there
are errors in the program. As such, it should give helpful error messages.
Also, compilers may be instructed to generate debug information together
with executable code in order help users debug runtime errors in their pro-
gram.
    In this course, we will not formally evaluate the quality or detail of your
error messages, although you should strive to achieve at least a minimum
standard so that you can use your own compiler effectively.


Retargetability. At the outset, we think of a compiler of going from one
source language to one target language. In practice, compilers may be re-
quired to generate more than one target from a given source (for example,

L ECTURE N OTES                                             A UGUST 24, 2009
L1.4                                            Compiler Design: Overview


x86-64 and ARM code), sometimes at very different levels of abstraction
(for example, x86-64 assembly or LLVM intermediate code).
    In this course we will deemphasize retargetability, although if you struc-
ture your compiler following the general outline presented in the next sec-
tion, it should not be too difficult to retrofit another code generator. One of
the options for the last lab in this course is to retarget your compiler to pro-
duce code in a low-level virtual machine (LLVM). Using LLVM tools this
means you will be able to produce efficient binaries for a variety of concrete
machine architectures.


4        The Structure of a Compiler
Certain general common structures have arisen over decades of develop-
ment of compilers. Many of these are based on experience and sound en-
gineering principles rather than any formal theory, although some parts,
such as parsers, are very well understood from the theoretical side. The
overall structure of a typical compiler is shown in Figure 1.
    In this course, we will begin by giving you the front and middle ends
of a simple compiler for a very small language, and you have to write the
back end, that is, perform instruction selection and register allocation. Con-
sequently, Lectures 2 and 3 will be concerned with instruction selection and
register allocation, respectively, so that you can write your own.
    We then turn to the front end and follow through the phases of a com-
piler in order to complete the picture, while incrementally complicating
the language features you have to compile. Roughly, we will proceed as
follows, subject to adjustment throughout the course:

    1. A simple expression language

    2. Loops and conditionals

    3. Functions

    4. Structs and arrays

    5. Memory safety and basic optimizations

The last lab is somewhat open-ended and allows either to implement fur-
ther optimizations, a garbage collector, or a new back end which uses the
low-level virtual machine (LLVM)1 .
    1
        See http://llvm.org


L ECTURE N OTES                                               A UGUST 24, 2009
Compiler Design: Overview                                                    L1.5




                     Figure 1: Structure of a typical compiler2


References
[App98]        Andrew W. Appel. Modern Compiler Implementation in ML.
               Cambridge University Press, Cambridge, England, 1998.

[MHJM09] Michael Matz, Jan Hubi˘ ka, Andreas Jaeger, and Mark
                                    c
         Mitchell. System V application binary interface, AMD64 ar-
         chitecture processor supplement. Available at http://www.
         x86-64.org/documentation/abi.pdf, May 2009. Draft
         0.99.




  2
      Thanks to David Koes for this diagram.


L ECTURE N OTES                                                   A UGUST 24, 2009

Contenu connexe

Tendances

Cmp2412 programming principles
Cmp2412 programming principlesCmp2412 programming principles
Cmp2412 programming principlesNIKANOR THOMAS
 
Compiler design tutorial
Compiler design tutorialCompiler design tutorial
Compiler design tutorialVarsha Shukla
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Shipra Swati
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design BasicsAkhil Kaushik
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer ProgrammingProf. Erwin Globio
 
The Programmer Life Cycle
The Programmer Life CycleThe Programmer Life Cycle
The Programmer Life CycleRussell Ovans
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chaptersIbrahim Elewah
 
Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Md Hossen
 
Lecture1 compilers
Lecture1 compilersLecture1 compilers
Lecture1 compilersAftab Ahmad
 
An introduction to_programming_with_c__threads 2005
An introduction to_programming_with_c__threads 2005An introduction to_programming_with_c__threads 2005
An introduction to_programming_with_c__threads 2005mohammad shayestehfar
 
Programming lesson1
Programming lesson1Programming lesson1
Programming lesson1camfollower
 
Principles of programming
Principles of programmingPrinciples of programming
Principles of programmingRob Paok
 

Tendances (20)

Cmp2412 programming principles
Cmp2412 programming principlesCmp2412 programming principles
Cmp2412 programming principles
 
Compilers
CompilersCompilers
Compilers
 
Compiler design tutorial
Compiler design tutorialCompiler design tutorial
Compiler design tutorial
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Introduction to Computer Programming
Introduction to Computer ProgrammingIntroduction to Computer Programming
Introduction to Computer Programming
 
The Programmer Life Cycle
The Programmer Life CycleThe Programmer Life Cycle
The Programmer Life Cycle
 
WEBSITE DEVELOPMENT
WEBSITE DEVELOPMENTWEBSITE DEVELOPMENT
WEBSITE DEVELOPMENT
 
Computer programming all chapters
Computer programming all chaptersComputer programming all chapters
Computer programming all chapters
 
Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.Compiler vs Interpreter-Compiler design ppt.
Compiler vs Interpreter-Compiler design ppt.
 
Lecture1 compilers
Lecture1 compilersLecture1 compilers
Lecture1 compilers
 
An introduction to_programming_with_c__threads 2005
An introduction to_programming_with_c__threads 2005An introduction to_programming_with_c__threads 2005
An introduction to_programming_with_c__threads 2005
 
Introduction to c language
Introduction to c language Introduction to c language
Introduction to c language
 
How a Compiler Works ?
How a Compiler Works ?How a Compiler Works ?
How a Compiler Works ?
 
Language processor
Language processorLanguage processor
Language processor
 
Programming lesson1
Programming lesson1Programming lesson1
Programming lesson1
 
Abc c program
Abc c programAbc c program
Abc c program
 
VMPaper
VMPaperVMPaper
VMPaper
 
Principles of programming
Principles of programmingPrinciples of programming
Principles of programming
 

En vedette

What's Next in Growth? 2016
What's Next in Growth? 2016What's Next in Growth? 2016
What's Next in Growth? 2016Andrew Chen
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)maditabalnco
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsBarry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome EconomyHelge Tennø
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your BusinessBarry Feldman
 

En vedette (7)

01 overview
01 overview01 overview
01 overview
 
Compiler Questions
Compiler QuestionsCompiler Questions
Compiler Questions
 
What's Next in Growth? 2016
What's Next in Growth? 2016What's Next in Growth? 2016
What's Next in Growth? 2016
 
Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)Reuters: Pictures of the Year 2016 (Part 2)
Reuters: Pictures of the Year 2016 (Part 2)
 
The Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post FormatsThe Six Highest Performing B2B Blog Post Formats
The Six Highest Performing B2B Blog Post Formats
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
 
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business32 Ways a Digital Marketing Consultant Can Help Grow Your Business
32 Ways a Digital Marketing Consultant Can Help Grow Your Business
 

Similaire à 01 overview

Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxdawod yimer
 
Ch 1.pptx
Ch 1.pptxCh 1.pptx
Ch 1.pptxwoldu2
 
SSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfSSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfJacobDragonette
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptxAshenafiGirma5
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introductionmengistu23
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxZiyadMohammed17
 
Compiler Design Using Context-Free Grammar
Compiler Design Using Context-Free GrammarCompiler Design Using Context-Free Grammar
Compiler Design Using Context-Free GrammarIRJET Journal
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3aminmesbahi
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfSubramanyambharathis
 
Unit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptxUnit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptxAsst.prof M.Gokilavani
 

Similaire à 01 overview (20)

Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptx
 
Ch 1.pptx
Ch 1.pptxCh 1.pptx
Ch 1.pptx
 
SS UI Lecture 1
SS UI Lecture 1SS UI Lecture 1
SS UI Lecture 1
 
Ss ui lecture 1
Ss ui lecture 1Ss ui lecture 1
Ss ui lecture 1
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
 
First session quiz
First session quizFirst session quiz
First session quiz
 
First session quiz
First session quizFirst session quiz
First session quiz
 
SSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfSSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdf
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
 
CD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
 
Compiler Design Using Context-Free Grammar
Compiler Design Using Context-Free GrammarCompiler Design Using Context-Free Grammar
Compiler Design Using Context-Free Grammar
 
.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3.NET Core, ASP.NET Core Course, Session 3
.NET Core, ASP.NET Core Course, Session 3
 
Assembly
AssemblyAssembly
Assembly
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
 
Unit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptxUnit 1_Evaluation Criteria_session 3.pptx
Unit 1_Evaluation Criteria_session 3.pptx
 
Lect-01.ppt
Lect-01.pptLect-01.ppt
Lect-01.ppt
 
Cd unit i
Cd unit iCd unit i
Cd unit i
 

Dernier

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 

Dernier (20)

Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 

01 overview

  • 1. Lecture Notes on Compiler Design: Overview 15-411: Compiler Design Frank Pfenning Lecture 1 August 24, 2009 1 Introduction This course is a thorough introduction to compiler design, focusing on more low-level and systems aspects rather than high-level questions such as polymorphic type inference or separate compilation. You will be build- ing several complete end-to-end compilers for successively more complex languages, culminating in a mildly optimizing compiler for a safe variant of the C programming language to x86-64 assembly language. For the last project you will have the opportunity to optimize more aggressively, to im- plement a garbage collector, or retarget the compiler to an abstract machine. In this overview we review the goals for this class and give a general description of the structure of a compiler. Additional material can be found in the optional textbook [App98, Chapter 1]. 2 Goals After this course you should know how a compiler works in some depth. In particular, you should understand the structure of a compiler, and how the source and target languages influence various choices in its design. It will give you a new appreciation for programming language features and the implementation challenges they pose, as well as for the actual hardware ar- chitecture and the runtime system in which your generated code executes. Understanding the details of typical compilation models will also make you a more discerning programmer. L ECTURE N OTES A UGUST 24, 2009
  • 2. L1.2 Compiler Design: Overview You will also understand some specific components of compiler tech- nology, such as lexical analysis, grammars and parsing, type-checking, in- termediate representations, static analysis, common optimizations, instruc- tion selection, register allocation, code generation, and runtime organiza- tion. The knowledge gained should be broad enough that if you are con- fronted with the task of contributing to the implementation of a real com- piler in the field, you should be able to do so confidently and quickly. For many of you, this will be the first time you have to write, main- tain, and evolve a complex piece of software. You will have to program for correctness, while keeping an eye on efficiency, both for the compiler itself and for the code it generates. Because you will have to rewrite the compiler from lab to lab, and also because you will be collaborating with a partner, you will have to pay close attention to issues of modularity and in- terfaces. Developing these software engineering and system building skills are an important goal of this class, although we will rarely talk about them explicitly. 3 Compiler Requirements As we will be implementing several compilers, it is important to under- stand which requirement compilers should satisfy. We discuss in each case to what extent it is relevant to this course. Correctness. Correctness is absolutely paramount. A buggy compiler is next to useless in practice. Since we cannot formally prove the correctness of your compilers, we use extensive testing. This testing is end-to-end, ver- ifying the correctness of the generated code on sample inputs. We also ver- ify that your compiler rejects programs as expected when the input is not well-formed (lexically, syntactically, or with respect to the static semantics), and that the generated code raises an exception as expected if the language specification prescribes this. We go so far as to test that your generated code fails to terminate (with a time-out) when the source program should diverge. Emphasis on correctness means that we very carefully define the se- mantics of the source language. The semantics of the target language is given by the GNU assembler on the lab machines together with the seman- tics of the actualy machine. Unlike C, we try to make sure that as little as possible about the source language remains undefined. This is not just for testability, but also good language design practice since an unambigu- L ECTURE N OTES A UGUST 24, 2009
  • 3. Compiler Design: Overview L1.3 ously defined language is portable. The only part we do not fully define are precise resource constraints regarding the generated code (for example, the amount of memory available). Efficiency. In a production compiler, efficiency of the generated code and also efficiency of the compiler itself are important considerations. In this course, we set very lax targets for both, emphasizing correctness instead. In one of the later labs in the course, you will have the opportunity to optimize the generated code. The early emphasis on correctness has consequences for your approach to the design of the implementation. Modularity and simplicity of the code are important for two reasons: first, your code is much more likely to be correct, and, second, you will be able to respond to changes in the source language specification from lab to lab much more easily. Interoperability. Programs do not run in isolation, but are linked with library code before they are executed, or will be called as a library from other code. This puts some additional requirements on the compiler, which must respect certain interface specifications. Your generated code will be required to execute correctly in the environ- ment on the lab machines. This means that you will have to respect calling conventions early on (for example, properly save callee-save registers) and data layout conventions later, when your code will be calling library func- tions. You will have to carefully study the ABI specification [MHJM09] as it applies to C and our target architecture. Usability. A compiler interacts with the programmer primarily when there are errors in the program. As such, it should give helpful error messages. Also, compilers may be instructed to generate debug information together with executable code in order help users debug runtime errors in their pro- gram. In this course, we will not formally evaluate the quality or detail of your error messages, although you should strive to achieve at least a minimum standard so that you can use your own compiler effectively. Retargetability. At the outset, we think of a compiler of going from one source language to one target language. In practice, compilers may be re- quired to generate more than one target from a given source (for example, L ECTURE N OTES A UGUST 24, 2009
  • 4. L1.4 Compiler Design: Overview x86-64 and ARM code), sometimes at very different levels of abstraction (for example, x86-64 assembly or LLVM intermediate code). In this course we will deemphasize retargetability, although if you struc- ture your compiler following the general outline presented in the next sec- tion, it should not be too difficult to retrofit another code generator. One of the options for the last lab in this course is to retarget your compiler to pro- duce code in a low-level virtual machine (LLVM). Using LLVM tools this means you will be able to produce efficient binaries for a variety of concrete machine architectures. 4 The Structure of a Compiler Certain general common structures have arisen over decades of develop- ment of compilers. Many of these are based on experience and sound en- gineering principles rather than any formal theory, although some parts, such as parsers, are very well understood from the theoretical side. The overall structure of a typical compiler is shown in Figure 1. In this course, we will begin by giving you the front and middle ends of a simple compiler for a very small language, and you have to write the back end, that is, perform instruction selection and register allocation. Con- sequently, Lectures 2 and 3 will be concerned with instruction selection and register allocation, respectively, so that you can write your own. We then turn to the front end and follow through the phases of a com- piler in order to complete the picture, while incrementally complicating the language features you have to compile. Roughly, we will proceed as follows, subject to adjustment throughout the course: 1. A simple expression language 2. Loops and conditionals 3. Functions 4. Structs and arrays 5. Memory safety and basic optimizations The last lab is somewhat open-ended and allows either to implement fur- ther optimizations, a garbage collector, or a new back end which uses the low-level virtual machine (LLVM)1 . 1 See http://llvm.org L ECTURE N OTES A UGUST 24, 2009
  • 5. Compiler Design: Overview L1.5 Figure 1: Structure of a typical compiler2 References [App98] Andrew W. Appel. Modern Compiler Implementation in ML. Cambridge University Press, Cambridge, England, 1998. [MHJM09] Michael Matz, Jan Hubi˘ ka, Andreas Jaeger, and Mark c Mitchell. System V application binary interface, AMD64 ar- chitecture processor supplement. Available at http://www. x86-64.org/documentation/abi.pdf, May 2009. Draft 0.99. 2 Thanks to David Koes for this diagram. L ECTURE N OTES A UGUST 24, 2009