1 | "use strict";
|
2 |
|
3 | var definitions = {};
|
4 |
|
5 | function defineType(typeName, metadata) {
|
6 | definitions[typeName] = metadata;
|
7 | }
|
8 |
|
9 | defineType("Module", {
|
10 | spec: {
|
11 | wasm: "https://webassembly.github.io/spec/core/binary/modules.html#binary-module",
|
12 | wat: "https://webassembly.github.io/spec/core/text/modules.html#text-module"
|
13 | },
|
14 | doc: "A module consists of a sequence of sections (termed fields in the text format).",
|
15 | unionType: ["Node"],
|
16 | fields: {
|
17 | id: {
|
18 | maybe: true,
|
19 | type: "string"
|
20 | },
|
21 | fields: {
|
22 | array: true,
|
23 | type: "Node"
|
24 | },
|
25 | metadata: {
|
26 | optional: true,
|
27 | type: "ModuleMetadata"
|
28 | }
|
29 | }
|
30 | });
|
31 | defineType("ModuleMetadata", {
|
32 | unionType: ["Node"],
|
33 | fields: {
|
34 | sections: {
|
35 | array: true,
|
36 | type: "SectionMetadata"
|
37 | },
|
38 | functionNames: {
|
39 | optional: true,
|
40 | array: true,
|
41 | type: "FunctionNameMetadata"
|
42 | },
|
43 | localNames: {
|
44 | optional: true,
|
45 | array: true,
|
46 | type: "ModuleMetadata"
|
47 | },
|
48 | producers: {
|
49 | optional: true,
|
50 | array: true,
|
51 | type: "ProducersSectionMetadata"
|
52 | }
|
53 | }
|
54 | });
|
55 | defineType("ModuleNameMetadata", {
|
56 | unionType: ["Node"],
|
57 | fields: {
|
58 | value: {
|
59 | type: "string"
|
60 | }
|
61 | }
|
62 | });
|
63 | defineType("FunctionNameMetadata", {
|
64 | unionType: ["Node"],
|
65 | fields: {
|
66 | value: {
|
67 | type: "string"
|
68 | },
|
69 | index: {
|
70 | type: "number"
|
71 | }
|
72 | }
|
73 | });
|
74 | defineType("LocalNameMetadata", {
|
75 | unionType: ["Node"],
|
76 | fields: {
|
77 | value: {
|
78 | type: "string"
|
79 | },
|
80 | localIndex: {
|
81 | type: "number"
|
82 | },
|
83 | functionIndex: {
|
84 | type: "number"
|
85 | }
|
86 | }
|
87 | });
|
88 | defineType("BinaryModule", {
|
89 | unionType: ["Node"],
|
90 | fields: {
|
91 | id: {
|
92 | maybe: true,
|
93 | type: "string"
|
94 | },
|
95 | blob: {
|
96 | array: true,
|
97 | type: "string"
|
98 | }
|
99 | }
|
100 | });
|
101 | defineType("QuoteModule", {
|
102 | unionType: ["Node"],
|
103 | fields: {
|
104 | id: {
|
105 | maybe: true,
|
106 | type: "string"
|
107 | },
|
108 | string: {
|
109 | array: true,
|
110 | type: "string"
|
111 | }
|
112 | }
|
113 | });
|
114 | defineType("SectionMetadata", {
|
115 | unionType: ["Node"],
|
116 | fields: {
|
117 | section: {
|
118 | type: "SectionName"
|
119 | },
|
120 | startOffset: {
|
121 | type: "number"
|
122 | },
|
123 | size: {
|
124 | type: "NumberLiteral"
|
125 | },
|
126 | vectorOfSize: {
|
127 | comment: "Size of the vector in the section (if any)",
|
128 | type: "NumberLiteral"
|
129 | }
|
130 | }
|
131 | });
|
132 | defineType("ProducersSectionMetadata", {
|
133 | unionType: ["Node"],
|
134 | fields: {
|
135 | producers: {
|
136 | array: true,
|
137 | type: "ProducerMetadata"
|
138 | }
|
139 | }
|
140 | });
|
141 | defineType("ProducerMetadata", {
|
142 | unionType: ["Node"],
|
143 | fields: {
|
144 | language: {
|
145 | type: "ProducerMetadataVersionedName",
|
146 | array: true
|
147 | },
|
148 | processedBy: {
|
149 | type: "ProducerMetadataVersionedName",
|
150 | array: true
|
151 | },
|
152 | sdk: {
|
153 | type: "ProducerMetadataVersionedName",
|
154 | array: true
|
155 | }
|
156 | }
|
157 | });
|
158 | defineType("ProducerMetadataVersionedName", {
|
159 | unionType: ["Node"],
|
160 | fields: {
|
161 | name: {
|
162 | type: "string"
|
163 | },
|
164 | version: {
|
165 | type: "string"
|
166 | }
|
167 | }
|
168 | });
|
169 |
|
170 |
|
171 |
|
172 |
|
173 | defineType("LoopInstruction", {
|
174 | unionType: ["Node", "Block", "Instruction"],
|
175 | fields: {
|
176 | id: {
|
177 | constant: true,
|
178 | type: "string",
|
179 | value: "loop"
|
180 | },
|
181 | label: {
|
182 | maybe: true,
|
183 | type: "Identifier"
|
184 | },
|
185 | resulttype: {
|
186 | maybe: true,
|
187 | type: "Valtype"
|
188 | },
|
189 | instr: {
|
190 | array: true,
|
191 | type: "Instruction"
|
192 | }
|
193 | }
|
194 | });
|
195 | defineType("Instr", {
|
196 | unionType: ["Node", "Expression", "Instruction"],
|
197 | fields: {
|
198 | id: {
|
199 | type: "string"
|
200 | },
|
201 | object: {
|
202 | optional: true,
|
203 | type: "Valtype"
|
204 | },
|
205 | args: {
|
206 | array: true,
|
207 | type: "Expression"
|
208 | },
|
209 | namedArgs: {
|
210 | optional: true,
|
211 | type: "Object"
|
212 | }
|
213 | }
|
214 | });
|
215 | defineType("IfInstruction", {
|
216 | unionType: ["Node", "Instruction"],
|
217 | fields: {
|
218 | id: {
|
219 | constant: true,
|
220 | type: "string",
|
221 | value: "if"
|
222 | },
|
223 | testLabel: {
|
224 | comment: "only for WAST",
|
225 | type: "Identifier"
|
226 | },
|
227 | test: {
|
228 | array: true,
|
229 | type: "Instruction"
|
230 | },
|
231 | result: {
|
232 | maybe: true,
|
233 | type: "Valtype"
|
234 | },
|
235 | consequent: {
|
236 | array: true,
|
237 | type: "Instruction"
|
238 | },
|
239 | alternate: {
|
240 | array: true,
|
241 | type: "Instruction"
|
242 | }
|
243 | }
|
244 | });
|
245 |
|
246 |
|
247 |
|
248 |
|
249 | defineType("StringLiteral", {
|
250 | unionType: ["Node", "Expression"],
|
251 | fields: {
|
252 | value: {
|
253 | type: "string"
|
254 | }
|
255 | }
|
256 | });
|
257 | defineType("NumberLiteral", {
|
258 | unionType: ["Node", "NumericLiteral", "Expression"],
|
259 | fields: {
|
260 | value: {
|
261 | type: "number"
|
262 | },
|
263 | raw: {
|
264 | type: "string"
|
265 | }
|
266 | }
|
267 | });
|
268 | defineType("LongNumberLiteral", {
|
269 | unionType: ["Node", "NumericLiteral", "Expression"],
|
270 | fields: {
|
271 | value: {
|
272 | type: "LongNumber"
|
273 | },
|
274 | raw: {
|
275 | type: "string"
|
276 | }
|
277 | }
|
278 | });
|
279 | defineType("FloatLiteral", {
|
280 | unionType: ["Node", "NumericLiteral", "Expression"],
|
281 | fields: {
|
282 | value: {
|
283 | type: "number"
|
284 | },
|
285 | nan: {
|
286 | optional: true,
|
287 | type: "boolean"
|
288 | },
|
289 | inf: {
|
290 | optional: true,
|
291 | type: "boolean"
|
292 | },
|
293 | raw: {
|
294 | type: "string"
|
295 | }
|
296 | }
|
297 | });
|
298 | defineType("Elem", {
|
299 | unionType: ["Node"],
|
300 | fields: {
|
301 | table: {
|
302 | type: "Index"
|
303 | },
|
304 | offset: {
|
305 | array: true,
|
306 | type: "Instruction"
|
307 | },
|
308 | funcs: {
|
309 | array: true,
|
310 | type: "Index"
|
311 | }
|
312 | }
|
313 | });
|
314 | defineType("IndexInFuncSection", {
|
315 | unionType: ["Node"],
|
316 | fields: {
|
317 | index: {
|
318 | type: "Index"
|
319 | }
|
320 | }
|
321 | });
|
322 | defineType("ValtypeLiteral", {
|
323 | unionType: ["Node", "Expression"],
|
324 | fields: {
|
325 | name: {
|
326 | type: "Valtype"
|
327 | }
|
328 | }
|
329 | });
|
330 | defineType("TypeInstruction", {
|
331 | unionType: ["Node", "Instruction"],
|
332 | fields: {
|
333 | id: {
|
334 | maybe: true,
|
335 | type: "Index"
|
336 | },
|
337 | functype: {
|
338 | type: "Signature"
|
339 | }
|
340 | }
|
341 | });
|
342 | defineType("Start", {
|
343 | unionType: ["Node"],
|
344 | fields: {
|
345 | index: {
|
346 | type: "Index"
|
347 | }
|
348 | }
|
349 | });
|
350 | defineType("GlobalType", {
|
351 | unionType: ["Node", "ImportDescr"],
|
352 | fields: {
|
353 | valtype: {
|
354 | type: "Valtype"
|
355 | },
|
356 | mutability: {
|
357 | type: "Mutability"
|
358 | }
|
359 | }
|
360 | });
|
361 | defineType("LeadingComment", {
|
362 | unionType: ["Node"],
|
363 | fields: {
|
364 | value: {
|
365 | type: "string"
|
366 | }
|
367 | }
|
368 | });
|
369 | defineType("BlockComment", {
|
370 | unionType: ["Node"],
|
371 | fields: {
|
372 | value: {
|
373 | type: "string"
|
374 | }
|
375 | }
|
376 | });
|
377 | defineType("Data", {
|
378 | unionType: ["Node"],
|
379 | fields: {
|
380 | memoryIndex: {
|
381 | type: "Memidx"
|
382 | },
|
383 | offset: {
|
384 | type: "Instruction"
|
385 | },
|
386 | init: {
|
387 | type: "ByteArray"
|
388 | }
|
389 | }
|
390 | });
|
391 | defineType("Global", {
|
392 | unionType: ["Node"],
|
393 | fields: {
|
394 | globalType: {
|
395 | type: "GlobalType"
|
396 | },
|
397 | init: {
|
398 | array: true,
|
399 | type: "Instruction"
|
400 | },
|
401 | name: {
|
402 | maybe: true,
|
403 | type: "Identifier"
|
404 | }
|
405 | }
|
406 | });
|
407 | defineType("Table", {
|
408 | unionType: ["Node", "ImportDescr"],
|
409 | fields: {
|
410 | elementType: {
|
411 | type: "TableElementType"
|
412 | },
|
413 | limits: {
|
414 | assertNodeType: true,
|
415 | type: "Limit"
|
416 | },
|
417 | name: {
|
418 | maybe: true,
|
419 | type: "Identifier"
|
420 | },
|
421 | elements: {
|
422 | array: true,
|
423 | optional: true,
|
424 | type: "Index"
|
425 | }
|
426 | }
|
427 | });
|
428 | defineType("Memory", {
|
429 | unionType: ["Node", "ImportDescr"],
|
430 | fields: {
|
431 | limits: {
|
432 | type: "Limit"
|
433 | },
|
434 | id: {
|
435 | maybe: true,
|
436 | type: "Index"
|
437 | }
|
438 | }
|
439 | });
|
440 | defineType("FuncImportDescr", {
|
441 | unionType: ["Node", "ImportDescr"],
|
442 | fields: {
|
443 | id: {
|
444 | type: "Identifier"
|
445 | },
|
446 | signature: {
|
447 | type: "Signature"
|
448 | }
|
449 | }
|
450 | });
|
451 | defineType("ModuleImport", {
|
452 | unionType: ["Node"],
|
453 | fields: {
|
454 | module: {
|
455 | type: "string"
|
456 | },
|
457 | name: {
|
458 | type: "string"
|
459 | },
|
460 | descr: {
|
461 | type: "ImportDescr"
|
462 | }
|
463 | }
|
464 | });
|
465 | defineType("ModuleExportDescr", {
|
466 | unionType: ["Node"],
|
467 | fields: {
|
468 | exportType: {
|
469 | type: "ExportDescrType"
|
470 | },
|
471 | id: {
|
472 | type: "Index"
|
473 | }
|
474 | }
|
475 | });
|
476 | defineType("ModuleExport", {
|
477 | unionType: ["Node"],
|
478 | fields: {
|
479 | name: {
|
480 | type: "string"
|
481 | },
|
482 | descr: {
|
483 | type: "ModuleExportDescr"
|
484 | }
|
485 | }
|
486 | });
|
487 | defineType("Limit", {
|
488 | unionType: ["Node"],
|
489 | fields: {
|
490 | min: {
|
491 | type: "number"
|
492 | },
|
493 | max: {
|
494 | optional: true,
|
495 | type: "number"
|
496 | },
|
497 |
|
498 | shared: {
|
499 | optional: true,
|
500 | type: "boolean"
|
501 | }
|
502 | }
|
503 | });
|
504 | defineType("Signature", {
|
505 | unionType: ["Node"],
|
506 | fields: {
|
507 | params: {
|
508 | array: true,
|
509 | type: "FuncParam"
|
510 | },
|
511 | results: {
|
512 | array: true,
|
513 | type: "Valtype"
|
514 | }
|
515 | }
|
516 | });
|
517 | defineType("Program", {
|
518 | unionType: ["Node"],
|
519 | fields: {
|
520 | body: {
|
521 | array: true,
|
522 | type: "Node"
|
523 | }
|
524 | }
|
525 | });
|
526 | defineType("Identifier", {
|
527 | unionType: ["Node", "Expression"],
|
528 | fields: {
|
529 | value: {
|
530 | type: "string"
|
531 | },
|
532 | raw: {
|
533 | optional: true,
|
534 | type: "string"
|
535 | }
|
536 | }
|
537 | });
|
538 | defineType("BlockInstruction", {
|
539 | unionType: ["Node", "Block", "Instruction"],
|
540 | fields: {
|
541 | id: {
|
542 | constant: true,
|
543 | type: "string",
|
544 | value: "block"
|
545 | },
|
546 | label: {
|
547 | maybe: true,
|
548 | type: "Identifier"
|
549 | },
|
550 | instr: {
|
551 | array: true,
|
552 | type: "Instruction"
|
553 | },
|
554 | result: {
|
555 | maybe: true,
|
556 | type: "Valtype"
|
557 | }
|
558 | }
|
559 | });
|
560 | defineType("CallInstruction", {
|
561 | unionType: ["Node", "Instruction"],
|
562 | fields: {
|
563 | id: {
|
564 | constant: true,
|
565 | type: "string",
|
566 | value: "call"
|
567 | },
|
568 | index: {
|
569 | type: "Index"
|
570 | },
|
571 | instrArgs: {
|
572 | array: true,
|
573 | optional: true,
|
574 | type: "Expression"
|
575 | },
|
576 | numeric: {
|
577 | type: "Index",
|
578 | optional: true
|
579 | }
|
580 | }
|
581 | });
|
582 | defineType("CallIndirectInstruction", {
|
583 | unionType: ["Node", "Instruction"],
|
584 | fields: {
|
585 | id: {
|
586 | constant: true,
|
587 | type: "string",
|
588 | value: "call_indirect"
|
589 | },
|
590 | signature: {
|
591 | type: "SignatureOrTypeRef"
|
592 | },
|
593 | intrs: {
|
594 | array: true,
|
595 | optional: true,
|
596 | type: "Expression"
|
597 | }
|
598 | }
|
599 | });
|
600 | defineType("ByteArray", {
|
601 | unionType: ["Node"],
|
602 | fields: {
|
603 | values: {
|
604 | array: true,
|
605 | type: "Byte"
|
606 | }
|
607 | }
|
608 | });
|
609 | defineType("Func", {
|
610 | unionType: ["Node", "Block"],
|
611 | fields: {
|
612 | name: {
|
613 | maybe: true,
|
614 | type: "Index"
|
615 | },
|
616 | signature: {
|
617 | type: "SignatureOrTypeRef"
|
618 | },
|
619 | body: {
|
620 | array: true,
|
621 | type: "Instruction"
|
622 | },
|
623 | isExternal: {
|
624 | comment: "means that it has been imported from the outside js",
|
625 | optional: true,
|
626 | type: "boolean"
|
627 | },
|
628 | metadata: {
|
629 | optional: true,
|
630 | type: "FuncMetadata"
|
631 | }
|
632 | }
|
633 | });
|
634 |
|
635 |
|
636 |
|
637 |
|
638 | defineType("InternalBrUnless", {
|
639 | unionType: ["Node", "Intrinsic"],
|
640 | fields: {
|
641 | target: {
|
642 | type: "number"
|
643 | }
|
644 | }
|
645 | });
|
646 | defineType("InternalGoto", {
|
647 | unionType: ["Node", "Intrinsic"],
|
648 | fields: {
|
649 | target: {
|
650 | type: "number"
|
651 | }
|
652 | }
|
653 | });
|
654 | defineType("InternalCallExtern", {
|
655 | unionType: ["Node", "Intrinsic"],
|
656 | fields: {
|
657 | target: {
|
658 | type: "number"
|
659 | }
|
660 | }
|
661 | });
|
662 |
|
663 |
|
664 |
|
665 |
|
666 | defineType("InternalEndAndReturn", {
|
667 | unionType: ["Node", "Intrinsic"],
|
668 | fields: {}
|
669 | });
|
670 | module.exports = definitions; |
\ | No newline at end of file |