source: trip-planner-front/node_modules/@webassemblyjs/wasm-edit/README.md@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1# @webassemblyjs/wasm-edit
2
3> Rewrite a WASM binary
4
5Replace in-place an AST node in the binary.
6
7## Installation
8
9```sh
10yarn add @webassemblyjs/wasm-edit
11```
12
13## Usage
14
15Update:
16
17```js
18import { edit } from "@webassemblyjs/wasm-edit";
19
20const binary = [/*...*/];
21
22const visitors = {
23 ModuleImport({ node }) {
24 node.module = "foo";
25 node.name = "bar";
26 }
27};
28
29const newBinary = edit(binary, visitors);
30```
31
32Replace:
33
34```js
35import { edit } from "@webassemblyjs/wasm-edit";
36
37const binary = [/*...*/];
38
39const visitors = {
40 Instr(path) {
41 const newNode = t.callInstruction(t.indexLiteral(0));
42 path.replaceWith(newNode);
43 }
44};
45
46const newBinary = edit(binary, visitors);
47```
48
49Remove:
50
51```js
52import { edit } from "@webassemblyjs/wasm-edit";
53
54const binary = [/*...*/];
55
56const visitors = {
57 ModuleExport({ node }) {
58 path.remove()
59 }
60};
61
62const newBinary = edit(binary, visitors);
63```
64
65Insert:
66
67```js
68import { add } from "@webassemblyjs/wasm-edit";
69
70const binary = [/*...*/];
71
72const newBinary = add(actualBinary, [
73 t.moduleImport("env", "mem", t.memory(t.limit(1)))
74]);
75```
76
77## Providing the AST
78
79Providing an AST allows you to handle the decoding yourself, here is the API:
80
81```js
82addWithAST(Program, ArrayBuffer, Array<Node>): ArrayBuffer;
83editWithAST(Program, ArrayBuffer, visitors): ArrayBuffer;
84```
85
86Note that the AST will be updated in-place.
Note: See TracBrowser for help on using the repository browser.