Overview
Compilers are a fundamental piece of software infrastructure. They enable programmers to write programs in high-level programming languages and obtain efficient, executable code that can run on a variety of hardware platforms. This course covers the design and implementation of compilers. We will see how to structure compilers as a series of discrete, well-defined transformations between different representations of programs. Throughout the course of the semester, students will implement a complete compiler for a small yet powerful typed, functional programming language.
Schedule
(Note: tentative—subject to change)
| Week | Date | Lecture | Notes | Homework | |
|---|---|---|---|---|---|
| 1 | Mon | Jan 26 | overview, OCaml tutorial | ||
| Wed | Jan 28 | ps0 released | |||
| 2 | Mon | Feb 2 | assembly, RISC-V, interpreters | ||
| Wed | Feb 4 |
ps0 due
ps1 released |
|||
| 3 | Mon | Feb 9 | lexing, parsing | ||
| Wed | Feb 11 |
ps1 due
ps2 released |
|||
| 4 | Mon | Feb 16 | no lecture—Presidents' day (university holiday) | ||
| Tue | Feb 17 |
(Note: lecture Tue instead of Mon—legislative Monday)
codegen, basic optimizations |
|||
| Wed | Feb 18 |
ps2 due
ps3 released |
|||
| 5 | Mon | Feb 23 | procedures, stack frames, abstract machines | ||
| Wed | Feb 25 |
ps3 due
ps4 released |
|||
| 6 | Mon | Mar 2 | heap-allocated data, richer data types, first-class functions, closures | ||
| Wed | Mar 4 |
ps4 due
ps5 released |
|||
| 7 | Mon | Mar 9 | closures (cont.), type checking, type inference | ||
| Wed | Mar 11 |
ps5 due
ps6 released |
|||
| 8 | Mon | Mar 16 | no lecture—spring break | ||
| 9 | Mon | Mar 23 | type inference (cont.), polymorphism, compiler optimizations | ||
| 10 | Mon | Mar 30 | compiler optimizations (cont.), basic blocks, control-flow graphs, SSA, data-flow analysis | ||
| Wed | Apr 1 |
ps6 due
ps7 released miniproject released |
|||
| 11 | Mon | Apr 6 | SSA (cont.), register allocation, graph coloring | ||
| 12 | Mon | Apr 13 | loop optimizations, pointer analysis | ||
| Wed | Apr 15 | ps7 due | |||
| 13 | Mon | Apr 20 | OOP, memory management, garbage collection | ||
| 14 | Mon | Apr 27 | garbage collection (cont.) | ||
| 15 | Mon | May 4 | parallelism | miniproject due | |
Policies
Grading: homework assignments (80%), final project (20%). The overall course grade will be based on the weighted average of these two components.
Late Submissions: Assignments submitted after their deadline are considered late. Students may take up to 3 “no questions asked” late days throughout the semester. Each late day used grants a 24 hour extension. Each late day must be used in its entirety (e.g., you cannot use “half” a late day to get a 12 hour extension). You may use multiple late days on a single assignment. You must notify the instructor that you are using a late day. If a student has no remaining late days, a late assignment will only be accepted under extenuating circumstances, such as a medical emergency. Please let the instructor know if such circumstances arise. Otherwise, the late assignment will receive 0 credit. “No questions asked” late days may not be used for the project deliverables, only for the homework assignments. However, extenuating circumstances (such as a medical emergency) may be used to justify extensions for project deliverables.
Academic Integrity: The instructor, the CS department, and NYU as a whole take academic integrity seriously. Please review the department academic integrity policy. In this course, you may not collaborate on assignments. You are free to talk at a high level with fellow students about lecture material discussed in the course and how that material might be relevant to a given assignment. But you may not exchange or share code with fellow students, nor look at or seek help with such assignments on the internet or other sources.
For example, in this course we will describe various data structures and algorithms used as part of compilation. It would be OK to ask a fellow student for help understanding how such an algorithm works or if there are corner cases/details you did not understand so that you can go about implementing the algorithm yourself. However, the discussion should be restricted to high level “white board” discussion: drawing a figure, explaining a lecture slide, etc. Things that are not appropriate would be sharing a code snippet to implement the data structure, asking a fellow student to diagnose a compiler error or debug your code, etc.
Accommodations: Students who have a disability that requires accommodations must inform the instructor that they require such accommodations as soon as possible. Please submit documentation through the Moses Center for Student Accessibility (CSA). You can learn more about NYU's accessibility accommodations policy on the CSA website.
Assignments
Periodic homework assignments, in which students implement the compiler for the course, are responsible for 80% of the overall grade. Given their varying complexity and difficulty, some assignments affect the overall score in the course more than others. In particular, each assignment will be weighted with an assigned number of points. A student's overall “raw” score for the homework component will be the sum total of all points from the assignments.
The tentative list of assignments is as follows:
- OCaml warm-up (6 pts)
- RISC-V Simulator (6 pts)
- Parsing (6 pts)
- Fortran-ish → RISC-V (6 pts)
- C-ish → RISC-V (8 pts)
- Scheme-ish → C-ish (10 pts)
- ML-ish → Scheme-ish (10 pts)
- Control-flow Graph Analysis (20 pts)
The number, subject, and point values of assignments are subject to change from the above list. The definitive point weighting of each assignment is given on Gradescope.
Project
A larger-scale project, completed individually, is responsible for 20% of the overall grade. Your goal in the project will be to improve and optimize the basic compiler infrastructure we have built during the semester in the main assignments.
Resources
Gradescope. Assignments will be submitted and graded on Gradescope.
Textbook. There is no official or required textbook for the course. There are many books on compilers out there; the book that most closely follows what we are doing is Modern Compiler Implementation in ML by Andrew Appel. (Note: there are several textbooks by Andrew Appel with a similar name that vary in terms of what language the example compiler is implemented in. You want the “in ML” version, as Standard ML is closest to OCaml, the language we are using.)
Learning OCaml. There are a number of free OCaml tutorials and books that can supplement the coverage in class and provide material for those who wish to learn more.
- OCaml Programming: Correct + Efficient + Beautiful by Clarkson et al. This is an online textbook used for a course on OCaml programming at Cornell. It has an integrated sequence of several hundred video lectures that explain the material as well.
- OCaml.org Tutorials. These tutorials cover different aspects of the language and supporting tools (build managers, debuggers, profilers).
- OCaml Language Manual. The official language manual is surprisingly readable, and Part I gives a nice introduction to the language and its various features. Chapter 3 covers OCaml's object system, which we won't make use of in this course, so you can skip that.
- Real World OCaml by Yaron Minsky, Anil Madhavapeddy, and Jason Hickey. A very comprehensive book (with free online version). Be aware that the book uses an alternative standard library called Base, which we won't be using. However, you can still learn a lot about the language and its features by reading the book.
Acknowledgments
This course and its materials are based on course materials developed by Greg Morrisett, Jean-Baptiste Tristan, and Robert Muller, with adaptations by Joe Tassarotti. The instructor is grateful for their permission to use these resources.