Skip to content

chibicc

A small C compiler written for readability, able to build Git, SQLite and libpng.

Stars
12k
Forks
1.1k
Licence
MIT
Language
C
Last update
3.0 years ago
Type
Library

No commits in over a year — check for forks or alternatives before adopting.

What it is

chibicc is a small C compiler that implements most of the C11 standard. The README says it can compile real programs such as Git, SQLite, libpng and chibicc itself without modifying them, and that their test suites pass. It is also the reference implementation for the author's book on compilers, with each commit corresponding to a book section so readers can study one feature at a time.

  • Read individual commits to see how a C feature such as the conditional operator is implemented
  • Compile small C programs with a compiler whose source is easy to follow
  • Study the four stages described in the README: tokenize, preprocess, parse and codegen
  • Compare its design with other small compilers like tcc, as the README does

Great for

  • Developers who want to learn how a C compiler works internally
  • Students following a compiler-construction course or the author's book
  • Readers who want to see how a specific C feature, such as while loops or thread-local variables, is implemented in a few commits
  • People who value readable compiler source over speed

Not ideal for

  • Anyone who needs fast or optimized output: the README says there is no optimization pass and output is probably twice or more slower than GCC's
  • Users who need portability beyond x86-64 Linux: the author says it may or may not work on other systems and portability is not the goal
  • Contributors hoping to submit pull requests: the author rewrites history to fix bugs and does not take PRs directly
Step-by-step guide: how to use chibiccInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Clone and build from source

    You'll need: A C compiler and make (not specified in the README excerpt) · Linux on x86-64 is the author's tested platform

    Clone the repository

    git clone https://github.com/rui314/chibicc
  2. 2

    Run it

    • Clone the repository with git.
    • Follow the build instructions in the project README (not included in the excerpt provided).
    • Compile a small C file with the built chibicc binary.
    • Read the commit history alongside the book sections to learn each feature.
  3. 3

    Get the most out of it

    • Read the commits linked in the README (while, ?:, thread-local variables) to see single features implemented in isolation
    • Start from the first commit to follow the compiler's incremental build-up
    • Read the design principles section to understand the deliberate duplication and memory policy
    • Try compiling a larger C project to test feature coverage, as the author did with SQLite and Git

Downloads

Strengths

  • Readable source code, with commits organized as incremental lessons
  • Supports a wide range of C11 features and several GCC extensions, per the README
  • Compiles real-world projects such as Git and SQLite, with their test suites passing

Trade-offs

  • No optimization pass, so generated code is slow
  • Git history is rewritten to fix bugs and the author may force-push, which complicates forks
  • Last push in the metadata is October 2023 and there is no release, so activity is unclear

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.