A C0 compiler built in C++ with no external dependencies.
C0 is a safe subset of C designed for teaching. It features garbage-collected heap allocation, bounds-checked arrays, and contracts, while retaining C like expression syntax and control flow.
- Recursive descent parser
- SSA-based intermediate representation constructed directly from the AST using the algorithms described in Braun et al., "Simple and Efficient Construction of Static Single Assignment Form" (CC 2013)
- Pruned and minimal SSA form for reducible control flow
- Register allocation via greedy coloring on chordal interference graphs
- Zero external dependencies
- Arena allocator
Clang is strongly recommended. The codebase uses C++23 features that may not be fully supported by other compilers.
# Clone
git clone https://github.com/w4z3d/compiler.git
cd compiler
# Build with CMake and Ninja
mkdir build && cd build
cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Release -G Ninja ..
cmake --build .
./compiler examples/test.c0 <output>- M. Braun, S. Buchwald, S. Hack, R. Leißa, C. Mallon, A. Zwinkau. Simple and Efficient Construction of Static Single Assignment Form. CC 2013.
- S. Hack, D. Grund, G. Goos. Register Allocation for Programs in SSA Form. CC 2006.