Skip to main content

Crate wasi_assembler

Crate wasi_assembler 

Source
Expand description

Β§WASI Assembler

A comprehensive toolchain for WebAssembly (Wasm) and the WebAssembly System Interface (WASI), supporting both binary .wasm and text .wat formats.

Β§πŸ›οΈ Architecture

graph TB
    subgraph "Wasm/WASI Toolchain"
        A[Wasm/WAT Source] --> B[WASI Program Model]
        B --> C[Section Builder]
        C --> D[Instruction Encoder]
        D --> E[Wasm Binary (.wasm)]
        
        subgraph "Section Types"
            F[Type / Import / Function]
            G[Memory / Global / Export]
            H[Code / Data / Custom]
        end
        
        C --> F
        C --> G
        C --> H
    end

Β§πŸš€ Features

Β§Core Capabilities

  • Dual Format Support: Full support for reading and writing both binary .wasm files and text-based .wat representations.
  • Component Model: (🚧) Experimental support for the Wasm Component Model, including component, core module, and alias definitions.
  • Instruction Set: Comprehensive coverage of standard WebAssembly instructions, including numeric, control flow, and memory operations.

Β§Advanced Features

  • WASI Integration: Built-in support for defining WASI-specific imports and exports (e.g., wasi_snapshot_preview1).
  • Section Management: Automatic layout and encoding of all standard Wasm sections, plus support for custom sections (e.g., for debugging).
  • Validation: Includes a basic validator to ensure generated modules adhere to the WebAssembly specification.

Β§πŸ’» Usage

Β§Assembling WAT to WASM

The following example demonstrates how to parse a WAT string and compile it into a WASM binary.

use wasi_assembler::WasiAssembler;
use std::fs;

fn main() {
    let wat_source = r#"
        (module
            (func $add (param $lhs i32) (param $rhs i32) (result i32)
                local.get $lhs
                local.get $rhs
                i32.add)
            (export "add" (func $add))
        )
    "#;

    let assembler = WasiAssembler::new();
    let binary = assembler.assemble_from_str(wat_source).expect("Failed to assemble WAT");

    fs::write("add.wasm", binary).unwrap();
    println!("Generated add.wasm");
}

Β§πŸ› οΈ Support Status

FeatureSupport LevelSpecification
Core Wasm (MVP)βœ… FullWasm 1.0
WAT Text Formatβœ… FullWasm 1.0
WASI Preview 1βœ… FullSnapshot Preview 1
Component Model🚧 PartialPhase 4 (Draft)
SIMD / Atomics🚧 PartialPost-MVP

Legend: βœ… Supported, 🚧 In Progress, ❌ Not Supported

Β§πŸ”— Relations

  • gaia-types: Uses BinaryWriter and LEB128 encoding utilities for compact Wasm binary generation.
  • gaia-assembler: Acts as the primary WebAssembly backend for the Gaia project, enabling execution in browsers and WASI runtimes.

Re-exportsΒ§

pub use formats::wat;
pub use program::WasiAlias;
pub use program::WasiAliasTarget;
pub use program::WasiCanonicalOperation;
pub use program::WasiComponentItem;
pub use program::WasiCoreFunc;
pub use program::WasiCoreInstance;
pub use program::WasiCoreModule;
pub use program::WasiCoreType;
pub use program::WasiCustomSection;
pub use program::WasiDataSegment;
pub use program::WasiElementSegment;
pub use program::WasiExport;
pub use program::WasiFunction;
pub use program::WasiFunctionType;
pub use program::WasiGlobal;
pub use program::WasiImport;
pub use program::WasiInstance;
pub use program::WasiInstanceArg;
pub use program::WasiInstanceType;
pub use program::WasiInstruction;
pub use program::WasiMemory;
pub use program::WasiPrimitiveType;
pub use program::WasiProgram;
pub use program::WasiProgramBuilder;
pub use program::WasiProgramType;
pub use program::WasiRecordField;
pub use program::WasiResourceMethod;
pub use program::WasiResourceType;
pub use program::WasiSymbol;
pub use program::WasiSymbolType;
pub use program::WasiTable;
pub use program::WasiType;
pub use program::WasiTypeDefinition;
pub use program::WasiVariantCase;
pub use program::WasmExportType;
pub use program::WasmGlobalType;
pub use program::WasmImportType;
pub use program::WasmInfo;
pub use program::WasmLocal;
pub use program::WasmMemoryType;
pub use program::WasmReferenceType;
pub use program::WasmTableType;
pub use program::WasmValueType;

ModulesΒ§

formats
WASI 汇编器 - 格式倄理樑块
helpers
θΎ…εŠ©ε·₯具樑块
program
WASM η¨‹εΊι«˜ε±‚ζ¬‘ζŠ½θ±‘

StructsΒ§

WasiAssembler
WASI 汇编器

EnumsΒ§

WasiError
WASI ι”™θ――η±»εž‹