SlideShare a Scribd company logo
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

More Related Content

What's hot

Cmp2412 programming principles
Cmp2412 programming principlesCmp2412 programming principles
Cmp2412 programming principles
NIKANOR THOMAS
 
Compilers
CompilersCompilers
Compiler design tutorial
Compiler design tutorialCompiler design tutorial
Compiler design tutorial
Varsha Shukla
 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
Mukesh Tekwani
 
Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7Fundamental of Information Technology - UNIT 7
Fundamental of Information Technology - UNIT 7
Shipra Swati
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
Akhil 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 Cycle
Russell Ovans
 
WEBSITE DEVELOPMENT
WEBSITE DEVELOPMENTWEBSITE DEVELOPMENT
WEBSITE DEVELOPMENT
shahzadebaujiti
 
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 compilers
Aftab 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 2005
mohammad shayestehfar
 
Introduction to c language
Introduction to c language Introduction to c language
Introduction to c language
BAKRANIYA KALPESH
 
Language processor
Language processorLanguage processor
Language processor
Muhammad Mudarrak
 
Programming lesson1
Programming lesson1Programming lesson1
Programming lesson1camfollower
 
Abc c program
Abc c programAbc c program
Abc c program
Dayakar Siddula
 
Principles of programming
Principles of programmingPrinciples of programming
Principles of programming
Rob Paok
 

What's hot (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
 

Viewers also liked

What's Next in Growth? 2016
What's Next in Growth? 2016What's Next in Growth? 2016
What's Next in Growth? 2016
Andrew 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 Formats
Barry Feldman
 
The Outcome Economy
The Outcome EconomyThe Outcome Economy
The Outcome Economy
Helge 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 Business
Barry Feldman
 

Viewers also liked (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
 

Similar to 01 overview

Chapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptxChapter 2 Program language translation.pptx
Chapter 2 Program language translation.pptx
dawod yimer
 
Ch 1.pptx
Ch 1.pptxCh 1.pptx
Ch 1.pptx
woldu2
 
Ss ui lecture 1
Ss ui lecture 1Ss ui lecture 1
Ss ui lecture 1
Avinash Kapse
 
Introduction to Compiler design
Introduction to Compiler design Introduction to Compiler design
Introduction to Compiler design
Dr. C.V. Suresh Babu
 
First session quiz
First session quizFirst session quiz
First session quiz
Keroles karam khalil
 
First session quiz
First session quizFirst session quiz
First session quiz
Keroles karam khalil
 
SSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdfSSD Mod 2 -18CS61_Notes.pdf
SSD Mod 2 -18CS61_Notes.pdf
JacobDragonette
 
4_5802928814682016556.pptx
4_5802928814682016556.pptx4_5802928814682016556.pptx
4_5802928814682016556.pptx
AshenafiGirma5
 
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
ZiyadMohammed17
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
mengistu23
 
Compiler Design Using Context-Free Grammar
Compiler Design Using Context-Free GrammarCompiler Design Using Context-Free Grammar
Compiler Design Using Context-Free Grammar
IRJET 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 3
aminmesbahi
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
Selvaraj Seerangan
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
A. S. M. Shafi
 
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdfINTRODUCTION TO C PROGRAMMING MATERIAL.pdf
INTRODUCTION TO C PROGRAMMING MATERIAL.pdf
Subramanyambharathis
 
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
Asst.prof M.Gokilavani
 
Lect-01.ppt
Lect-01.pptLect-01.ppt
Lect-01.ppt
KamranAli649587
 
Cd unit i
Cd unit iCd unit i
Cd unit i
Abhimanyu Mishra
 

Similar to 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 to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptxCD - CH1 - Introduction to compiler design.pptx
CD - CH1 - Introduction to compiler design.pptx
 
Cd ch1 - introduction
Cd   ch1 - introductionCd   ch1 - introduction
Cd ch1 - introduction
 
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
 

Recently uploaded

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 

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