# h2oprooftoaster/bencth architecture

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

- Interactive diagram: https://gitdiagram.com/h2oprooftoaster/bencth
- Repository: https://github.com/h2oprooftoaster/bencth

## Overview

Bencthc is a small C compiler that accepts a source-file path and emits x86-64 assembly. The visible driver reads and displays the input, then invokes lexing, parsing, and code generation, freeing their arenas afterward. The parser builds translation-unit structures and uses symbol tables; code generation writes assembly. A semantic analyzer and assembly syscall/runtime support are present in the tree, but their connections to the driver are not established by the excerpts. The README is empty, so capability coverage is limited to the source evidence provided.

Main entry points: [`bencthc/src/main.c`](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/main.c) (Compiler driver), [`bencthc/src/parser.c`](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/parser.c) (Parser), [`bencthc/src/codeGenerator.c`](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/codeGenerator.c) (Code generator), [`bencthc/src/utils/file.c`](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/file.c) (File utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Compiler frontend"]
  node_driver["Compiler driver<br/>[main.c]"]
  node_lexer["Lexer<br/>[lexer.c]"]
  node_parser["Parser<br/>[parser.c]"]
  node_ast["Grammar structures<br/>[structs.h]"]
  node_symbols["Symbol tables<br/>[symbols.c]"]
  node_semantic["Semantic analyzer<br/>[semanticAnalyzer.c]"]
end

subgraph group_backend["Assembly backend"]
  node_codegen["Code generator<br/>[codeGenerator.c]"]
end

subgraph group_support["Runtime support"]
  node_fileio["File utilities<br/>[file.c]"]
  node_allocator["Arena allocator<br/>[allocator.c]"]
  node_strings["String utilities<br/>[string.c]"]
  node_syscalls["Linux syscalls<br/>[syscall.h]"]
  node_asm_runtime["Assembly runtime<br/>[b_crt.s]"]
end

node_user(("Compiler user"))
node_source["Input source"]
node_assembly["Assembly output"]

node_user -->|"runs"| node_driver
node_user -->|"provides"| node_source
node_driver -->|"reads input"| node_fileio
node_driver -->|"lexes"| node_lexer
node_driver -->|"parses"| node_parser
node_driver -->|"generates assembly"| node_codegen
node_driver -->|"writes"| node_assembly
node_parser -->|"uses"| node_symbols
node_parser -->|"builds"| node_ast
node_codegen -->|"writes output"| node_fileio
node_codegen -->|"looks up"| node_symbols
node_semantic -.->|"analyzes"| node_ast
node_fileio -.->|"uses"| node_syscalls
node_allocator -.->|"allocates via"| node_syscalls
node_asm_runtime -.->|"wraps"| node_syscalls

click node_driver "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/main.c"
click node_lexer "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/lexer.c"
click node_parser "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/parser.c"
click node_ast "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/structs.h"
click node_symbols "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/symbols.c"
click node_semantic "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/semanticAnalyzer.c"
click node_codegen "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/codeGenerator.c"
click node_fileio "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/file.c"
click node_allocator "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/allocator.c"
click node_strings "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/string.c"
click node_syscalls "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/syscalls/syscall.h"
click node_asm_runtime "https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/runtime/b_crt.s"

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_driver,node_lexer,node_parser,node_ast,node_symbols,node_semantic,node_user toneBlue
class node_codegen toneAmber
class node_fileio,node_allocator,node_strings,node_syscalls,node_asm_runtime toneMint
class node_source,node_assembly toneIndigo
```

## Components

### Compiler frontend

- [Compiler driver](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/main.c): `bencthc/src/main.c`
- [Lexer](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/lexer.c): `bencthc/src/lexer.c`
- [Parser](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/parser.c): `bencthc/src/parser.c`
- [Grammar structures](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/structs.h): `bencthc/src/structs.h`
- [Symbol tables](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/symbols.c): `bencthc/src/utils/symbols.c`
- [Semantic analyzer](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/semanticAnalyzer.c): `bencthc/src/semanticAnalyzer.c`

### Assembly backend

- [Code generator](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/codeGenerator.c): `bencthc/src/codeGenerator.c`

### Runtime support

- [File utilities](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/file.c): `bencthc/src/utils/file.c`
- [Arena allocator](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/allocator.c): `bencthc/src/utils/allocator.c`
- [String utilities](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/string.c): `bencthc/src/utils/string.c`
- [Linux syscalls](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/src/utils/syscalls/syscall.h): `bencthc/src/utils/syscalls/syscall.h`
- [Assembly runtime](https://github.com/h2oprooftoaster/bencth/blob/main/bencthc/runtime/b_crt.s): `bencthc/runtime/b_crt.s`

### Other components

- **Compiler user**
- **Input source**
- **Assembly output**

## Connections

- Compiler user → Compiler driver: runs (evidence: `bencthc/src/main.c`)
- Compiler user → Input source: provides
- Compiler driver → File utilities: reads input (evidence: `bencthc/src/main.c`)
- Compiler driver → Lexer: lexes (evidence: `bencthc/src/main.c`)
- Compiler driver → Parser: parses (evidence: `bencthc/src/main.c`)
- Compiler driver → Code generator: generates assembly (evidence: `bencthc/src/main.c`)
- Compiler driver → Assembly output: writes
- Parser → Symbol tables: uses (evidence: `bencthc/src/parser.c`)
- Parser → Grammar structures: builds (evidence: `bencthc/src/parser.c`)
- Code generator → File utilities: writes output (evidence: `bencthc/src/codeGenerator.c`)
- Code generator → Symbol tables: looks up (evidence: `bencthc/src/codeGenerator.c`)
- Semantic analyzer → Grammar structures: analyzes (evidence: `bencthc/src/semanticAnalyzer.c`)
- File utilities → Linux syscalls: uses (evidence: `bencthc/src/utils/file.c`)
- Arena allocator → Linux syscalls: allocates via (evidence: `bencthc/src/utils/allocator.c`)
- Assembly runtime → Linux syscalls: wraps
