This document covers the tools you need to build and run your compiler for this course: the LLVM/Clang toolchain, the provided runtime library, and how they fit into the test workflow.
| Tool | Minimum version | Needed for |
|---|---|---|
| LLVM / Clang | 19+ | Compiling generated LLVM IR to executables, linking with runtime |
| Python | 3.9+ | Test harness (test/run_tests.py) |
| (optional) CMake | 3.16+ | Building the provided runtime library |
GCC works as an alternative to Clang for compiling the runtime library, but Clang is required to compile the LLVM IR your compiler emits (GCC cannot read LLVM IR).
sudo apt install llvm-dev clang
# Verify installation
llvm-config --version # Should be 19 or later
clang --versionsudo dnf install llvm-devel clangbrew install llvm
# LLVM tools are keg-only; add them to your PATH:
export PATH="$(brew --prefix llvm)/bin:$PATH"Download the LLVM installer from https://releases.llvm.org/ or use:
choco install llvmThe overall flow is:
- Your compiler reads a
.splsource file and produces LLVM IR text (output.ll). - Clang compiles the IR to a native executable, optionally linking with the runtime library.
- The executable runs and its exit code / stdout are compared by the test harness.
# Step 1: Your compiler produces LLVM IR (output.ll)
./splc -o output.ll source.spl
# Step 2a: Compile IR to executable without the runtime
clang output.ll -o program
# Step 2b: Compile IR and link with the runtime library (grammar 3+)
clang output.ll -L build/libruntime -lsplruntime -o program
# Step 3: Run
./programNote about
lli: You can also run LLVM IR directly withlli, but the test harness expects a compiled executable. Useclangfor production runs.
The test harness needs a way to (a) build your compiler and (b) turn a .spl
file into a runnable executable. This is configured in test/config.json
(see test/README.md for the full format).
The compile stage in the config must produce an executable at {exe}. A
typical approach:
"compile": {
"cmd": ["bash", "-c",
"{root}/build/splc -g {grammar} -o /tmp/out.ll {input} && " +
"clang /tmp/out.ll -L{root}/build/libruntime -lsplruntime -o {exe} -Wno-override-module"]
}Adjust the splc invocation to match your own compiler's CLI, and drop the
runtime library flags for grammars 1–2 if you are not using it.
The runtime library (libruntime/) is a small C library providing print
helpers for grammars 3+. See doc/runtime.md for its API.
cmake -S libruntime -B build/libruntime
cmake --build build/libruntime
# produces build/libruntime/libsplruntime.aIf you don't use CMake, you can compile it directly:
cc -c libruntime/spl_runtime.c -o spl_runtime.o
ar rcs libsplruntime.a spl_runtime.oBefore implementing anything, make sure the toolchain works end to end with a hand-written IR file:
cat > hello.ll <<'EOF'
declare void @println()
define i64 @main() {
entry:
call void @println()
ret i64 0
}
EOF
clang hello.ll -L build/libruntime -lsplruntime -o hello
./helloIf this prints an empty line and exits 0, your toolchain is ready.