Essentials of Compilation

An Incremental Approach in Python

by Siek

| ISBN: 9780262375559 | Copyright 2023

Click here to preview

Instructor Requests

Digital Exam/Desk Copy Print Desk Copy Ancillaries
Tabs

A hands-on approach to understanding and building compilers using the programming language Python.

Compilers are notoriously difficult programs to teach and understand. Most books about compilers dedicate one chapter to each progressive stage, a structure that hides how language features motivate design choices. By contrast, this innovative textbook provides an incremental approach that allows students to write every single line of code themselves. Jeremy Siek guides the reader in constructing their own compiler in the powerful object-oriented programming language Python, adding complex language features as the book progresses. Essentials of Compilation explains the essential concepts, algorithms, and data structures that underlie modern compilers and lays the groundwork for future study of advanced topics. Already in wide use by students and professionals alike, this rigorous but accessible book invites readers to learn by doing.

•Deconstructs the challenge of compiler construction into bite-sized pieces
•Enhances learning by connecting language features to compiler design choices
•Develops understanding of how programs are mapped onto computer hardware
•Classroom-tested, hands-on approach suitable for students and professionals
•Extensive ancillary resources include source code and solutions

Expand/Collapse All
Contents (pg. vii)
Preface (pg. xi)
1. Preliminaries (pg. 1)
1.1 Abstract Syntax Trees (pg. 1)
1.2 Grammars (pg. 3)
1.3 Pattern Matching (pg. 5)
1.4 Recursive Functions (pg. 6)
1.5 Interpreters (pg. 8)
1.6 Example Compiler: A Partial Evaluator (pg. 10)
2. Integers and Variables (pg. 13)
2.1 The LVar Language (pg. 13)
2.2 The x86Int Assembly Language (pg. 16)
2.3 Planning the Trip to x86 (pg. 21)
2.4 Remove Complex Operands (pg. 23)
2.5 Select Instructions (pg. 25)
2.6 Assign Homes (pg. 26)
2.7 Patch Instructions (pg. 27)
2.8 Generate Prelude and Conclusion (pg. 27)
2.9 Challenge: Partial Evaluator for LVar (pg. 28)
3. Parsing (pg. 29)
3.1 Lexical Analysis and Regular Expressions (pg. 29)
3.2 Grammars and Parse Trees (pg. 31)
3.3 Ambiguous Grammars (pg. 33)
3.4 From Parse Trees to Abstract Syntax Trees (pg. 34)
3.5 Earley's Algorithm (pg. 36)
3.6 The LALR(1) Algorithm (pg. 40)
3.7 Further Reading (pg. 43)
4. Register Allocation (pg. 45)
4.1 Registers and Calling Conventions (pg. 46)
4.2 Liveness Analysis (pg. 49)
4.3 Build the Interference Graph (pg. 51)
4.4 Graph Coloring via Sudoku (pg. 52)
4.5 Patch Instructions (pg. 58)
4.6 Generate Prelude and Conclusion (pg. 58)
4.7 Challenge: Move Biasing (pg. 59)
4.8 Further Reading (pg. 62)
5. Booleans and Conditionals (pg. 65)
5.1 The LIf Language (pg. 66)
5.2 Type Checking LIf Programs (pg. 66)
5.3 The CIf Intermediate Language (pg. 72)
5.4 The x86If Language (pg. 72)
5.5 Shrink the LIf Language (pg. 75)
5.6 Remove Complex Operands (pg. 75)
5.7 Explicate Control (pg. 76)
5.8 Select Instructions (pg. 82)
5.9 Register Allocation (pg. 83)
5.10 Patch Instructions (pg. 84)
5.11 Generate Prelude and Conclusion (pg. 84)
5.12 Challenge: Optimize Blocks and Remove Jumps (pg. 85)
5.13 Further Reading (pg. 88)
6. Loops and Dataflow Analysis (pg. 91)
6.1 The LWhile Language (pg. 91)
6.2 Cyclic Control Flow and Dataflow Analysis (pg. 91)
6.3 Remove Complex Operands (pg. 96)
6.4 Explicate Control (pg. 96)
6.5 Register Allocation (pg. 96)
7. Tuples and Garbage Collection (pg. 99)
7.1 The LTup Language (pg. 99)
7.2 Garbage Collection (pg. 102)
7.3 Expose Allocation (pg. 109)
7.4 Remove Complex Operands (pg. 110)
7.5 Explicate Control and the CTup Language (pg. 110)
7.6 Select Instructions and the x86Global Language (pg. 111)
7.7 Register Allocation (pg. 116)
7.8 Generate Prelude and Conclusion (pg. 116)
7.9 Challenge: Arrays (pg. 118)
7.10 Further Reading (pg. 123)
8. Functions (pg. 125)
8.1 The LFun Language (pg. 125)
8.2 Functions in x86 (pg. 130)
8.3 Shrink LFun (pg. 133)
8.4 Reveal Functions and the LFunRef Language (pg. 133)
8.5 Limit Functions (pg. 133)
8.6 Remove Complex Operands (pg. 134)
8.7 Explicate Control and the CFun Language (pg. 135)
8.8 Select Instructions and the x86Defcallq* Language (pg. 136)
8.9 Register Allocation (pg. 138)
8.10 Patch Instructions (pg. 139)
8.11 Generate Prelude and Conclusion (pg. 139)
8.12 An Example Translation (pg. 141)
9. Lexically Scoped Functions (pg. 143)
9.1 The L Language (pg. 145)
9.2 Assignment and Lexically Scoped Functions (pg. 150)
9.3 Uniquify Variables (pg. 151)
9.4 Assignment Conversion (pg. 151)
9.5 Closure Conversion (pg. 153)
9.6 Expose Allocation (pg. 156)
9.7 Explicate Control and CClos (pg. 156)
9.8 Select Instructions (pg. 157)
9.9 Challenge: Optimize Closures (pg. 158)
9.10 Further Reading (pg. 160)
10. Dynamic Typing (pg. 161)
10.1 The LDyn Language (pg. 161)
10.2 Representation of Tagged Values (pg. 165)
10.3 The LAny Language (pg. 166)
10.4 Cast Insertion: Compiling LDyn to LAny (pg. 170)
10.5 Reveal Casts (pg. 170)
10.6 Assignment Conversion (pg. 171)
10.7 Closure Conversion (pg. 171)
10.8 Remove Complex Operands (pg. 172)
10.9 Explicate Control and CAny (pg. 172)
10.10 Select Instructions (pg. 172)
10.11 Register Allocation for LAny (pg. 174)
11. Gradual Typing (pg. 177)
11.1 Type Checking L? (pg. 177)
11.2 Interpreting LCast (pg. 183)
11.3 Overload Resolution (pg. 184)
11.4 Cast Insertion (pg. 185)
11.5 Lower Casts (pg. 187)
11.6 Differentiate Proxies (pg. 188)
11.7 Reveal Casts (pg. 190)
11.8 Closure Conversion (pg. 191)
11.9 Select Instructions (pg. 191)
11.10 Further Reading (pg. 193)
12. Generics (pg. 195)
12.1 Compiling Generics (pg. 201)
12.2 Resolve Instantiation (pg. 202)
12.3 Erase Generic Types (pg. 202)
A. Appendix (pg. 207)
A.1 x86 Instruction Set Quick Reference (pg. 207)
References (pg. 208)
Index (pg. 217)

Jeremy G. Siek

Jeremy G. Siek is professor of computer science at Indiana University and author of The Boost Graph Library. He invented gradual typing, a type system that integrates both dynamic and static typing in the same programming language.

Instructors Only
You must have an instructor account and submit a request to access instructor materials for this book.
eTextbook
Go paperless today! Available online anytime, nothing to download or install.

Features

  • Bookmarking
  • Note taking
  • Highlighting