How acmpesuecc/awasme works
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: parser.cpp Parser core · vm.cpp VM · instruction.cpp Opcode exec · Makefile Build
Components 17
Shared Core
Common WASM module model used by both parsing and execution.
- Module model · Shared WebAssembly module representation.
include/module/module.hpp - Instructions · Decoded instruction representation shared across the repo.
include/module/instruction.hpp - Values · Shared value and type model used by parser and engine.
include/module/value.hpp
Parser Path
Binary decoding and module construction pipeline.
- Parser CLI · Command-line entry point for parsing a .wasm file.
src/parser/main.cpp - Code parsing · Low-level section and instruction stream decoding.
src/parser/codeparsing.cpp - Parser core · Higher-level parsing and module assembly logic.
src/parser/parser.cpp - Parse types · Parsing-side type definitions and semantic helpers.
include/parser/types.hpp
Engine Path
Interpreter and runtime execution pipeline.
- Engine CLI · Standalone interpreter entry point.
src/engine/main.cpp - VM · Core execution loop and runtime state coordination.
src/engine/vm.cpp - Opcode exec · Maps decoded instructions to runtime behavior.
src/engine/instruction.cpp - Functions · Instruction implementations and host-call support.
src/engine/funcs.cpp - Value runtime · Runtime handling for WASM values and conversions.
src/engine/value.cpp - Errors · Parse and runtime error handling support.
src/engine/errors.cpp - Globals · Shared runtime globals and configuration.
include/engine/global.hpp
Runtime & Packaging
Entry points and browser build integration.
- Emscripten glue · Browser-facing bootstrap for the compiled runtime.
index.js - Build · Build targets for parser and engine deliverables.
Makefile
Other components
- WASM binary · Raw WebAssembly bytecode consumed by the parser.
Connections 21
- 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.