# acmpesuecc/awasme architecture

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

- Interactive diagram: https://gitdiagram.com/acmpesuecc/awasme
- Repository: https://github.com/acmpesuecc/awasme

## Overview

1. **Repository purpose**
   - This is a C++20 WebAssembly interpreter called **aWASMe**.
   - The codebase is split into two main execution paths: a **parser** that reads and decodes WASM binaries, and an **engine** that simulates execution in a VM.
   - The README describes a dual-mode setup: native CLI execution and a browser-oriented build via **Emscripten**.

2. **Top-level architecture**
   - The repo is organized around a shared core model in `include/module`, with separate parser and engine subsystems built on top of it.
   - `src/parser` consumes raw WASM bytes and builds an internal module representation.
   - `src/engine` takes that module representation and runs it inside a virtual machine.

3. **Shared module layer**
   - `include/module` defines the common data structures used by both sides of the pipeline:
     - `module.hpp` for the overall WASM module model
     - `instruction.hpp` for decoded instructions
     - `value.hpp` for runtime/value types
   - This layer is the boundary between decoding and execution: parser outputs these structures, engine consumes them.

4. **Parsing subsystem**
   - `src/parser/codeparsing.cpp` and `include/parser/codeparsing.hpp` suggest the low-level binary parsing logic for reading WASM sections and instruction streams.
   - `parser.cpp` and `types.hpp` likely handle higher-level syntactic/semantic interpretation of decoded bytes.
   - The parser executable in `src/parser/main.cpp` is the CLI entry point for loading a `.wasm` file and producing a structured internal representation.

5. **Execution subsystem**
   - `src/engine/vm.cpp` is the center of the interpreter: it likely manages instruction dispatch, stack behavior, and control flow.
   - `funcs.cpp` contains instruction or host-function implementations, while `instruction.cpp` maps decoded opcodes to runtime behavior.
   - `value.cpp` holds runtime value handling, and `errors.cpp` centralizes execution-time failures.

6. **Runtime state and boundaries**
   - `include/engine/global.hpp` implies a small set of shared runtime globals or configuration used across the VM.
   - The engine is responsible for simulation concerns such as stacks, locals, globals, and possibly linear memory, while the parser remains purely representational.
   - This separation keeps decoding logic independent from execution logic.

7. **End-to-end data flow**
   - Input starts as a binary WASM file.
   - The parser decodes the file into the shared module/instruction/value model.
   - The engine loads that model and executes it instruction-by-instruction in the VM.
   - Errors can occur in either phase: parse/validation errors in the parser, runtime faults in the engine.

8. **Browser/runtime integration**
   - The README indicates the project is intended to run in the browser through **Emscripten**.
   - `index.js` is likely the JavaScript bootstrap or glue layer for the WebAssembly-compiled runtime.
   - In architecture terms, Emscripten is the bridge that turns the C++ engine into a browser-consumable artifact.

9. **Build and execution model**
   - `Makefile` orchestrates the two deliverables: `engine.exe` and `parser.exe`.
   - The engine can run standalone, while the parser is a diagnostic/inspection tool for a given WASM file.
   - This suggests the repo supports both development-time inspection and execution-time simulation.

10. **Current scope and planned expansion**
   - The README’s future work points to missing or partial support for advanced WASM features: tables, reference types, exception handling, SIMD, and a fuller simulator UI.
   - That implies the current architecture is centered on core WASM parsing and a baseline interpreter, with room for richer runtime state visualization later.

11. **What to diagram**
   - A useful architecture diagram should show:
     - WASM binary input
     - Parser pipeline
     - Shared module representation
     - VM execution engine
     - Error handling path
     - Browser/Emscripten packaging path
   - The key boundary is between **decoded module data** and **runtime execution state**.

