# kokinf/minicompiler architecture

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

- Interactive diagram: https://gitdiagram.com/kokinf/minicompiler
- Repository: https://github.com/kokinf/minicompiler

## Overview

MiniCompiler is a Go compiler for MiniLang that emits NASM x86-64 assembly. The principal workflow takes a source file through tokenization, parsing, semantic checks, intermediate representation, and native-code generation; the CLI also exposes inspection and diagnostics modes. The README documents the language’s arrays, C externals, and optimization capabilities. Connections for unsampled implementation details are omitted or shown as documented workflow; source excerpts do not expose all pipeline calls.

Main entry points: [`src/cmd/compiler/main.go`](https://github.com/kokinf/minicompiler/blob/main/src/cmd/compiler/main.go) (Compiler CLI), [`src/internal/codegen/x86_generator.go`](https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/x86_generator.go) (x86-64 Generator), [`src/internal/semantic/analyzer.go`](https://github.com/kokinf/minicompiler/blob/main/src/internal/semantic/analyzer.go) (Semantic Analyzer), [`src/internal/lexer/scanner.go`](https://github.com/kokinf/minicompiler/blob/main/src/internal/lexer/scanner.go) (Lexer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Language Front End"]
  node_lexer["Lexer<br/>[scanner.go]"]
  node_tokens["Token Model<br/>[token.go]"]
  node_parser["Parser<br/>[parser.go]"]
  node_ast["AST<br/>[ast.go]"]
  node_ast_views["AST Printers<br/>[printer.go]"]
end

subgraph group_middle["Analysis and IR"]
  node_semantic["Semantic Analyzer<br/>[analyzer.go]"]
  node_symbol_table["Symbol Table<br/>[symbol_table.go]"]
  node_type_system["Type System<br/>[type_system.go]"]
  node_ir_gen["IR Generator<br/>[generator.go]"]
  node_ir_opt["IR Optimizer<br/>[optimizer.go]"]
  node_ir_model["IR Model<br/>[instruction.go]"]
end

subgraph group_backend["Native Backend"]
  node_codegen["x86-64 Generator<br/>[x86_generator.go]"]
  node_expressions["Expression Codegen"]
  node_codegen_opts["Codegen Optimizations"]
  node_externals["C Call Support<br/>[external_calls.go]"]
  node_libc_decls["C Library Declarations<br/>[stdlib.h]"]
  node_runtime["Runtime Assembly<br/>[runtime.asm]"]
end

subgraph group_cli["CLI and Diagnostics"]
  node_cli_main["Compiler CLI<br/>[main.go]"]
  node_diagnostics["Error Formatting<br/>[error_formatter.go]"]
  node_warnings["Warning Controls<br/>[warnings.go]"]
end

node_developer(("MiniLang Developer"))
node_assembly["NASM Assembly"]

node_developer -->|"invokes"| node_cli_main
node_cli_main -->|"tokenizes"| node_lexer
node_lexer -->|"creates tokens"| node_tokens
node_cli_main -->|"parses source"| node_parser
node_parser -->|"builds AST"| node_ast
node_cli_main -->|"checks program"| node_semantic
node_semantic -->|"tracks symbols"| node_symbol_table
node_semantic -.->|"checks types"| node_type_system
node_cli_main -->|"generates IR"| node_ir_gen
node_ir_gen -->|"emits instructions"| node_ir_model
node_cli_main -->|"optimizes IR"| node_ir_opt
node_ir_opt -.->|"rewrites IR"| node_ir_model
node_cli_main -->|"generates assembly"| node_codegen
node_codegen -.->|"delegates expressions"| node_expressions
node_codegen -.->|"applies passes"| node_codegen_opts
node_codegen -->|"emits NASM"| node_assembly
node_cli_main -->|"prints AST"| node_ast_views
node_developer -->|"selects format"| node_diagnostics
node_cli_main -->|"reports errors"| node_diagnostics
node_cli_main -->|"configures warnings"| node_warnings
node_codegen -.->|"handles C calls"| node_externals
node_externals -.->|"uses declarations"| node_libc_decls
node_assembly -->|"links runtime"| node_runtime

click node_cli_main "https://github.com/kokinf/minicompiler/blob/main/src/cmd/compiler/main.go"
click node_lexer "https://github.com/kokinf/minicompiler/blob/main/src/internal/lexer/scanner.go"
click node_tokens "https://github.com/kokinf/minicompiler/blob/main/src/internal/token/token.go"
click node_parser "https://github.com/kokinf/minicompiler/blob/main/src/internal/parser/parser.go"
click node_ast "https://github.com/kokinf/minicompiler/blob/main/src/internal/ast/ast.go"
click node_ast_views "https://github.com/kokinf/minicompiler/blob/main/src/internal/ast/printer.go"
click node_semantic "https://github.com/kokinf/minicompiler/blob/main/src/internal/semantic/analyzer.go"
click node_symbol_table "https://github.com/kokinf/minicompiler/blob/main/src/internal/semantic/symbol_table.go"
click node_type_system "https://github.com/kokinf/minicompiler/blob/main/src/internal/semantic/type_system.go"
click node_ir_gen "https://github.com/kokinf/minicompiler/blob/main/src/internal/ir/generator.go"
click node_ir_opt "https://github.com/kokinf/minicompiler/blob/main/src/internal/ir/optimizer.go"
click node_ir_model "https://github.com/kokinf/minicompiler/blob/main/src/internal/ir/instruction.go"
click node_codegen "https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/x86_generator.go"
click node_expressions "https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/expression_generator.go"
click node_codegen_opts "https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/optimization_passes.go"
click node_externals "https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/external_calls.go"
click node_libc_decls "https://github.com/kokinf/minicompiler/blob/main/src/libc/stdlib.h"
click node_runtime "https://github.com/kokinf/minicompiler/blob/main/src/runtime/runtime.asm"
click node_diagnostics "https://github.com/kokinf/minicompiler/blob/main/src/internal/utils/error_formatter.go"
click node_warnings "https://github.com/kokinf/minicompiler/blob/main/src/internal/utils/warnings.go"

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_lexer,node_tokens,node_parser,node_ast,node_ast_views toneBlue
class node_semantic,node_symbol_table,node_type_system,node_ir_gen,node_ir_opt,node_ir_model toneAmber
class node_codegen,node_expressions,node_codegen_opts,node_externals,node_libc_decls,node_runtime toneMint
class node_cli_main,node_diagnostics,node_warnings toneRose
class node_developer,node_assembly toneIndigo
```

## Components

### Language Front End

- [Lexer](https://github.com/kokinf/minicompiler/blob/main/src/internal/lexer/scanner.go): `src/internal/lexer/scanner.go`
- [Token Model](https://github.com/kokinf/minicompiler/blob/main/src/internal/token/token.go): `src/internal/token/token.go`
- [Parser](https://github.com/kokinf/minicompiler/blob/main/src/internal/parser/parser.go): `src/internal/parser/parser.go`
- [AST](https://github.com/kokinf/minicompiler/blob/main/src/internal/ast/ast.go): `src/internal/ast/ast.go`
- [AST Printers](https://github.com/kokinf/minicompiler/blob/main/src/internal/ast/printer.go): `src/internal/ast/printer.go`

### Analysis and IR

- [Semantic Analyzer](https://github.com/kokinf/minicompiler/blob/main/src/internal/semantic/analyzer.go): `src/internal/semantic/analyzer.go`
- [Symbol Table](https://github.com/kokinf/minicompiler/blob/main/src/internal/semantic/symbol_table.go): `src/internal/semantic/symbol_table.go`
- [Type System](https://github.com/kokinf/minicompiler/blob/main/src/internal/semantic/type_system.go): `src/internal/semantic/type_system.go`
- [IR Generator](https://github.com/kokinf/minicompiler/blob/main/src/internal/ir/generator.go): `src/internal/ir/generator.go`
- [IR Optimizer](https://github.com/kokinf/minicompiler/blob/main/src/internal/ir/optimizer.go): `src/internal/ir/optimizer.go`
- [IR Model](https://github.com/kokinf/minicompiler/blob/main/src/internal/ir/instruction.go): `src/internal/ir/instruction.go`

### Native Backend

- [x86-64 Generator](https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/x86_generator.go): `src/internal/codegen/x86_generator.go`
- [Expression Codegen](https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/expression_generator.go): `src/internal/codegen/expression_generator.go`
- [Codegen Optimizations](https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/optimization_passes.go): `src/internal/codegen/optimization_passes.go`
- [C Call Support](https://github.com/kokinf/minicompiler/blob/main/src/internal/codegen/external_calls.go): `src/internal/codegen/external_calls.go`
- [C Library Declarations](https://github.com/kokinf/minicompiler/blob/main/src/libc/stdlib.h): `src/libc/stdlib.h`
- [Runtime Assembly](https://github.com/kokinf/minicompiler/blob/main/src/runtime/runtime.asm): `src/runtime/runtime.asm`

### CLI and Diagnostics

- [Compiler CLI](https://github.com/kokinf/minicompiler/blob/main/src/cmd/compiler/main.go): `src/cmd/compiler/main.go`
- [Error Formatting](https://github.com/kokinf/minicompiler/blob/main/src/internal/utils/error_formatter.go): `src/internal/utils/error_formatter.go`
- [Warning Controls](https://github.com/kokinf/minicompiler/blob/main/src/internal/utils/warnings.go): `src/internal/utils/warnings.go`

### Other components

- **MiniLang Developer**
- **NASM Assembly**

## Connections

- MiniLang Developer → Compiler CLI: invokes (evidence: `README.md`)
- Compiler CLI → Lexer: tokenizes (evidence: `README.md`)
- Lexer → Token Model: creates tokens (evidence: `src/internal/lexer/scanner.go`)
- Compiler CLI → Parser: parses source (evidence: `README.md`)
- Parser → AST: builds AST (evidence: `README.md`)
- Compiler CLI → Semantic Analyzer: checks program (evidence: `src/cmd/compiler/main.go`)
- Semantic Analyzer → Symbol Table: tracks symbols (evidence: `src/internal/semantic/analyzer.go`)
- Semantic Analyzer → Type System: checks types
- Compiler CLI → IR Generator: generates IR (evidence: `README.md`)
- IR Generator → IR Model: emits instructions (evidence: `README.md`)
- Compiler CLI → IR Optimizer: optimizes IR (evidence: `README.md`)
- IR Optimizer → IR Model: rewrites IR
- Compiler CLI → x86-64 Generator: generates assembly (evidence: `README.md`)
- x86-64 Generator → Expression Codegen: delegates expressions
- x86-64 Generator → Codegen Optimizations: applies passes
- x86-64 Generator → NASM Assembly: emits NASM (evidence: `README.md`)
- Compiler CLI → AST Printers: prints AST (evidence: `README.md`)
- MiniLang Developer → Error Formatting: selects format (evidence: `README.md`)
- Compiler CLI → Error Formatting: reports errors (evidence: `src/cmd/compiler/main.go`)
- Compiler CLI → Warning Controls: configures warnings (evidence: `README.md`)
- x86-64 Generator → C Call Support: handles C calls
- C Call Support → C Library Declarations: uses declarations
- NASM Assembly → Runtime Assembly: links runtime (evidence: `README.md`)
