binaryen.js
===========
**binaryen.js** is a port of [Binaryen](https://github.com/WebAssembly/binaryen) to the Web, allowing you to generate [WebAssembly](https://webassembly.org) using a JavaScript API.
<a href="https://github.com/AssemblyScript/binaryen.js/actions?query=workflow%3ABuild"><img src="https://img.shields.io/github/workflow/status/AssemblyScript/binaryen.js/Build/main?label=build&logo=github" alt="Build status" /></a>
<a href="https://www.npmjs.com/package/binaryen"><img src="https://img.shields.io/npm/v/binaryen.svg?label=latest&color=007acc&logo=npm" alt="npm version" /></a>
<a href="https://www.npmjs.com/package/binaryen"><img src="https://img.shields.io/npm/v/binaryen/nightly.svg?label=nightly&color=007acc&logo=npm" alt="npm nightly version" /></a>
Usage
-----
```
$> npm install binaryen
```
```js
import binaryen from "binaryen";
// Create a module with a single function
var myModule = new binaryen.Module();
myModule.addFunction("add", binaryen.createType([ binaryen.i32, binaryen.i32 ]), binaryen.i32, [ binaryen.i32 ],
myModule.block(null, [
myModule.local.set(2,
myModule.i32.add(
myModule.local.get(0, binaryen.i32),
myModule.local.get(1, binaryen.i32)
)
),
myModule.return(
myModule.local.get(2, binaryen.i32)
)
])
);
myModule.addFunctionExport("add", "add");
// Optimize the module using default passes and levels
myModule.optimize();
// Validate the module
if (!myModule.validate())
throw new Error("validation error");
// Generate text format and binary
var textData = myModule.emitText();
var wasmData = myModule.emitBinary();
// Example usage with the WebAssembly API
var compiled = new WebAssembly.Module(wasmData);
var instance = new WebAssembly.Instance(compiled, {});
console.log(instance.exports.add(41, 1));
```
The buildbot also publishes nightly versions once a day if there have been changes. The latest nightly can be installed through
```
$> npm install binaryen@nightly
```
or you can use one of the [previous versions](https://github.com/AssemblyScript/binaryen.js/tags) instead if necessary.
### Usage with a CDN
* From GitHub via [jsDelivr](https://www.jsdelivr.com):<br />
`https://cdn.jsdelivr.net/gh/AssemblyScript/binaryen.js@VERSION/index.js`
* From npm via [jsDelivr](https://www.jsdelivr.com):<br />
`https://cdn.jsdelivr.net/npm/binaryen@VERSION/index.js`
* From npm via [unpkg](https://unpkg.com):<br />
`https://unpkg.com/binaryen@VERSION/index.js`
Replace `VERSION` with a [specific version](https://github.com/AssemblyScript/binaryen.js/releases) or omit it (not recommended in production) to use main/latest.
### Command line
The package includes Node.js builds of [wasm-opt](https://github.com/WebAssembly/binaryen#wasm-opt) and [wasm2js](https://github.com/WebAssembly/binaryen#wasm2js).
API
---
**Please note** that the Binaryen API is evolving fast and that definitions and documentation provided by the package tend to get out of sync despite our best efforts. It's a bot after all. If you rely on binaryen.js and spot an issue, please consider sending a PR our way by updating [index.d.ts](./index.d.ts) and [README.md](./README.md) to reflect the [current API](https://github.com/WebAssembly/binaryen/blob/main/src/js/binaryen.js-post.js).
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
### Contents
- [Types](#types)
- [Module construction](#module-construction)
- [Module manipulation](#module-manipulation)
- [Module validation](#module-validation)
- [Module optimization](#module-optimization)
- [Module creation](#module-creation)
- [Expression construction](#expression-construction)
- [Control flow](#control-flow)
- [Variable accesses](#variable-accesses)
- [Integer operations](#integer-operations)
- [Floating point operations](#floating-point-operations)
- [Datatype conversions](#datatype-conversions)
- [Function calls](#function-calls)
- [Linear memory accesses](#linear-memory-accesses)
- [Host operations](#host-operations)
- [Vector operations ð¦](#vector-operations-)
- [Atomic memory accesses ð¦](#atomic-memory-accesses-)
- [Atomic read-modify-write operations ð¦](#atomic-read-modify-write-operations-)
- [Atomic wait and notify operations ð¦](#atomic-wait-and-notify-operations-)
- [Sign extension operations ð¦](#sign-extension-operations-)
- [Multi-value operations ð¦](#multi-value-operations-)
- [Exception handling operations ð¦](#exception-handling-operations-)
- [Reference types operations ð¦](#reference-types-operations-)
- [Bulk memory operations ð¦](#bulk-memory-operations-)
- [Expression manipulation](#expression-manipulation)
- [Relooper](#relooper)
- [Source maps](#source-maps)
- [Debugging](#debugging)
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
[Future features](http://webassembly.org/docs/future-features/) ð¦ might not be supported by all runtimes.
### Types
* **none**: `Type`<br />
The none type, e.g., `void`.
* **i32**: `Type`<br />
32-bit integer type.
* **i64**: `Type`<br />
64-bit integer type.
* **f32**: `Type`<br />
32-bit float type.
* **f64**: `Type`<br />
64-bit float (double) type.
* **v128**: `Type`<br />
128-bit vector type. ð¦
* **funcref**: `Type`<br />
A function reference. ð¦
* **anyref**: `Type`<br />
Any host reference. ð¦
* **nullref**: `Type`<br />
A null reference. ð¦
* **exnref**: `Type`<br />
An exception reference. ð¦
* **unreachable**: `Type`<br />
Special type indicating unreachable code when obtaining information about an expression.
* **auto**: `Type`<br />
Special type used in **Module#block** exclusively. Lets the API figure out a block's result type automatically.
* **createType**(types: `Type[]`): `Type`<br />
Creates a multi-value type from an array of types.
* **expandType**(type: `Type`): `Type[]`<br />
Expands a multi-value type to an array of types.
### Module construction
* new **Module**()<br />
Constructs a new module.
* **parseText**(text: `string`): `Module`<br />
Creates a module from Binaryen's s-expression text format (not official stack-style text format).
* **readBinary**(data: `Uint8Array`): `Module`<br />
Creates a module from binary data.
### Module manipulation
* Module#**addFunction**(name: `string`, params: `Type`, results: `Type`, vars: `Type[]`, body: `ExpressionRef`): `FunctionRef`<br />
Adds a function. `vars` indicate additional locals, in the given order.
* Module#**getFunction**(name: `string`): `FunctionRef`<br />
Gets a function, by name,
* Module#**removeFunction**(name: `string`): `void`<br />
Removes a function, by name.
* Module#**getNumFunctions**(): `number`<br />
Gets the number of functions within the module.
* Module#**getFunctionByIndex**(index: `number`): `FunctionRef`<br />
Gets the function at the specified index.
* Module#**addFunctionImport**(internalName: `string`, externalModuleName: `string`, externalBaseName: `string`, params: `Type`, results: `Type`): `void`<br />
Adds a function import.
* Module#**addTableImport**(internalName: `string`, externalModuleName: `string`, externalBaseName: `string`): `void`<br />
Adds a table import. There's just one table for now, using name `"0"`.
* Module#**addMemoryImport**(internalName: `string`, externalModuleName: `string`, externalBaseName: `string`): `void`<br />
Adds a memory import. There's just one memory for now, using name `"0"`.
* Module#**addGlobalImport**(internalName: `string`, externalModuleName: `string`, externalBaseName: `string`, globalType: `Type`): `void`<br />
Adds a glob
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Unity WebGL 微信小游戏适配方案 (2000个子文件)
libxlua.a 2.45MB
UnityWebSocket.Editor.asmdef 365B
UnityWebSocket.Runtime.asmdef 306B
LightProbes.asset 536KB
NavMesh.asset 103KB
ProjectSettings.asset 20KB
ProjectSettings.asset 19KB
ProjectSettings.asset 18KB
QualitySettings.asset 7KB
InputManager.asset 6KB
InputManager.asset 6KB
InputManager.asset 6KB
QualitySettings.asset 5KB
QualitySettings.asset 4KB
GraphicsSettings.asset 2KB
GraphicsSettings.asset 2KB
Physics2DSettings.asset 2KB
GraphicsSettings.asset 2KB
EditorBuildSettings.asset 1KB
Physics2DSettings.asset 1KB
NavMeshAreas.asset 1KB
EditorSettings.asset 1KB
DynamicsManager.asset 1KB
NavMeshAreas.asset 1KB
EditorSettings.asset 1KB
MemorySettings.asset 1KB
MemorySettings.asset 1KB
MemorySettings.asset 1KB
EditorSettings.asset 1KB
DynamicsManager.asset 1KB
UnityConnectSettings.asset 1005B
UnityConnectSettings.asset 1002B
PackageManagerSettings.asset 927B
PackageManagerSettings.asset 927B
NavMeshAreas.asset 884B
UnityConnectSettings.asset 872B
PackageManagerSettings.asset 862B
Physics2DSettings.asset 854B
EditorUserSettings.asset 745B
DynamicsManager.asset 658B
AudioManager.asset 443B
TagManager.asset 392B
VFXManager.asset 387B
AutoStreamingSettings.asset 379B
AutoStreamingSettings.asset 379B
TagManager.asset 378B
TagManager.asset 378B
AudioManager.asset 357B
AutoStreamingSettings.asset 317B
AudioManager.asset 279B
EditorBuildSettings.asset 277B
VFXManager.asset 273B
VFXManager.asset 273B
TimeManager.asset 202B
TimeManager.asset 202B
VersionControlSettings.asset 188B
VersionControlSettings.asset 188B
VersionControlSettings.asset 188B
TimeManager.asset 175B
EditorBuildSettings.asset 160B
XRSettings.asset 158B
XRSettings.asset 158B
NetworkManager.asset 151B
NetworkManager.asset 151B
PresetManager.asset 146B
UPRSettings.asset 140B
UPRSettings.asset 140B
PresetManager.asset 120B
PresetManager.asset 120B
ClusterInputManager.asset 114B
ClusterInputManager.asset 114B
ClusterInputManager.asset 114B
build.bat 873B
signatured1.lua.bytes 200B
signatured3.lua.bytes 177B
signatured2.lua.bytes 177B
simpledlmalloc.c 229KB
tolua.c 68KB
lpeg.c 63KB
lstrlib.c 46KB
lparser.c 45KB
lvm.c 43KB
lua_cjson.c 41KB
lparser.c 36KB
lparser.c 36KB
lgc.c 36KB
lcode.c 34KB
lapi.c 31KB
lauxlib.c 30KB
lauxlib.c 30KB
xlua.c 30KB
ldo.c 25KB
loadlib.c 23KB
lstrlib.c 23KB
lstrlib.c 23KB
lvm.c 23KB
lvm.c 23KB
lapi.c 22KB
lapi.c 22KB
lcode.c 21KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 6723
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功