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