Welcome to MCC
MCC (Michael’s C Compiler) is a self-hosting C compiler written in Rust that transforms C source code into executable machine code through a complete compilation pipeline. Built with modern tooling and designed for correctness, MCC demonstrates how to build a production-quality compiler with incremental compilation, error recovery, and comprehensive test coverage.Complete Pipeline
Seven distinct stages from preprocessing through assembly, with clear separation of concerns and well-defined intermediate representations
Incremental Compilation
Powered by Salsa for fast development cycles—only recomputes what changed in your source files
Comprehensive Testing
Built on the writing-a-c-compiler-tests suite with 20 chapters of progressive language features
Modern Rust Codebase
Clean architecture with tree-sitter parsing, strong typing, and zero-cost abstractions
Architecture Overview
MCC follows a classic compiler pipeline where each stage consumes the output of the previous stage:Preprocessing
Runs the system C preprocessor (
cc -E -P) to handle includes, macros, and conditional compilationRendering
Converts assembly IR to textual assembly with OS-specific conventions (macOS symbol prefixes, Linux stack notes)
Key Features
Incremental Compilation with Salsa
Every compilation stage is implemented as a Salsa tracked function, enabling:- Cached results - Reuse previously computed ASTs, IR, and assembly when source files haven’t changed
- Fine-grained invalidation - Only recompute what’s affected by your edits
- Fast iteration - Dramatically reduced compile times during development
Error Recovery and Diagnostics
MCC uses codespan-reporting to provide helpful diagnostics:- Non-fatal errors - Compilation continues to collect all errors in a single pass
- Precise source locations - Errors point to exact lines and columns in your code
- Accumulated diagnostics - Each stage can emit multiple warnings and errors
Multi-Target Support
Built ontarget-lexicon for cross-platform compilation:
- x86_64 primary target - Generates optimized x64 assembly
- OS-specific conventions - Handles macOS vs Linux symbol naming and stack notes
- Extensible architecture - Designed to support additional targets
Modular Crate Structure
The project is organized into focused crates:The modular design ensures that syntax changes don’t require recompiling the entire compiler, and the driver contains no compilation logic—only orchestration.
Architectural Invariants
MCC maintains strict boundaries to ensure maintainability:- Linear dependencies - No compilation stage depends on later stages
- Pure syntax layer -
mcc-syntaxcontains no compilation logic - Salsa tracking - All stages are pure functions with incremental computation
- Non-fatal errors - Diagnostics accumulate rather than panicking
- External tools - Delegates preprocessing, assembly, and linking to the system compiler
What You’ll Learn
By exploring MCC’s source code and documentation, you’ll understand:- How to structure a multi-stage compiler with clear module boundaries
- Implementing incremental compilation with Salsa
- Using tree-sitter for robust parsing with error recovery
- Designing intermediate representations (HIR, TAC, Assembly IR)
- Generating x86_64 assembly from high-level constructs
- Building comprehensive test infrastructure for a compiler
- Integrating with system tooling (preprocessor, assembler, linker)
Next Steps
Installation
Install Rust and build MCC from source
Quick Start
Compile your first C program with MCC