GitXplorerGitXplorer
w

wassemble

public
8 stars
0 forks
1 issues

Commits

List of commits on branch master.
Unverified
918b01439878984323a71ffe561b50b93db49bef

Fix encoding of local.get

wwingo committed 5 years ago
Unverified
9f5164a7bb79739d3f76c104314aca53fb081c39

Fix bugs

wwingo committed 5 years ago
Unverified
a412b3ae98618463d23ed958890f16a607b1261a

Add a brief usage section

wwingo committed 5 years ago
Unverified
38f856763f45c638e2968a08f5f31c1f964028aa

Remove a debug print

wwingo committed 5 years ago
Unverified
3a3ff331d6d123005074ea7c2743a51e6a55b494

Minor tweaks

wwingo committed 5 years ago
Unverified
0ca8f0a3a952ec494b596237133e9b00f03a9e79

Update package.json

wwingo committed 5 years ago

README

The README file for this repository.

wassemble

wassemble is a JavaScript tool to convert WebAssembly standard textual format (wat) to binary (wasm). It is a single file of JavaScript with no dependencies.

Note, wabt is a more full-featured toolkit for working with WebAssembly, both in textual and binary formats, and includes a tool called wat2wasm. However sometimes you just want a simple JS file to drop into your projects; that's what wassemble is about. You could think of it as a clone of wabt's wat2wasm, but built in a different way.

Differences from wabt

Unlike wat2wasm, wassemble does minimal error-checking. Notably, it doesn't type-check the module; it assumes the WebAssembly implementation will signal any validation-time errors when the module is instantiated. As such, this tool is most useful for compiling known-valid wat files, or for generating known-invalid modules for fuzzing or testing purposes.

Install

npm install wassemble

As this project has no dependencies, alternately you can just drop wassemble.mjs anywhere in your project tree.

Usage

Assuming you installed via NPM, this code compiles a WebAssembly add function, synchronously instantiates it, and adds a couple numbers:

import wassemble from 'wassemble/wassemble.mjs';

let bytes = wassemble(`
  (module
    (func $add (export "add") (param i32 i32) (result i32)
      (i32.add (local.get 0) (local.get 1))))`)

let mod = new WebAssembly.Instance(new WebAssembly.Module(bytes));

console.log(mod.exports.add(10, 32));

Of course it's better to use WebAssembly.instantiate if possible.

License

wassemble is available under the Blue Oak Model License, version 1.0.0. See LICENSE.md for full details.