This repository is the scaffolding for an end-to-end compiler. It is a useful starting point when developing a new language — taking care of the workflow and wiring typical in most of my personal programming language projects.
To build, check out the repository and execute the following commands:
$ git submodule init
$ git submodule update
$ cmake -H. -Bbuild
$ cmake --build build --target compiler
$ ./build/compiler
We include LLVM as a submodule.
The compiler is split into four primary directories representing the logical parts of the compiler workflow:
parser/
- A parser based on Bison and Flex.checker/
- Placeholder module to check the program for semantic correctness.emitter/
- Backend code generation to LLVM IR.commands/
- A lightweight framework for supporting different compiler commands. Out of the box, the compiler supports the following commands:compiler run
- Execute a program using just-in-time compilationcompiler build
- Generates a binary (optionally cross-compiling for different architectures)compiler check
- Checks a program for semantic correctnesscompiler parse
- Checks a program for syntactic correctnesscompiler ir
- Emits the LLVM IR code for a program
The project builds a compiler for a minimal languge that prints the results of simple integer expressions, e.g.,
1 * 3 + (12 % 5)
(2 << 3) / 2
prints
5
8
This scaffolding is used exclusively for personal projects by Bret Taylor (btaylor@gmail.com).