git ssb


0+

wanderer / wasm-json-toolkit



Branch:

wanderer committed removed uneeded codeLatest: 08c173e on 2/20/2017, 11:57:18 AM
📄.gitmodules
📄.travis.yml
📄README.md
📁bin
📄customSection.js
📁example
📄immediates.json
📄index.js
📄json2wasm.js
📄package.json
📄stream.js
📁test
📄text2json.js
📄wasm2json.js

SYNOPSIS

NPM Package
Build Status
Coverage Status

js-standard-style

A small toolkit for converting wasm binaries into json and back.

INSTALL

npm install wasm-json-toolkit

USAGE

const fs = require('fs')
const wasm2json = require('wasm-json-toolkit').wasm2json

const wasm = fs.readFileSync('./test.wasm')
const json = wasm2json(wasm)

console.log(JSON.stringify(json, null, 2))

CLI

Install -g global for cli usage.

wasm2json [FILE] given a file containing a wasm module produces a json representation
json2wasm [FILE] given a file containing a json representation produces a wasm module

API

wasm2json

./index.js:6-6

converts a wasm binary into a json representation

Parameters

Returns Object

json2wasm

./index.js:13-13

converts a json representation to a wasm binary

Parameters

Returns Buffer

text2json

./index.js:27-27

converts text to json. The only text accepted is a simple list of opcode name and immediates

Parameters

Examples

const codeStr = `
i64.const 1
i64.const 2
i64.add
`
const json = text2json(codeStr)

Returns Object

exammple json output

wast

(module
  (func $addTwo (param i32 i32) (result i32)
    (i32.add
      (get_local 0)
      (get_local 1)))
  (export "addTwo" (func $addTwo)))

wasm

0x010661646454776f00000a09010700200020016a0b

json

[
  {
    "name": "preramble",
    "magic": [0,97,115,109],
    "version": [13,0,0,0]
  },
  {
    "name": "type",
    "entries": [
      {
        "form": "func",
        "params": ["i32","i32"],
        "return_type": "i32"
      }
    ]
  },
  {
    "name": "function",
    "entries": [0]
  },
  {
    "name": "export",
    "entries": [
      {
        "field_str": "addTwo",
        "kind": "Function",
        "index": 0
      }
    ]
  },
  {
    "name": "code",
    "entries": [
      {
        "locals": [],
        "code": [
          {
            "name": "get_local",
            "immediaties": "0"
          },
          {
            "name": "get_local",
            "immediaties": "1"
          },
          {
            "return_type": "i32",
            "name": "add"
          },
          {
            "name": "end"
          }
        ]
      }
    ]
  }
]

LICENSE

MPL-2.0)


Built with git-ssb-web