Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stagas/wat-compiler

webassembly wat text format to binary compiler
https://github.com/stagas/wat-compiler

binary bytecode compiler wabt wasm wat webassembly

Last synced: 6 days ago
JSON representation

webassembly wat text format to binary compiler

Awesome Lists containing this project

README

        

wat-compiler


webassembly wat text format to binary compiler


🔧 Install
· 🧩 Example
· 📜 API docs
· 🔥 Releases
· 💪🏼 Contribute
· 🖐️ Help

***

## Install

```sh
$ npm i wat-compiler
```

## API

#### Table of Contents

* [make](#make)
* [Parameters](#parameters)

### make

[index.js:25-27](https://github.com/stagas/wat-compiler/blob/da299d9672ca3cf692083212afadad27720fd8f1/index.js#L25-L27 "Source code on GitHub")

Compiles a WAT source string to a buffer.

```js
import compile from 'wat-compiler'
const buffer = compile('(func (export "answer") (result i32) (i32.const 42))')
const mod = new WebAssembly.Module(buffer)
const instance = new WebAssembly.Instance(mod)
console.log(instance.exports.answer()) // => 42
```

#### Parameters

* `code` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** The WAT code to compile
* `options` **Options** An options object

* `options.metrics` **[boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)** Enable metrics with console.time
* `context` (optional, default `{}`)

Returns **[Uint8Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array)** The buffer to be passed on to WebAssembly

## Contribute

[Fork](https://github.com/stagas/wat-compiler/fork) or
[edit](https://github.dev/stagas/wat-compiler) and submit a PR.

All contributions are welcome!

## License

Public Domain © 2021
[stagas](https://github.com/stagas)