Code Monkey home page Code Monkey logo

wabt.js's Introduction

wabt.js

wabt.js is a port of WABT to the Web, allowing you to manipulate WebAssembly modules using a JavaScript API.

Build status npm version npm nightly version

Usage

$> npm install wabt
require("wabt")().then(wabt => {
  var wasm = ...; // a buffer holding the contents of a wasm file

  var myModule = wabt.readWasm(wasm, { readDebugNames: true });
  myModule.applyNames();

  var wast = myModule.toText({ foldExprs: false, inlineExport: false });

  console.log(wast);
});

The buildbot also publishes nightly versions once a day if there have been changes. The latest nightly can be installed through

$> npm install --save-exact wabt@nightly

or you can use one of the previous versions instead if necessary. Note the --save-exact when using a nightly.

Usage with a CDN

  • From GitHub via jsDelivr:
    https://cdn.jsdelivr.net/gh/AssemblyScript/wabt.js@VERSION/index.js
  • From npm via jsDelivr:
    https://cdn.jsdelivr.net/npm/wabt@VERSION/index.js
  • From npm via UNPKG:
    https://unpkg.com/wabt@VERSION/index.js

Replace VERSION with a specific version or omit it (not recommended in production) to use master/latest.

API

  • parseWat(filename: string, buffer: string | Uint8Array, options?: WasmFeatures): WasmModule
    Parses a WebAssembly text format source to a module.

  • readWasm(buffer: Uint8Array, options: ReadWasmOptions & WasmFeatures): WasmModule
    Reads a WebAssembly binary to a module.

  • WasmModule
    A class representing a WebAssembly module.

    • validate(): void
      Validates the module. Throws if not valid.
    • resolveNames(): void
      Resolves names to indexes.
    • generateNames(): void
      Generates textual names for function types, globals, labels etc.
    • applyNames(): void
      Applies textual names. Throws on error.
    • toText(options: ToTextOptions): string
      Converts the module to wat text format.
    • toBinary(options: ToBinaryOptions): ToBinaryResult
      Converts the module to a wasm binary.
    • destroy(): void
      Disposes the module and frees its resources.
  • ReadWasmOptions
    Options modifying the behavior of readWasm.

    • readDebugNames: boolean
      Reads textual names from the name section.
  • ToTextOptions
    Options modifying the behavior of WasmModule#toText.

    • foldExprs: boolean
    • inlineExport: boolean
  • ToBinaryOptions
    Options modifying the behavior of WasmModule#toBinary.

    • log: boolean
    • canonicalize_lebs: boolean
    • relocatable: boolean
    • write_debug_names: boolean
  • ToBinaryResult
    Result object of WasmModule#toBinary.

    • buffer: Uint8Array
      The wasm binary buffer.
    • log: string
      Generated log output.
  • WasmFeatures
    Post-MVP WebAssembly features to legalize.

    • exceptions: boolean
      Exception handling (proposal).
    • mutable_globals: boolean
      Import/Export mutable globals (proposal).
    • sat_float_to_int: boolean
      Non-trapping Float-to-int Conversions (proposal).
    • sign_extension: boolean
      Sign-extension operators (proposal).
    • simd: boolean
      128-bit packed SIMD (proposal).
    • threads: boolean
      Threading (proposal).
    • multi_value: boolean
      Multi-value (proposal).
    • tail_call: boolean
      Tail Call (proposal).
    • bulk_memory: boolean
      Bulk Memory Operations and Conditional Segment Initialization (proposal).
    • reference_types: boolean
      Reference Types (proposal).
    • annotations: boolean
      Custom Annotation Syntax for the Wasm Text Format (proposal).
    • gc: boolean
      Garbage collection (proposal).

CLI

Node.js ports of the following command line tools are included in the package as well:

  • wasm2c converts a WebAssembly binary file to a C source and header.
  • wasm2wat translates from WebAssembly binary format to text format.
  • wat2wasm translates from WebAssembly text format to binary format.
  • wasm-decompile decompiles a wasm binary into readable C-like syntax.
  • wasm-interp decodes and runs a WebAssembly binary file using a stack-based interpreter.
  • wasm-objdump prints information about a wasm binary. Similiar to objdump.
  • wasm-opcodecnt counts opcode usage for instructions.
  • wasm-strip removes sections of a WebAssembly binary file.
  • wasm-validate validates a file in WebAssembly binary format.

The tools can also be run ad hoc (without explicitly installing the package), for example with:

$> npx -p wabt wasm2wat myModule.wasm -o myModule.wat

wabt.js's People

Contributors

actions-user avatar dcodeio avatar sharpiro avatar syrusakbary avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.