How obijunior/vbrcc works
VBRCC is a single-file C compiler that emits x86-64 Windows executables. Its principal workflow preprocesses and lexes source, parses an AST, type-checks it, generates Intel-syntax assembly, then assembles and writes PE output; optional modes use external linkers. The graph also preserves compile-time folding, diagnostics, bundled headers, and the COFF path. Edges follow the README or source-index references and excerpts; unsampled backend details are not expanded beyond documented behavior.
Main entry points: main.rs Compiler CLI · mod.rs Preprocessor · assembler_driver.rs Assembler driver · parser.rs Parser
Components 26
C front end
- Preprocessor
src/preprocessor/mod.rs - Include resolver
src/preprocessor/include.rs - Macro expansion
src/preprocessor/macros.rs - Conditional expressions
src/preprocessor/cond_expr.rs - Lexer
src/lexer.rs - Parser
src/parser.rs
Semantic analysis
- AST and types
src/ast.rs - Type checker
src/typeck.rs - Constant evaluation
src/constfold.rs - Diagnostics
src/diagnostic.rs
Code generation
- Assembly generation
src/codegen.rs
Assembly and output
- Assembler driver
src/assembler_driver.rs - Assembly parser
src/assembler/instruction.rs - Instruction encoder
src/assembler/encoder.rs - Register model
src/assembler/register.rs - Relocations
src/assembler/relocation.rs - PE executable writer
src/assembler/pe.rs - COFF object writer
src/assembler/coff.rs - Windows executable
- COFF object
Headers and integrations
- Bundled C headers
src/headers - Windows C runtime
- lld-link toolchain
- GCC toolchain
Other components
- C source author
- Compiler CLI
src/main.rs
Connections 29
- C source author → Compiler CLI: provides source
README.md - Compiler CLI → Preprocessor: compiles input
- Preprocessor → Include resolver: resolves includes
src/preprocessor/mod.rs - Preprocessor → Macro expansion: expands macros
src/preprocessor/mod.rs - Preprocessor → Conditional expressions: evaluates directives
src/preprocessor/mod.rs - Preprocessor → Lexer: tokenizes lines
src/preprocessor/mod.rs - Preprocessor → Parser: emits tokens
src/preprocessor/mod.rs - Parser → AST and types: builds AST
src/parser.rs - Parser → Constant evaluation: folds constants
src/parser.rs - Type checker → AST and types: annotates expressions
src/typeck.rs - Type checker → Constant evaluation: evaluates constants
src/typeck.rs - Assembly generation → Type checker: consumes typed AST
src/codegen.rs - Assembly generation → AST and types: walks AST
src/codegen.rs - Compiler CLI → Diagnostics: renders errors
- Compiler CLI → Assembly generation: requests assembly
- Compiler CLI → Assembler driver: assembles output
- Assembler driver → Assembly parser: parses assembly
- Assembly parser → Instruction encoder: encodes instructions
src/assembler/mod.rs - Instruction encoder → Register model: uses registers
src/assembler/encoder.rs - Instruction encoder → Relocations: records relocations
src/assembler/encoder.rs - Assembler driver → PE executable writer: writes PE output
- Assembler driver → COFF object writer: writes COFF output
- PE executable writer → Windows executable: produces executable
README.md - COFF object writer → COFF object: produces object
src/assembler/coff.rs - Compiler CLI → Bundled C headers: preprocesses headers
README.md - Windows executable → Windows C runtime: imports runtime
README.md - Compiler CLI → lld-link toolchain: invokes optional linker
README.md - COFF object → lld-link toolchain: linked by
README.md - Compiler CLI → GCC toolchain: invokes optional backend
README.md