A modular compiler pipeline written in Rust. (LLVM/Clang inspired)
DecentClang is a multi-crate Rust workspace implementing a full compilation pipeline:
Oat → Lexer → Parser → Typechecker → LLVMlite IR → x86 IR → Assembler → Executable
The focus of the project is:
- Phase isolation
- Deterministic artifact generation
- Clean intermediate representations
- Compiler-grade CLI ergonomics
- Toolchain architecture clarity
Originally implemented in OCaml (NUS CS4212), rewritten from scratch in Rust with stronger modularity and system-level design.
- Handwritten lexer
- Recursive descent parser
- Type inference and return-path validation
- AST → LLVMlite lowering
- LLVMlite → x86 IR code generation
- Assembly emission
- Executable linking (scaffold)
--timestage timing breakdown-vverbose diagnostics--emit-ir--emit-asm--out-dir <dir>--color auto|always|never- Structured error formatting with spans
Example error:
error: mismatched types
--> examples/broken.oat:12:15
|
12 | return x + true;
| ^^^^^ expected `int`, found `bool`
note: try converting `true` to an integer
Diagnostics are deterministic and exit codes follow compiler conventions.
Build all crates:
cargo build --workspaceBuild optimized driver:
cargo build -p driver --releaseRun:
./target/release/dclang examples/fact.oatdclang examples/fact.oat
dclang --time examples/fact.oat
dclang -v --emit-ir --emit-asm --out-dir target/dclang examples/fact.oatDecentClang/
├── lexer/ # Tokenization
├── parser/ # AST construction
├── typechecker/ # Static analysis & inference
├── frontend/ # AST → LLVMlite IR
├── llvm/ # LLVMlite IR definitions
├── backend/ # LLVMlite → x86 IR lowering
├── x86/ # x86 IR modeling
├── assembler/ # Assembly emission & layout
└── driver/ # CLI entrypoint
Each crate compiles independently and exposes a narrow API surface.
DecentClang emphasizes:
- Clear ownership boundaries between compilation phases
- No hidden global state
- Explicit IR modeling
- Toolchain-like CLI behavior
- Deterministic outputs suitable for automation
The project treats the compiler as developer tooling, not as a UI application.
Run tests:
cargo test --workspaceFormat:
cargo fmtLint:
cargo clippy --workspace -- -D warningsCore pipeline operational. Frontend lowering and full linking evolving. CLI stable and feature-complete for development use.
MIT
