How rui314/chibicc works
chibicc is a small C11 compiler. A developer supplies C source to the driver, which reads and tokenizes it, expands preprocessing directives and headers, parses declarations and expressions into typed ASTs, emits x86-64 assembly, and invokes the system linker for an executable. The sampled code also shows UTF-8 handling, C11 type features, ABI-aware code generation, atomics, variadic arguments, TLS, VLAs, and related extensions. Some driver orchestration is documented rather than present in the excerpts.
Main entry points: main.c Compiler Driver · parse.c C Parser · codegen.c Code Generator · tokenize.c Tokenizer
Components 16
Compiler Driver
- Compiler Driver
main.c
Frontend
- Tokenizer
tokenize.c - UTF-8 Support
unicode.c - Preprocessor
preprocess.c - C11 Headers
include - C Parser
parse.c
Language Model
- Type System
type.c - Typed AST
parse.c - C11 Features
parse.c
Backend
- Code Generator
codegen.c - x86-64 ABI
codegen.c
Other components
- C Developer
- C Source
- Assembly Output
- System Linker
- Executable
Connections 19
- C Developer → C Source: writes
- C Source → Compiler Driver: supplies
- Compiler Driver → Tokenizer: dispatches
- Tokenizer → UTF-8 Support: decodes UTF-8
- Tokenizer → Preprocessor: emits tokens
- C11 Headers → Preprocessor: provides macros
- Preprocessor → C Parser: expands tokens
- Compiler Driver → C Parser: invokes parser
- C Parser → Type System: adds types
- C Parser → Typed AST: constructs AST
- Type System → Typed AST: annotates AST
- C Parser → C11 Features: handles features
- Compiler Driver → Code Generator: invokes codegen
- Typed AST → Code Generator: provides AST
- Code Generator → x86-64 ABI: applies ABI
- Code Generator → Assembly Output: emits assembly
- Compiler Driver → System Linker: runs linker
- Assembly Output → System Linker: links input
- System Linker → Executable: produces executable