1 | # @webassemblyjs/ast
|
---|
2 |
|
---|
3 | > AST utils for webassemblyjs
|
---|
4 |
|
---|
5 | ## Installation
|
---|
6 |
|
---|
7 | ```sh
|
---|
8 | yarn add @webassemblyjs/ast
|
---|
9 | ```
|
---|
10 |
|
---|
11 | ## Usage
|
---|
12 |
|
---|
13 | ### Traverse
|
---|
14 |
|
---|
15 | ```js
|
---|
16 | import { traverse } from "@webassemblyjs/ast";
|
---|
17 |
|
---|
18 | traverse(ast, {
|
---|
19 | Module(path) {
|
---|
20 | console.log(path.node);
|
---|
21 | }
|
---|
22 | });
|
---|
23 | ```
|
---|
24 |
|
---|
25 | ### Instruction signatures
|
---|
26 |
|
---|
27 | ```js
|
---|
28 | import { signatures } from "@webassemblyjs/ast";
|
---|
29 |
|
---|
30 | console.log(signatures);
|
---|
31 | ```
|
---|
32 |
|
---|
33 | ### Path methods
|
---|
34 |
|
---|
35 | - `findParent: NodeLocator`
|
---|
36 | - `replaceWith: Node => void`
|
---|
37 | - `remove: () => void`
|
---|
38 | - `insertBefore: Node => void`
|
---|
39 | - `insertAfter: Node => void`
|
---|
40 | - `stop: () => void`
|
---|
41 |
|
---|
42 | ### AST utils
|
---|
43 |
|
---|
44 | - function `module(id, fields, metadata)`
|
---|
45 | - function `moduleMetadata(sections, functionNames, localNames)`
|
---|
46 | - function `moduleNameMetadata(value)`
|
---|
47 | - function `functionNameMetadata(value, index)`
|
---|
48 | - function `localNameMetadata(value, localIndex, functionIndex)`
|
---|
49 | - function `binaryModule(id, blob)`
|
---|
50 | - function `quoteModule(id, string)`
|
---|
51 | - function `sectionMetadata(section, startOffset, size, vectorOfSize)`
|
---|
52 | - function `loopInstruction(label, resulttype, instr)`
|
---|
53 | - function `instruction(id, args, namedArgs)`
|
---|
54 | - function `objectInstruction(id, object, args, namedArgs)`
|
---|
55 | - function `ifInstruction(testLabel, test, result, consequent, alternate)`
|
---|
56 | - function `stringLiteral(value)`
|
---|
57 | - function `numberLiteralFromRaw(value, raw)`
|
---|
58 | - function `longNumberLiteral(value, raw)`
|
---|
59 | - function `floatLiteral(value, nan, inf, raw)`
|
---|
60 | - function `elem(table, offset, funcs)`
|
---|
61 | - function `indexInFuncSection(index)`
|
---|
62 | - function `valtypeLiteral(name)`
|
---|
63 | - function `typeInstruction(id, functype)`
|
---|
64 | - function `start(index)`
|
---|
65 | - function `globalType(valtype, mutability)`
|
---|
66 | - function `leadingComment(value)`
|
---|
67 | - function `blockComment(value)`
|
---|
68 | - function `data(memoryIndex, offset, init)`
|
---|
69 | - function `global(globalType, init, name)`
|
---|
70 | - function `table(elementType, limits, name, elements)`
|
---|
71 | - function `memory(limits, id)`
|
---|
72 | - function `funcImportDescr(id, signature)`
|
---|
73 | - function `moduleImport(module, name, descr)`
|
---|
74 | - function `moduleExportDescr(exportType, id)`
|
---|
75 | - function `moduleExport(name, descr)`
|
---|
76 | - function `limit(min, max)`
|
---|
77 | - function `signature(params, results)`
|
---|
78 | - function `program(body)`
|
---|
79 | - function `identifier(value, raw)`
|
---|
80 | - function `blockInstruction(label, instr, result)`
|
---|
81 | - function `callInstruction(index, instrArgs)`
|
---|
82 | - function `callIndirectInstruction(signature, intrs)`
|
---|
83 | - function `byteArray(values)`
|
---|
84 | - function `func(name, signature, body, isExternal, metadata)`
|
---|
85 | - Constant`isModule`
|
---|
86 | - Constant`isModuleMetadata`
|
---|
87 | - Constant`isModuleNameMetadata`
|
---|
88 | - Constant`isFunctionNameMetadata`
|
---|
89 | - Constant`isLocalNameMetadata`
|
---|
90 | - Constant`isBinaryModule`
|
---|
91 | - Constant`isQuoteModule`
|
---|
92 | - Constant`isSectionMetadata`
|
---|
93 | - Constant`isLoopInstruction`
|
---|
94 | - Constant`isInstruction`
|
---|
95 | - Constant`isObjectInstruction`
|
---|
96 | - Constant`isIfInstruction`
|
---|
97 | - Constant`isStringLiteral`
|
---|
98 | - Constant`isNumberLiteral`
|
---|
99 | - Constant`isLongNumberLiteral`
|
---|
100 | - Constant`isFloatLiteral`
|
---|
101 | - Constant`isElem`
|
---|
102 | - Constant`isIndexInFuncSection`
|
---|
103 | - Constant`isValtypeLiteral`
|
---|
104 | - Constant`isTypeInstruction`
|
---|
105 | - Constant`isStart`
|
---|
106 | - Constant`isGlobalType`
|
---|
107 | - Constant`isLeadingComment`
|
---|
108 | - Constant`isBlockComment`
|
---|
109 | - Constant`isData`
|
---|
110 | - Constant`isGlobal`
|
---|
111 | - Constant`isTable`
|
---|
112 | - Constant`isMemory`
|
---|
113 | - Constant`isFuncImportDescr`
|
---|
114 | - Constant`isModuleImport`
|
---|
115 | - Constant`isModuleExportDescr`
|
---|
116 | - Constant`isModuleExport`
|
---|
117 | - Constant`isLimit`
|
---|
118 | - Constant`isSignature`
|
---|
119 | - Constant`isProgram`
|
---|
120 | - Constant`isIdentifier`
|
---|
121 | - Constant`isBlockInstruction`
|
---|
122 | - Constant`isCallInstruction`
|
---|
123 | - Constant`isCallIndirectInstruction`
|
---|
124 | - Constant`isByteArray`
|
---|
125 | - Constant`isFunc`
|
---|
126 | - Constant`assertModule`
|
---|
127 | - Constant`assertModuleMetadata`
|
---|
128 | - Constant`assertModuleNameMetadata`
|
---|
129 | - Constant`assertFunctionNameMetadata`
|
---|
130 | - Constant`assertLocalNameMetadata`
|
---|
131 | - Constant`assertBinaryModule`
|
---|
132 | - Constant`assertQuoteModule`
|
---|
133 | - Constant`assertSectionMetadata`
|
---|
134 | - Constant`assertLoopInstruction`
|
---|
135 | - Constant`assertInstruction`
|
---|
136 | - Constant`assertObjectInstruction`
|
---|
137 | - Constant`assertIfInstruction`
|
---|
138 | - Constant`assertStringLiteral`
|
---|
139 | - Constant`assertNumberLiteral`
|
---|
140 | - Constant`assertLongNumberLiteral`
|
---|
141 | - Constant`assertFloatLiteral`
|
---|
142 | - Constant`assertElem`
|
---|
143 | - Constant`assertIndexInFuncSection`
|
---|
144 | - Constant`assertValtypeLiteral`
|
---|
145 | - Constant`assertTypeInstruction`
|
---|
146 | - Constant`assertStart`
|
---|
147 | - Constant`assertGlobalType`
|
---|
148 | - Constant`assertLeadingComment`
|
---|
149 | - Constant`assertBlockComment`
|
---|
150 | - Constant`assertData`
|
---|
151 | - Constant`assertGlobal`
|
---|
152 | - Constant`assertTable`
|
---|
153 | - Constant`assertMemory`
|
---|
154 | - Constant`assertFuncImportDescr`
|
---|
155 | - Constant`assertModuleImport`
|
---|
156 | - Constant`assertModuleExportDescr`
|
---|
157 | - Constant`assertModuleExport`
|
---|
158 | - Constant`assertLimit`
|
---|
159 | - Constant`assertSignature`
|
---|
160 | - Constant`assertProgram`
|
---|
161 | - Constant`assertIdentifier`
|
---|
162 | - Constant`assertBlockInstruction`
|
---|
163 | - Constant`assertCallInstruction`
|
---|
164 | - Constant`assertCallIndirectInstruction`
|
---|
165 | - Constant`assertByteArray`
|
---|
166 | - Constant`assertFunc`
|
---|
167 |
|
---|