Main entry points: [`src/parser/parser.cpp`](https://github.com/acmpesuecc/awasme/blob/main/src/parser/parser.cpp) (Parser core), [`src/engine/vm.cpp`](https://github.com/acmpesuecc/awasme/blob/main/src/engine/vm.cpp) (VM), [`src/engine/instruction.cpp`](https://github.com/acmpesuecc/awasme/blob/main/src/engine/instruction.cpp) (Opcode exec), [`Makefile`](https://github.com/acmpesuecc/awasme/tree/main/Makefile) (Build)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_shared["Shared Core"]
  node_module_model[("Module model<br/>IR<br/>[module.hpp]")]
  node_instruction_model["Instructions<br/>IR<br/>[instruction.hpp]"]
  node_value_model["Values<br/>IR<br/>[value.hpp]"]
end

subgraph group_group_parser["Parser Path"]
  node_parser_main["Parser CLI<br/>entrypoint<br/>[main.cpp]"]
  node_codeparsing["Code parsing<br/>decoder<br/>[codeparsing.cpp]"]
  node_parser_core["Parser core<br/>builder<br/>[parser.cpp]"]
  node_parser_types{{"Parse types<br/>schema<br/>[types.hpp]"}}
end

subgraph group_group_engine["Engine Path"]
  node_engine_main["Engine CLI<br/>entrypoint<br/>[main.cpp]"]
  node_vm["VM<br/>interpreter<br/>[vm.cpp]"]
  node_instruction_exec["Opcode exec<br/>dispatch<br/>[instruction.cpp]"]
  node_funcs["Functions<br/>runtime<br/>[funcs.cpp]"]
  node_engine_values["Value runtime<br/>[value.cpp]"]
  node_errors["Errors<br/>faults<br/>[errors.cpp]"]
  node_global_state{{"Globals<br/>state<br/>[global.hpp]"}}
end

subgraph group_group_runtime["Runtime & Packaging"]
  node_emscripten_glue["Emscripten glue<br/>bridge<br/>[index.js]"]
  node_build["Build<br/>orchestration"]
end

node_wasm_input["WASM binary<br/>input"]

node_wasm_input -->|"loads"| node_parser_main
node_parser_main -->|"invokes"| node_codeparsing
node_codeparsing -->|"decodes into"| node_parser_core
node_parser_core -->|"uses"| node_parser_types
node_parser_core -->|"builds"| node_module_model
node_parser_core -->|"emits"| node_instruction_model
node_parser_core -->|"emits"| node_value_model
node_module_model -->|"loads"| node_engine_main
node_engine_main -->|"starts"| node_vm
node_vm -->|"reads"| node_global_state
node_vm -->|"dispatches"| node_instruction_exec
node_instruction_exec -->|"delegates"| node_funcs
node_instruction_exec -->|"manipulates"| node_engine_values
node_instruction_exec -->|"raises"| node_errors
node_funcs -->|"reports"| node_errors
node_engine_values -->|"uses"| node_value_model
node_module_model -->|"provides program"| node_vm
node_build -->|"builds"| node_parser_main
node_build -->|"builds"| node_engine_main
node_build -->|"packages"| node_emscripten_glue
node_emscripten_glue -->|"bridges"| node_vm

click node_parser_main "https://github.com/acmpesuecc/awasme/blob/main/src/parser/main.cpp"
click node_codeparsing "https://github.com/acmpesuecc/awasme/blob/main/src/parser/codeparsing.cpp"
click node_parser_core "https://github.com/acmpesuecc/awasme/blob/main/src/parser/parser.cpp"
click node_parser_types "https://github.com/acmpesuecc/awasme/blob/main/include/parser/types.hpp"
click node_module_model "https://github.com/acmpesuecc/awasme/blob/main/include/module/module.hpp"
click node_instruction_model "https://github.com/acmpesuecc/awasme/blob/main/include/module/instruction.hpp"
click node_value_model "https://github.com/acmpesuecc/awasme/blob/main/include/module/value.hpp"
click node_engine_main "https://github.com/acmpesuecc/awasme/blob/main/src/engine/main.cpp"
click node_vm "https://github.com/acmpesuecc/awasme/blob/main/src/engine/vm.cpp"
click node_instruction_exec "https://github.com/acmpesuecc/awasme/blob/main/src/engine/instruction.cpp"
click node_funcs "https://github.com/acmpesuecc/awasme/blob/main/src/engine/funcs.cpp"
click node_engine_values "https://github.com/acmpesuecc/awasme/blob/main/src/engine/value.cpp"
click node_errors "https://github.com/acmpesuecc/awasme/blob/main/src/engine/errors.cpp"
click node_global_state "https://github.com/acmpesuecc/awasme/blob/main/include/engine/global.hpp"
click node_emscripten_glue "https://github.com/acmpesuecc/awasme/blob/main/index.js"
click node_build "https://github.com/acmpesuecc/awasme/tree/main/Makefile"

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_module_model,node_instruction_model,node_value_model toneBlue
class node_parser_main,node_codeparsing,node_parser_core,node_parser_types toneAmber
class node_engine_main,node_vm,node_instruction_exec,node_funcs,node_engine_values,node_errors,node_global_state toneMint
class node_emscripten_glue,node_build toneRose
class node_wasm_input toneNeutral
```

## Components

### Shared Core

Common WASM module model used by both parsing and execution.

- [Module model](https://github.com/acmpesuecc/awasme/blob/main/include/module/module.hpp): IR · Shared WebAssembly module representation. · `include/module/module.hpp`
- [Instructions](https://github.com/acmpesuecc/awasme/blob/main/include/module/instruction.hpp): IR · Decoded instruction representation shared across the repo. · `include/module/instruction.hpp`
- [Values](https://github.com/acmpesuecc/awasme/blob/main/include/module/value.hpp): IR · Shared value and type model used by parser and engine. · `include/module/value.hpp`

### Parser Path

Binary decoding and module construction pipeline.

- [Parser CLI](https://github.com/acmpesuecc/awasme/blob/main/src/parser/main.cpp): entrypoint · Command-line entry point for parsing a .wasm file. · `src/parser/main.cpp`
- [Code parsing](https://github.com/acmpesuecc/awasme/blob/main/src/parser/codeparsing.cpp): decoder · Low-level section and instruction stream decoding. · `src/parser/codeparsing.cpp`
- [Parser core](https://github.com/acmpesuecc/awasme/blob/main/src/parser/parser.cpp): builder · Higher-level parsing and module assembly logic. · `src/parser/parser.cpp`
- [Parse types](https://github.com/acmpesuecc/awasme/blob/main/include/parser/types.hpp): schema · Parsing-side type definitions and semantic helpers. · `include/parser/types.hpp`

### Engine Path

Interpreter and runtime execution pipeline.

- [Engine CLI](https://github.com/acmpesuecc/awasme/blob/main/src/engine/main.cpp): entrypoint · Standalone interpreter entry point. · `src/engine/main.cpp`
- [VM](https://github.com/acmpesuecc/awasme/blob/main/src/engine/vm.cpp): interpreter · Core execution loop and runtime state coordination. · `src/engine/vm.cpp`
- [Opcode exec](https://github.com/acmpesuecc/awasme/blob/main/src/engine/instruction.cpp): dispatch · Maps decoded instructions to runtime behavior. · `src/engine/instruction.cpp`
- [Functions](https://github.com/acmpesuecc/awasme/blob/main/src/engine/funcs.cpp): runtime · Instruction implementations and host-call support. · `src/engine/funcs.cpp`
- [Value runtime](https://github.com/acmpesuecc/awasme/blob/main/src/engine/value.cpp): runtime · Runtime handling for WASM values and conversions. · `src/engine/value.cpp`
- [Errors](https://github.com/acmpesuecc/awasme/blob/main/src/engine/errors.cpp): faults · Parse and runtime error handling support. · `src/engine/errors.cpp`
- [Globals](https://github.com/acmpesuecc/awasme/blob/main/include/engine/global.hpp): state · Shared runtime globals and configuration. · `include/engine/global.hpp`

### Runtime & Packaging

Entry points and browser build integration.

- [Emscripten glue](https://github.com/acmpesuecc/awasme/blob/main/index.js): bridge · Browser-facing bootstrap for the compiled runtime. · `index.js`
- [Build](https://github.com/acmpesuecc/awasme/tree/main/Makefile): orchestration · Build targets for parser and engine deliverables. · `Makefile`

### Other components

- **WASM binary**: input · Raw WebAssembly bytecode consumed by the parser.

## Connections

- WASM binary → Parser CLI: loads · The CLI receives a WebAssembly binary.
- Parser CLI → Code parsing: invokes · Entry point drives low-level decoding.
- Code parsing → Parser core: decodes into · Binary sections and instructions are assembled into higher-level structures.
- Parser core → Parse types: uses · Parser logic relies on parsing-side semantic types.
- Parser core → Module model: builds · Produces the shared module representation.
- Parser core → Instructions: emits · Decoded instruction data becomes shared IR.
- Parser core → Values: emits · Parser populates shared value/type definitions.
- Module model → Engine CLI: loads · The engine consumes the parsed module representation.
- Engine CLI → VM: starts · Standalone engine initializes the virtual machine.
- VM → Globals: reads · VM uses shared runtime globals and configuration.
- VM → Opcode exec: dispatches · Execution loop sends decoded opcodes to handlers.
- Opcode exec → Functions: delegates · Opcode behavior is implemented by runtime functions.
- Opcode exec → Value runtime: manipulates · Execution depends on runtime value operations.
- Opcode exec → Errors: raises · Execution faults route through centralized error handling.
- Functions → Errors: reports · Function implementations surface runtime failures.
- Value runtime → Values: uses · Runtime values build on the shared value model.
- Module model → VM: provides program · The module model is the program consumed by the interpreter.
- Build → Parser CLI: builds · Makefile produces the parser executable.
- Build → Engine CLI: builds · Makefile produces the engine executable.
- Build → Emscripten glue: packages · Build flow also targets browser-oriented output.
- Emscripten glue → VM: bridges · JavaScript bootstrap connects browser runtime to the engine.
