Literature and Resources
We recommend the following course book:
- Keith D. Cooper & Linda Torczon. Engineering a Compiler. Second Edition, Morgan Kaufmann, 2012.
The book is available for free online, using your KTH account. See this link.
Cigrid
Cigrid is a simple subset of C/C++ designed for learning compilers. The Cigrid language is used throughout the whole course as the source language that is compiled into x86 assembler code. You can find the latest Cigrid reference manual here Download Cigrid reference manual here.
X86-64 Reference Sheet
To make it simpler to find information about the x86-64 assembly instruction set architecture, we have created a x86-64 reference sheet Download x86-64 reference sheet suitable for this course. Note that this sheet only shows a subset of all instructions. The complete instruction set can be found here Links to an external site..
Development Languages and Environments
You will do a lot of coding in this course and we strongly suggest that you do your work in a language that promotes a functional style of programming. In the beginning of this course, we will give a crash course in functional programming in OCaml Links to an external site.. If you are not already fluent in any of the other languages, we strongly recommend that you do the exercises in OCaml Links to an external site..
The languages that will be supported in the automatic grading system are: OCaml Links to an external site., Haskell Links to an external site., and Rust Links to an external site.. We will also support the use of Java and C/C++, but we do not recommend that you use these languages in this course, even if it is formally allowed.
C/C++ Resources
The Cigrid language is a subset of C/C++. Hence, it is good to have basic understanding of these languages. However, you do not need to understand the object-oriented aspects of C++. Here are some relevant links:
- The book The C programming Language Links to an external site., second edition by Brian W. Kernighan and Dennis M. Ritchie is the reference book for C. You can buy this book in a book store, but there are also a few copies available at the KTH library.
- The webpage C - Quick Guide Links to an external site. is a good online page that summarizes the basics about C.
- The book The C Book Links to an external site.is an online book that is fairly comprehensive.
- The website cplusplus.com Links to an external site. contains good tutorials and a reference guide to standard libraries Links to an external site..
Unix Commands
This course assumes that you have basic understanding in using a Unix command shell. If you are unfamiliar with Unix, please take a look at this ubuntu command line tutorial Links to an external site., or the website linuxcommand.org Links to an external site.. In general, we recommend that you develop using Linux or MacOS. However, other platforms are possible to use, by executing programs using Vagrant (see below).
Vagrant
We recommend that you use Vagrant Links to an external site. when compiling and running the assignments. Vagrant is a tool that makes it possible to compile and run programs using a Linux environment, while still editing your source code files in your host operating system (e.g. MacOS, Linux, or Windows). To learn about the fundamentals of Vagrant, see this getting started guide Links to an external site..
We have prepared a specific Vagrant setup file for the course. In particular, it is important to use this setup when solving the assignments for Module 2 and 3. Please see the course webpage Vagrant, located in the left menu in Canvas.
Parsing
- Precedence climbing. See this link, Links to an external site. section "Precedence climbing". Note: the link is disallowed by some browsers. Chrome works.
- LR parsing. For the theory, see the course book. There are different variants of LR/LALR parsers in most language environments. See for instance ocamlyacc Links to an external site. and Menhir Links to an external site. for Ocaml, Happy Links to an external site. for Haskell, and LALRPOP Links to an external site. for Rust.
Assembler Resources
The focus on this course is on compiling to x86 assembler. Here are a few useful resources:
- The reference manual to the The Netwide Assembler (NASM) Links to an external site..
- A good NASM tutorial Links to an external site..
- A good post on AMD64 ABI calling conventions Links to an external site..
- The AMD64 ABI document is maintained on Gitlab Links to an external site.. A compiled PDF-version for version 1.0 is available here Links to an external site..
- Direct link to Intel's reference manual for x86-64, including all instructions Links to an external site..
- The Intel® 64 and IA-32 Architectures Software Developer Manuals. Links to an external site.
- Some low-level software optimization resources Links to an external site..
- Intel's intrinsics guide Links to an external site., includes a complete list of SIMD instructions, latencies, and throughput numbers.
- A page with various links Links to an external site. about x86 assembly optimization.