Boop is a small C-like compiler that tokenizes source code, builds an AST, and emits LLVM IR. The project is intentionally simple right now. The goal seems to be keeping the pipeline easy to read while still using LLVM for the backend.
- Tokenizer, parser, and AST construction
- LLVM IR code generation
- Writes IR to a
.llfile or prints it with-emit-llvm - Supported language pieces:
- integer literals and identifiers
- local declarations with
auto externdeclarations for callable functions- assignment statements
- function calls
return- control flow with
if,else, andwhile - arithmetic, comparison, logical, and shift operators
- builtin
putnumsupport in the LLVM backend
include/public headers for tokens, parser, AST, and codegensrc/compiler implementationtests/small source files used for checking behaviorClover/a separate compiler project in the same repository
Build with the provided Makefile:
makeThis produces the compiler binary in the project root.
Compile a source file and write LLVM IR to a file:
./compiler tests/test_add.bccPrint LLVM IR directly to stdout:
./compiler tests/test_add.bcc -emit-llvmIf you write to a .ll file, you can turn it into an executable with clang:
clang test_add.ll -o test_addmain() {
auto x, y;
x = 10;
y = 20;
if (x < y) {
putnum(x);
}
return(0);
}- All values are currently treated as
i64in the LLVM backend - Top-level globals are parsed, but they are currently lowered as per-function stack slots
- The parser is still small and does not handle a full C-style language
MIT. See LICENCE.