finds.dev← search

// the find

rui314/9cc

★ 1,950 · C · MIT · updated Nov 2020

A Small C Compiler

A small, hand-written C compiler targeting x86-64, written by rui314 as a teaching exercise in compiler construction. It's for developers who want to understand how a real compiler pipeline (parse -> semantic analysis -> IR -> register allocation -> codegen) works end to end, not for anyone who needs to actually compile C code today.

The staged architecture is unusually easy to follow for a compiler codebase — each phase (parse.c, sema.c, gen_ir.c, regalloc.c, gen_x86.c) is its own file with a clear single job, which makes it a good reference for learning how register allocation and IR lowering actually work in practice. The README explains the reasoning behind every unconventional choice (no free(), reading whole files into memory, hand-rolled recursive descent instead of lex/yacc) instead of just listing features, so you understand the tradeoffs rather than guessing at them. The IR has infinite virtual registers mapped down to real ones, which is the same technique production compilers use, just stripped down to something you can read in one sitting.

It's dead: last push was 2020 and the README itself tells you to go use chibicc instead, so cloning this over its successor is actively the wrong move for anyone except someone following the author's older blog series. Language coverage is intentionally incomplete — the author states outright it can't compile real-world C yet, so don't expect switch statements, structs, or much of the standard library to work reliably. x86-64-only codegen with no other backend, and the test suite (test.c plus two .inc files) is nowhere near enough to trust this with anything beyond toy programs.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →