# webassembly/wabt architecture

> Architecture diagram of the GitHub repository webassembly/wabt, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/webassembly/wabt
- Repository: https://github.com/webassembly/wabt

## Overview

##### Main Components and Architecture

- Binary Processing Layer
- Components from include/wabt/binary-*.h
- Handles WebAssembly binary format parsing/generation
- IR (Intermediate Representation) Layer
- Based on include/wabt/ir.h
- Central data structure for WebAssembly representation
- Validation Layer
- Validator and type-checker components
- Based on include/wabt/validator.h and type-checker.h

b) Tool Layer (Surrounding the core):
Main tools in a circular pattern around the core:
- wat2wasm: Text to binary converter
- wasm2wat: Binary to text converter
- wasm-objdump: Binary analysis tool
- wasm-interp: Interpreter
- wasm-decompile: Decompiler
- wasm2c: WebAssembly to C converter
- Additional tools (wasm-strip, wasm-validate, etc.)

##### Data Flow Representation

- Blue: Text processing
- Green: Binary processing
- Orange: Validation/Analysis
- Purple: Interpretation/Execution

##### Shared Infrastructure

- Lexer/Parser (include/wabt/wast-lexer.h, wast-parser.h)
- Error Handling (include/wabt/error-formatter.h)
- Stream Handling (include/wabt/stream.h)
- Common Utilities (include/wabt/common.h)

##### Feature Support Layer

A section showing supported WebAssembly proposals:
- Exception Handling
- SIMD
- Reference Types
- Bulk Memory
- Threading
- etc.

##### Integration Points

External integration points:
- JavaScript/Emscripten integration (for web demos)
- Test Framework integration
- C API for tool integration

##### Detailed Component Breakdown

For each major tool, show internal components:
- Input Processing
- Feature-specific Processing
- Output Generation
- Error Handling
- Validation Steps

##### Implementation Notes

Notes for important implementation details:
- C++ based implementation
- CMake build system
- Cross-platform support
- Test suite integration

- Modular design with shared core components
- Clear separation between text and binary processing
- Extensive validation and error handling
- Feature toggle support
- Tool independence with shared infrastructure

This design captures WABT's nature as a comprehensive WebAssembly toolkit while showing how individual tools interact with shared components and maintain spec compliance.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Core Components
    subgraph Core
        IR["IR Layer"]:::core
        BinaryProc["Binary Processing Layer"]:::core
        Validation["Validation Layer"]:::core
        
        IR <--> BinaryProc
        IR <--> Validation
        BinaryProc <--> Validation
    end

    %% Shared Infrastructure
    subgraph Infrastructure
        Lexer["Lexer/Parser"]:::infra
        ErrorHandle["Error Handling"]:::infra
        Stream["Stream Handling"]:::infra
        Common["Common Utilities"]:::infra
        TypeSystem["Type System"]:::infra
        Names["Name Resolution"]:::infra
    end

    %% Tools Layer
    subgraph Tools
        wat2wasm["wat2wasm"]:::tool
        wasm2wat["wasm2wat"]:::tool
        wasmobjdump["wasm-objdump"]:::tool
        wasminterp["wasm-interp"]:::tool
        wasmdecomp["wasm-decompile"]:::tool
        wasm2c["wasm2c"]:::tool
    end

    %% Feature Support
    subgraph Features
        direction TB
        FeatureSupport["Feature Support"]:::feature
        ExceptionHandling["Exception Handling"]:::feature
        SIMD["SIMD"]:::feature
        RefTypes["Reference Types"]:::feature
        BulkMem["Bulk Memory"]:::feature
        Threading["Threading"]:::feature
    end

    %% Connections
    Core --> Tools
    Infrastructure --> Core
    Features --> Core
    
    %% Tool Specific Flows
    wat2wasm --> IR
    IR --> wasm2wat
    BinaryProc --> wasmobjdump
    IR --> wasminterp
    IR --> wasmdecomp
    IR --> wasm2c

    %% Legend
    classDef core fill:#f9f,stroke:#333,stroke-width:2px
    classDef infra fill:#bbf,stroke:#333
    classDef tool fill:#bfb,stroke:#333
    classDef feature fill:#ffb,stroke:#333

    %% Click Events
    click IR "https://github.com/webassembly/wabt/blob/main/include/wabt/ir.h"
    click BinaryProc "https://github.com/webassembly/wabt/blob/main/include/wabt/binary.h"
    click Validation "https://github.com/webassembly/wabt/blob/main/include/wabt/validator.h"
    click Lexer "https://github.com/webassembly/wabt/blob/main/include/wabt/wast-lexer.h"
    click ErrorHandle "https://github.com/webassembly/wabt/blob/main/include/wabt/error-formatter.h"
    click Stream "https://github.com/webassembly/wabt/blob/main/include/wabt/stream.h"
    click Common "https://github.com/webassembly/wabt/blob/main/include/wabt/common.h"
    click TypeSystem "https://github.com/webassembly/wabt/blob/main/include/wabt/type.h"
    click Names "https://github.com/webassembly/wabt/blob/main/include/wabt/resolve-names.h"
    click wat2wasm "https://github.com/webassembly/wabt/blob/main/src/tools/wat2wasm.cc"
    click wasm2wat "https://github.com/webassembly/wabt/blob/main/src/tools/wasm2wat.cc"
    click wasmobjdump "https://github.com/webassembly/wabt/blob/main/src/tools/wasm-objdump.cc"
    click wasminterp "https://github.com/webassembly/wabt/blob/main/src/tools/wasm-interp.cc"
    click wasmdecomp "https://github.com/webassembly/wabt/blob/main/src/tools/wasm-decompile.cc"
    click wasm2c "https://github.com/webassembly/wabt/blob/main/src/tools/wasm2c.cc"
    click FeatureSupport "https://github.com/webassembly/wabt/blob/main/include/wabt/feature.h"
```
