# daichikahtava/wacc-compiler architecture

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

- Interactive diagram: https://gitdiagram.com/daichikahtava/wacc-compiler
- Repository: https://github.com/daichikahtava/wacc-compiler

## Overview

This repository implements a WACC compiler: a source file is parsed into an AST, checked for semantic correctness, translated into AArch64 instructions, and written as assembly. Parsing and semantic errors stop the workflow before code generation. The compiler also provides runtime helper routines and register allocation support. The sampled excerpts show the main orchestration and several module interactions; links for unsampled internals are omitted rather than inferred.

Main entry points: [`src/main/wacc/treeWalker.scala`](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/treeWalker.scala) (AST translator), [`src/main/wacc/Main.scala`](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/Main.scala) (Compiler entry), [`src/main/wacc/aarch64_formatter.scala`](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/aarch64_formatter.scala) (AArch64 formatter), [`src/main/wacc/semantics.scala`](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/semantics.scala) (Semantic checker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_front["Language Frontend"]
  node_lexer["WACC lexer<br/>[lexer.scala]"]
  node_parser["WACC parser<br/>[parser.scala]"]
  node_ast["AST model<br/>[syntax.scala]"]
  node_bridges["Parser bridges"]
end

subgraph group_analysis["Semantic Analysis"]
  node_semantics["Semantic checker<br/>[semantics.scala]"]
  node_symbols["Scopes and types<br/>[symTable.scala]"]
  node_errors["Semantic diagnostics"]
end

subgraph group_codegen["Code Generation"]
  node_walker["AST translator<br/>[treeWalker.scala]"]
  node_instructions["Instruction model<br/>[instructions.scala]"]
  node_formatter["AArch64 formatter"]
  node_registers["Register configuration"]
  node_assembly["Assembly output"]
end

subgraph group_runtime["Runtime Support"]
  node_helpers["Runtime helpers"]
end

node_user(("Compiler user"))
node_main["Compiler entry<br/>[Main.scala]"]

node_user -->|"provides source"| node_main
node_main -->|"parses input"| node_parser
node_parser -->|"builds AST"| node_ast
node_ast -->|"uses implicits"| node_lexer
node_ast -->|"uses bridges"| node_bridges
node_main -->|"checks AST"| node_semantics
node_semantics -->|"tracks scopes"| node_symbols
node_semantics -->|"reports errors"| node_errors
node_main -->|"translates AST"| node_walker
node_walker -->|"queries types"| node_semantics
node_walker -->|"registers helpers"| node_formatter
node_walker -->|"produces instructions"| node_instructions
node_formatter -->|"formats instructions"| node_instructions
node_formatter -->|"uses configuration"| node_registers
node_walker -->|"requests routines"| node_helpers
node_helpers -->|"defines instructions"| node_instructions
node_helpers -->|"uses configuration"| node_registers
node_main -->|"writes assembly"| node_formatter
node_formatter -->|"emits file"| node_assembly

click node_main "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/Main.scala"
click node_lexer "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/lexer.scala"
click node_parser "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/parser.scala"
click node_ast "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/syntax.scala"
click node_bridges "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/parserBridgepos.scala"
click node_semantics "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/semantics.scala"
click node_symbols "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/symTable.scala"
click node_errors "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/semErrorReporter.scala"
click node_walker "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/treeWalker.scala"
click node_instructions "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/instructions.scala"
click node_formatter "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/aarch64_formatter.scala"
click node_registers "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/registerConfig.scala"
click node_helpers "https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/internalFunctions.scala"

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_parser,node_ast,node_bridges,node_user toneBlue
class node_semantics,node_symbols,node_errors toneAmber
class node_walker,node_instructions,node_formatter,node_registers,node_assembly toneMint
class node_helpers toneRose
class node_main toneTeal
```

## Components

### Language Frontend

- [WACC lexer](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/lexer.scala): `src/main/wacc/lexer.scala`
- [WACC parser](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/parser.scala): `src/main/wacc/parser.scala`
- [AST model](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/syntax.scala): `src/main/wacc/syntax.scala`
- [Parser bridges](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/parserBridgepos.scala): `src/main/wacc/parserBridgepos.scala`

### Semantic Analysis

- [Semantic checker](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/semantics.scala): `src/main/wacc/semantics.scala`
- [Scopes and types](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/symTable.scala): `src/main/wacc/symTable.scala`
- [Semantic diagnostics](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/semErrorReporter.scala): `src/main/wacc/semErrorReporter.scala`

### Code Generation

- [AST translator](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/treeWalker.scala): `src/main/wacc/treeWalker.scala`
- [Instruction model](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/instructions.scala): `src/main/wacc/instructions.scala`
- [AArch64 formatter](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/aarch64_formatter.scala): `src/main/wacc/aarch64_formatter.scala`
- [Register configuration](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/registerConfig.scala): `src/main/wacc/registerConfig.scala`
- **Assembly output**

### Runtime Support

- [Runtime helpers](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/internalFunctions.scala): `src/main/wacc/internalFunctions.scala`

### Other components

- **Compiler user**
- [Compiler entry](https://github.com/daichikahtava/wacc-compiler/blob/main/src/main/wacc/Main.scala): `src/main/wacc/Main.scala`

## Connections

- Compiler user → Compiler entry: provides source (evidence: `src/main/wacc/Main.scala`)
- Compiler entry → WACC parser: parses input (evidence: `src/main/wacc/Main.scala`)
- WACC parser → AST model: builds AST (evidence: `src/main/wacc/parser.scala`)
- AST model → WACC lexer: uses implicits (evidence: `src/main/wacc/syntax.scala`)
- AST model → Parser bridges: uses bridges (evidence: `src/main/wacc/syntax.scala`)
- Compiler entry → Semantic checker: checks AST (evidence: `src/main/wacc/Main.scala`)
- Semantic checker → Scopes and types: tracks scopes (evidence: `src/main/wacc/semantics.scala`)
- Semantic checker → Semantic diagnostics: reports errors (evidence: `src/main/wacc/semantics.scala`)
- Compiler entry → AST translator: translates AST (evidence: `src/main/wacc/Main.scala`)
- AST translator → Semantic checker: queries types (evidence: `src/main/wacc/treeWalker.scala`)
- AST translator → AArch64 formatter: registers helpers (evidence: `src/main/wacc/treeWalker.scala`)
- AST translator → Instruction model: produces instructions (evidence: `src/main/wacc/treeWalker.scala`)
- AArch64 formatter → Instruction model: formats instructions (evidence: `src/main/wacc/aarch64_formatter.scala`)
- AArch64 formatter → Register configuration: uses configuration (evidence: `src/main/wacc/aarch64_formatter.scala`)
- AST translator → Runtime helpers: requests routines (evidence: `src/main/wacc/treeWalker.scala`)
- Runtime helpers → Instruction model: defines instructions (evidence: `src/main/wacc/internalFunctions.scala`)
- Runtime helpers → Register configuration: uses configuration (evidence: `src/main/wacc/internalFunctions.scala`)
- Compiler entry → AArch64 formatter: writes assembly (evidence: `src/main/wacc/Main.scala`)
- AArch64 formatter → Assembly output: emits file (evidence: `src/main/wacc/aarch64_formatter.scala`)
