antcc
A little C compiler using its own independent backend, being developed with these main goals:
- The C frontend aims to provide a practical implementation of ISO C (plus common extensions) that make it able to compile a lot of real-world C code.
- The backend seeks to offer a significant proportion of the impactful performance optimizations from industry-standard compilers in a much smaller and hackable footprint.
- And importantly, fun! I like learning about and experimenting with compiler implementation :)
- Supports most of C11 and some C23 features, as well as some common GNU extensions.
- It can build C codebases such as Lua, SQLite, git, curl, Tcl, DOOM, Vim...
- Compilation speed is very fast, and generated code efficiency is within 60~75% of
gcc -O1. - Custom, simple SSA-based
IR in the backend.
Example IR
function fibr : unsigned int(unsigned int) abi: (RDI) -> RAX @0: i32 %0 = param 0, i32 b @1 @1: ; preds: @0 i32 %4 = ulth i32 %0, 2 b %4, @2, @3 @2: ; preds: @1 ret %0 @3: ; preds: @1 i32 %7 = sub %0, 1 arg i32, %7 i32 %9 = call $fibr, #1 i32 %11 = sub %0, 2 arg i32, %11 i32 %13 = call $fibr, #1 i32 %14 = add %9, %13 ret %14 - Optimizations such as stack slot → register promotion, copy elimination, inlining, global code motion, common subexpression elimination, loop inversion.
- Instruction selection which utilizes x86 memory operands.
- Linear scan register allocation.
- Direct-to-object code emission, no external assembler required.
- Can generate position-independent code.
- Can currently target x86-64 and aarch64; linux and bsds.
Get the code: main git repository
You can read about the internals in the documentation.
Community
Come chat at #antcc on irc.libera.chat.
Contribution info
Credits
antcc is inspired by the QBE backend, and other small C compilers, mainly TinyCC, chibicc, cproc.Thanks to Urs Jansen from the TIN newsreader for providing early testing and bug reports.
More Links
- Development blog posts
- mirrors: GitHub, my cgit
- "Resources for Amateur Compiler Writers" via c9x.me
- "Programming language resources" via bernsteinbear.com