# obijunior/vbrcc architecture

> Architecture diagram of the GitHub repository obijunior/vbrcc, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/obijunior/vbrcc
- Repository: https://github.com/obijunior/vbrcc

## Overview

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: [`src/main.rs`](https://github.com/obijunior/vbrcc/blob/main/src/main.rs) (Compiler CLI), [`src/preprocessor/mod.rs`](https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/mod.rs) (Preprocessor), [`src/assembler_driver.rs`](https://github.com/obijunior/vbrcc/blob/main/src/assembler_driver.rs) (Assembler driver), [`src/parser.rs`](https://github.com/obijunior/vbrcc/blob/main/src/parser.rs) (Parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["C front end"]
  node_preprocess["Preprocessor<br/>[mod.rs]"]
  node_includes["Include resolver<br/>[include.rs]"]
  node_macros["Macro expansion<br/>[macros.rs]"]
  node_condexpr["Conditional expressions<br/>[cond_expr.rs]"]
  node_lexer["Lexer<br/>[lexer.rs]"]
  node_parser["Parser<br/>[parser.rs]"]
end

subgraph group_semantics["Semantic analysis"]
  node_ast["AST and types<br/>[ast.rs]"]
  node_typeck["Type checker<br/>[typeck.rs]"]
  node_constfold["Constant evaluation<br/>[constfold.rs]"]
  node_diagnostics["Diagnostics<br/>[diagnostic.rs]"]
end

subgraph group_backend["Code generation"]
  node_codegen["Assembly generation<br/>[codegen.rs]"]
end

subgraph group_assembly["Assembly and output"]
  node_asm_driver["Assembler driver"]
  node_asm_parse["Assembly parser<br/>[instruction.rs]"]
  node_encoder["Instruction encoder<br/>[encoder.rs]"]
  node_registers["Register model<br/>[register.rs]"]
  node_relocations["Relocations<br/>[relocation.rs]"]
  node_pe["PE executable writer<br/>[pe.rs]"]
  node_coff["COFF object writer<br/>[coff.rs]"]
  node_executable["Windows executable"]
  node_object["COFF object"]
end

subgraph group_runtime["Headers and integrations"]
  node_headers["Bundled C headers"]
  node_msvcrt["Windows C runtime"]
  node_lld["lld-link toolchain"]
  node_gcc["GCC toolchain"]
end

node_developer(("C source author"))
node_cli["Compiler CLI<br/>[main.rs]"]

node_developer -->|"provides source"| node_cli
node_cli -->|"compiles input"| node_preprocess
node_preprocess -->|"resolves includes"| node_includes
node_preprocess -->|"expands macros"| node_macros
node_preprocess -->|"evaluates directives"| node_condexpr
node_preprocess -->|"tokenizes lines"| node_lexer
node_preprocess -->|"emits tokens"| node_parser
node_parser -->|"builds AST"| node_ast
node_parser -->|"folds constants"| node_constfold
node_typeck -->|"annotates expressions"| node_ast
node_typeck -->|"evaluates constants"| node_constfold
node_codegen -->|"consumes typed AST"| node_typeck
node_codegen -->|"walks AST"| node_ast
node_cli -->|"renders errors"| node_diagnostics
node_cli -->|"requests assembly"| node_codegen
node_cli -->|"assembles output"| node_asm_driver
node_asm_driver -->|"parses assembly"| node_asm_parse
node_asm_parse -->|"encodes instructions"| node_encoder
node_encoder -->|"uses registers"| node_registers
node_encoder -->|"records relocations"| node_relocations
node_asm_driver -->|"writes PE output"| node_pe
node_asm_driver -->|"writes COFF output"| node_coff
node_pe -->|"produces executable"| node_executable
node_coff -->|"produces object"| node_object
node_cli -->|"preprocesses headers"| node_headers
node_executable -->|"imports runtime"| node_msvcrt
node_cli -.->|"invokes optional linker"| node_lld
node_object -->|"linked by"| node_lld
node_cli -.->|"invokes optional backend"| node_gcc

click node_cli "https://github.com/obijunior/vbrcc/blob/main/src/main.rs"
click node_preprocess "https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/mod.rs"
click node_includes "https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/include.rs"
click node_macros "https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/macros.rs"
click node_condexpr "https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/cond_expr.rs"
click node_lexer "https://github.com/obijunior/vbrcc/blob/main/src/lexer.rs"
click node_parser "https://github.com/obijunior/vbrcc/blob/main/src/parser.rs"
click node_ast "https://github.com/obijunior/vbrcc/blob/main/src/ast.rs"
click node_typeck "https://github.com/obijunior/vbrcc/blob/main/src/typeck.rs"
click node_constfold "https://github.com/obijunior/vbrcc/blob/main/src/constfold.rs"
click node_diagnostics "https://github.com/obijunior/vbrcc/blob/main/src/diagnostic.rs"
click node_codegen "https://github.com/obijunior/vbrcc/blob/main/src/codegen.rs"
click node_asm_driver "https://github.com/obijunior/vbrcc/blob/main/src/assembler_driver.rs"
click node_asm_parse "https://github.com/obijunior/vbrcc/blob/main/src/assembler/instruction.rs"
click node_encoder "https://github.com/obijunior/vbrcc/blob/main/src/assembler/encoder.rs"
click node_registers "https://github.com/obijunior/vbrcc/blob/main/src/assembler/register.rs"
click node_relocations "https://github.com/obijunior/vbrcc/blob/main/src/assembler/relocation.rs"
click node_pe "https://github.com/obijunior/vbrcc/blob/main/src/assembler/pe.rs"
click node_coff "https://github.com/obijunior/vbrcc/blob/main/src/assembler/coff.rs"
click node_headers "https://github.com/obijunior/vbrcc/tree/main/src/headers"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_preprocess,node_includes,node_macros,node_condexpr,node_lexer,node_parser toneBlue
class node_ast,node_typeck,node_constfold,node_diagnostics toneAmber
class node_codegen toneMint
class node_asm_driver,node_asm_parse,node_encoder,node_registers,node_relocations,node_pe,node_coff,node_executable,node_object toneRose
class node_headers,node_msvcrt,node_lld,node_gcc,node_developer toneIndigo
class node_cli toneTeal
```

## Components

### C front end

- [Preprocessor](https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/mod.rs): `src/preprocessor/mod.rs`
- [Include resolver](https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/include.rs): `src/preprocessor/include.rs`
- [Macro expansion](https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/macros.rs): `src/preprocessor/macros.rs`
- [Conditional expressions](https://github.com/obijunior/vbrcc/blob/main/src/preprocessor/cond_expr.rs): `src/preprocessor/cond_expr.rs`
- [Lexer](https://github.com/obijunior/vbrcc/blob/main/src/lexer.rs): `src/lexer.rs`
- [Parser](https://github.com/obijunior/vbrcc/blob/main/src/parser.rs): `src/parser.rs`

### Semantic analysis

- [AST and types](https://github.com/obijunior/vbrcc/blob/main/src/ast.rs): `src/ast.rs`
- [Type checker](https://github.com/obijunior/vbrcc/blob/main/src/typeck.rs): `src/typeck.rs`
- [Constant evaluation](https://github.com/obijunior/vbrcc/blob/main/src/constfold.rs): `src/constfold.rs`
- [Diagnostics](https://github.com/obijunior/vbrcc/blob/main/src/diagnostic.rs): `src/diagnostic.rs`

### Code generation

- [Assembly generation](https://github.com/obijunior/vbrcc/blob/main/src/codegen.rs): `src/codegen.rs`

### Assembly and output

- [Assembler driver](https://github.com/obijunior/vbrcc/blob/main/src/assembler_driver.rs): `src/assembler_driver.rs`
- [Assembly parser](https://github.com/obijunior/vbrcc/blob/main/src/assembler/instruction.rs): `src/assembler/instruction.rs`
- [Instruction encoder](https://github.com/obijunior/vbrcc/blob/main/src/assembler/encoder.rs): `src/assembler/encoder.rs`
- [Register model](https://github.com/obijunior/vbrcc/blob/main/src/assembler/register.rs): `src/assembler/register.rs`
- [Relocations](https://github.com/obijunior/vbrcc/blob/main/src/assembler/relocation.rs): `src/assembler/relocation.rs`
- [PE executable writer](https://github.com/obijunior/vbrcc/blob/main/src/assembler/pe.rs): `src/assembler/pe.rs`
- [COFF object writer](https://github.com/obijunior/vbrcc/blob/main/src/assembler/coff.rs): `src/assembler/coff.rs`
- **Windows executable**
- **COFF object**

### Headers and integrations

- [Bundled C headers](https://github.com/obijunior/vbrcc/tree/main/src/headers): `src/headers`
- **Windows C runtime**
- **lld-link toolchain**
- **GCC toolchain**

### Other components

- **C source author**
- [Compiler CLI](https://github.com/obijunior/vbrcc/blob/main/src/main.rs): `src/main.rs`

## Connections

- C source author → Compiler CLI: provides source (evidence: `README.md`)
- Compiler CLI → Preprocessor: compiles input
- Preprocessor → Include resolver: resolves includes (evidence: `src/preprocessor/mod.rs`)
- Preprocessor → Macro expansion: expands macros (evidence: `src/preprocessor/mod.rs`)
- Preprocessor → Conditional expressions: evaluates directives (evidence: `src/preprocessor/mod.rs`)
- Preprocessor → Lexer: tokenizes lines (evidence: `src/preprocessor/mod.rs`)
- Preprocessor → Parser: emits tokens (evidence: `src/preprocessor/mod.rs`)
- Parser → AST and types: builds AST (evidence: `src/parser.rs`)
- Parser → Constant evaluation: folds constants (evidence: `src/parser.rs`)
- Type checker → AST and types: annotates expressions (evidence: `src/typeck.rs`)
- Type checker → Constant evaluation: evaluates constants (evidence: `src/typeck.rs`)
- Assembly generation → Type checker: consumes typed AST (evidence: `src/codegen.rs`)
- Assembly generation → AST and types: walks AST (evidence: `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 (evidence: `src/assembler/mod.rs`)
- Instruction encoder → Register model: uses registers (evidence: `src/assembler/encoder.rs`)
- Instruction encoder → Relocations: records relocations (evidence: `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 (evidence: `README.md`)
- COFF object writer → COFF object: produces object (evidence: `src/assembler/coff.rs`)
- Compiler CLI → Bundled C headers: preprocesses headers (evidence: `README.md`)
- Windows executable → Windows C runtime: imports runtime (evidence: `README.md`)
- Compiler CLI → lld-link toolchain: invokes optional linker (evidence: `README.md`)
- COFF object → lld-link toolchain: linked by (evidence: `README.md`)
- Compiler CLI → GCC toolchain: invokes optional backend (evidence: `README.md`)
