# spotandjake/amod-4901 architecture

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

- Interactive diagram: https://gitdiagram.com/spotandjake/amod-4901
- Repository: https://github.com/spotandjake/amod-4901

## Overview

Decaf is a course-language compiler whose library API and CLI turn Decaf source into WebAssembly text (WAT). The principal workflow is lexing and parsing, front-end validation, type checking, ANF lowering and optimization, then WebAssembly code generation and module serialization. The graph also preserves the compiler’s intermediate representations and the documented ability to run generated WAT with an external WebAssembly runtime. Edges follow the API pipeline and indexed references; some internal front-end and backend wiring is not shown in the excerpts.

Main entry points: [`decaf/Compiler.cs`](https://github.com/spotandjake/amod-4901/blob/main/decaf/Compiler.cs) (Compiler API), [`decaf/Backend/Codegen.cs`](https://github.com/spotandjake/amod-4901/blob/main/decaf/Backend/Codegen.cs) (Code generation), [`decaf/IR/AnfTree.cs`](https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/AnfTree.cs) (ANF IR), [`decaf/Main.cs`](https://github.com/spotandjake/amod-4901/blob/main/decaf/Main.cs) (CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and API"]
  node_cli["CLI<br/>[Main.cs]"]
  node_compiler["Compiler API<br/>[Compiler.cs]"]
end

subgraph group_frontend["Front end"]
  node_lexer["Lexer<br/>[DecafLexer.cs]"]
  node_parser["Parser<br/>[DecafParser.cs]"]
  node_mapper["Parse-tree mapper<br/>[ParseTreeMapper.cs]"]
  node_scope["Scope checker<br/>[ScopeChecker.cs]"]
  node_semantic["Semantic analysis"]
end

subgraph group_middle["Middle end"]
  node_typecheck["Type checker<br/>[TypeChecker.cs]"]
  node_anfmapper["ANF lowering<br/>[AnfMapper.cs]"]
  node_optimizer["Optimizer<br/>[Main.cs]"]
end

subgraph group_ir["Intermediate representations"]
  node_parseir["Parse tree IR<br/>[ParseTree.cs]"]
  node_typedir["Typed tree IR<br/>[TypedTree.cs]"]
  node_anfir["ANF IR<br/>[AnfTree.cs]"]
  node_signatures["Type signatures<br/>[Signature.cs]"]
end

subgraph group_backend["WebAssembly backend"]
  node_codegen["Code generation<br/>[Codegen.cs]"]
  node_expressions["Wasm expressions<br/>[Expression.cs]"]
  node_module["Wasm module<br/>[WasmModule.cs]"]
  node_wat["Generated WAT<br/>[WasmModule.cs]"]
end

node_user(("Compiler user"))
node_runtime(("WebAssembly runtime"))

node_user -->|"invokes"| node_cli
node_cli -->|"calls"| node_compiler
node_compiler -->|"lexes"| node_lexer
node_compiler -->|"parses"| node_parser
node_compiler -->|"maps"| node_mapper
node_compiler -->|"checks scope"| node_scope
node_compiler -.->|"checks semantics"| node_semantic
node_compiler -->|"type checks"| node_typecheck
node_compiler -->|"lowers"| node_anfmapper
node_compiler -->|"optimizes"| node_optimizer
node_compiler -->|"generates code"| node_codegen
node_mapper -->|"builds"| node_parseir
node_typecheck -->|"produces"| node_typedir
node_anfmapper -->|"produces"| node_anfir
node_optimizer -->|"transforms"| node_anfir
node_codegen -->|"consumes"| node_anfir
node_codegen -->|"builds"| node_expressions
node_codegen -->|"builds"| node_module
node_module -->|"serializes"| node_wat
node_wat -->|"runs in"| node_runtime

click node_cli "https://github.com/spotandjake/amod-4901/blob/main/decaf/Main.cs"
click node_compiler "https://github.com/spotandjake/amod-4901/blob/main/decaf/Compiler.cs"
click node_lexer "https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/DecafLexer.cs"
click node_parser "https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/DecafParser.cs"
click node_mapper "https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/ParseTreeMapper.cs"
click node_scope "https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/ScopeChecker.cs"
click node_semantic "https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/SemanticAnalysis.cs"
click node_typecheck "https://github.com/spotandjake/amod-4901/blob/main/decaf/MiddleEnd/TypeChecker.cs"
click node_anfmapper "https://github.com/spotandjake/amod-4901/blob/main/decaf/MiddleEnd/AnfMapper.cs"
click node_optimizer "https://github.com/spotandjake/amod-4901/blob/main/decaf/MiddleEnd/Optimizations/Main.cs"
click node_parseir "https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/ParseTree.cs"
click node_typedir "https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/TypedTree.cs"
click node_anfir "https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/AnfTree.cs"
click node_signatures "https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/Signature.cs"
click node_codegen "https://github.com/spotandjake/amod-4901/blob/main/decaf/Backend/Codegen.cs"
click node_expressions "https://github.com/spotandjake/amod-4901/blob/main/decaf/WasmBuilder/Expression.cs"
click node_module "https://github.com/spotandjake/amod-4901/blob/main/decaf/WasmBuilder/WasmModule.cs"
click node_wat "https://github.com/spotandjake/amod-4901/blob/main/decaf/WasmBuilder/WasmModule.cs"

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_cli,node_compiler,node_user toneBlue
class node_lexer,node_parser,node_mapper,node_scope,node_semantic toneAmber
class node_typecheck,node_anfmapper,node_optimizer toneMint
class node_parseir,node_typedir,node_anfir,node_signatures toneRose
class node_codegen,node_expressions,node_module,node_wat,node_runtime toneIndigo
```

## Components

### Entry and API

- [CLI](https://github.com/spotandjake/amod-4901/blob/main/decaf/Main.cs): `decaf/Main.cs`
- [Compiler API](https://github.com/spotandjake/amod-4901/blob/main/decaf/Compiler.cs): `decaf/Compiler.cs`

### Front end

- [Lexer](https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/DecafLexer.cs): `decaf/Frontend/DecafLexer.cs`
- [Parser](https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/DecafParser.cs): `decaf/Frontend/DecafParser.cs`
- [Parse-tree mapper](https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/ParseTreeMapper.cs): `decaf/Frontend/ParseTreeMapper.cs`
- [Scope checker](https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/ScopeChecker.cs): `decaf/Frontend/ScopeChecker.cs`
- [Semantic analysis](https://github.com/spotandjake/amod-4901/blob/main/decaf/Frontend/SemanticAnalysis.cs): `decaf/Frontend/SemanticAnalysis.cs`

### Middle end

- [Type checker](https://github.com/spotandjake/amod-4901/blob/main/decaf/MiddleEnd/TypeChecker.cs): `decaf/MiddleEnd/TypeChecker.cs`
- [ANF lowering](https://github.com/spotandjake/amod-4901/blob/main/decaf/MiddleEnd/AnfMapper.cs): `decaf/MiddleEnd/AnfMapper.cs`
- [Optimizer](https://github.com/spotandjake/amod-4901/blob/main/decaf/MiddleEnd/Optimizations/Main.cs): `decaf/MiddleEnd/Optimizations/Main.cs`

### Intermediate representations

- [Parse tree IR](https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/ParseTree.cs): `decaf/IR/ParseTree.cs`
- [Typed tree IR](https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/TypedTree.cs): `decaf/IR/TypedTree.cs`
- [ANF IR](https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/AnfTree.cs): `decaf/IR/AnfTree.cs`
- [Type signatures](https://github.com/spotandjake/amod-4901/blob/main/decaf/IR/Signature.cs): `decaf/IR/Signature.cs`

### WebAssembly backend

- [Code generation](https://github.com/spotandjake/amod-4901/blob/main/decaf/Backend/Codegen.cs): `decaf/Backend/Codegen.cs`
- [Wasm expressions](https://github.com/spotandjake/amod-4901/blob/main/decaf/WasmBuilder/Expression.cs): `decaf/WasmBuilder/Expression.cs`
- [Wasm module](https://github.com/spotandjake/amod-4901/blob/main/decaf/WasmBuilder/WasmModule.cs): `decaf/WasmBuilder/WasmModule.cs`
- [Generated WAT](https://github.com/spotandjake/amod-4901/blob/main/decaf/WasmBuilder/WasmModule.cs): `decaf/WasmBuilder/WasmModule.cs`

### Other components

- **Compiler user**
- **WebAssembly runtime**

## Connections

- Compiler user → CLI: invokes
- CLI → Compiler API: calls (evidence: `decaf/Main.cs`)
- Compiler API → Lexer: lexes (evidence: `decaf/Compiler.cs`)
- Compiler API → Parser: parses (evidence: `decaf/Compiler.cs`)
- Compiler API → Parse-tree mapper: maps (evidence: `decaf/Compiler.cs`)
- Compiler API → Scope checker: checks scope (evidence: `decaf/Compiler.cs`)
- Compiler API → Semantic analysis: checks semantics
- Compiler API → Type checker: type checks (evidence: `decaf/Compiler.cs`)
- Compiler API → ANF lowering: lowers (evidence: `decaf/Compiler.cs`)
- Compiler API → Optimizer: optimizes (evidence: `decaf/Compiler.cs`)
- Compiler API → Code generation: generates code (evidence: `decaf/Compiler.cs`)
- Parse-tree mapper → Parse tree IR: builds (evidence: `decaf/Frontend/ParseTreeMapper.cs`)
- Type checker → Typed tree IR: produces (evidence: `decaf/MiddleEnd/TypeChecker.cs`)
- ANF lowering → ANF IR: produces (evidence: `decaf/MiddleEnd/AnfMapper.cs`)
- Optimizer → ANF IR: transforms (evidence: `decaf/MiddleEnd/Optimizations/Main.cs`)
- Code generation → ANF IR: consumes (evidence: `decaf/Backend/Codegen.cs`)
- Code generation → Wasm expressions: builds (evidence: `decaf/Backend/Codegen.cs`)
- Code generation → Wasm module: builds (evidence: `decaf/Backend/Codegen.cs`)
- Wasm module → Generated WAT: serializes (evidence: `decaf/WasmBuilder/WasmModule.cs`)
- Generated WAT → WebAssembly runtime: runs in
