watr 5.0.0 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/watr.js +825 -907
- package/dist/watr.min.js +5 -6
- package/dist/watr.wasm +0 -0
- package/package.json +3 -3
- package/readme.md +19 -5
- package/src/compile.js +236 -110
- package/src/const.js +125 -131
- package/src/encode.js +28 -3
- package/src/optimize.js +2909 -421
- package/src/print.js +8 -3
- package/src/util.js +33 -9
- package/types/src/compile.d.ts +1 -0
- package/types/src/compile.d.ts.map +1 -1
- package/types/src/const.d.ts +2 -1
- package/types/src/const.d.ts.map +1 -1
- package/types/src/encode.d.ts +5 -26
- package/types/src/encode.d.ts.map +1 -1
- package/types/src/optimize.d.ts +41 -33
- package/types/src/optimize.d.ts.map +1 -1
- package/types/src/print.d.ts.map +1 -1
- package/types/src/util.d.ts +5 -10
- package/types/src/util.d.ts.map +1 -1
package/dist/watr.js
CHANGED
|
@@ -19,17 +19,27 @@ __export(encode_exports, {
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
// src/util.js
|
|
22
|
-
var
|
|
23
|
-
|
|
22
|
+
var errLoc;
|
|
23
|
+
var errSrc;
|
|
24
|
+
var err = (text, pos = errLoc) => {
|
|
25
|
+
if (pos != null && errSrc) {
|
|
24
26
|
let line = 1, col = 1;
|
|
25
|
-
for (let i = 0; i < pos && i <
|
|
26
|
-
if (
|
|
27
|
+
for (let i = 0; i < pos && i < errSrc.length; i++) {
|
|
28
|
+
if (errSrc.charCodeAt(i) === 10) line++, col = 1;
|
|
27
29
|
else col++;
|
|
28
30
|
}
|
|
29
31
|
text += ` at ${line}:${col}`;
|
|
30
32
|
}
|
|
31
33
|
throw Error(text);
|
|
32
34
|
};
|
|
35
|
+
var setErrLoc = (loc) => {
|
|
36
|
+
errLoc = loc;
|
|
37
|
+
};
|
|
38
|
+
var setErrSrc = (src) => {
|
|
39
|
+
errSrc = src;
|
|
40
|
+
};
|
|
41
|
+
var getErrLoc = () => errLoc;
|
|
42
|
+
var getErrSrc = () => errSrc;
|
|
33
43
|
var sepRE = /^_|_$|[^\da-f]_|_[^\da-f]/i;
|
|
34
44
|
var intRE = /^[+-]?(?:0x[\da-f]+|\d+)$/i;
|
|
35
45
|
var tenc = new TextEncoder();
|
|
@@ -94,8 +104,17 @@ function uleb5(value) {
|
|
|
94
104
|
}
|
|
95
105
|
return result;
|
|
96
106
|
}
|
|
107
|
+
var I32_MEMO = /* @__PURE__ */ new Map();
|
|
97
108
|
function i32(n, buffer = []) {
|
|
98
|
-
if (typeof n === "string")
|
|
109
|
+
if (typeof n === "string") {
|
|
110
|
+
let v = I32_MEMO.get(n);
|
|
111
|
+
if (v === void 0) {
|
|
112
|
+
v = i32.parse(n);
|
|
113
|
+
if (I32_MEMO.size > 65536) I32_MEMO.clear();
|
|
114
|
+
I32_MEMO.set(n, v);
|
|
115
|
+
}
|
|
116
|
+
n = v;
|
|
117
|
+
}
|
|
99
118
|
while (true) {
|
|
100
119
|
const byte = Number(n & 127);
|
|
101
120
|
n >>= 7;
|
|
@@ -160,7 +179,7 @@ i64.parse = (n) => {
|
|
|
160
179
|
var F32_SIGN = 2147483648;
|
|
161
180
|
var F32_NAN = 2139095040;
|
|
162
181
|
var F32_QUIET = 4194304;
|
|
163
|
-
function f32(input, value, idx) {
|
|
182
|
+
function f32(input, out, value, idx) {
|
|
164
183
|
if (typeof input === "string" && (idx = input.indexOf("nan")) >= 0) {
|
|
165
184
|
if (input[idx + 3] === ":") {
|
|
166
185
|
const tail = input.slice(idx + 4);
|
|
@@ -173,12 +192,27 @@ function f32(input, value, idx) {
|
|
|
173
192
|
value = typeof input === "string" ? f32.parse(input) : input;
|
|
174
193
|
_f32[0] = value;
|
|
175
194
|
}
|
|
195
|
+
if (out) {
|
|
196
|
+
out.push(_u8[0], _u8[1], _u8[2], _u8[3]);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
176
199
|
return [_u8[0], _u8[1], _u8[2], _u8[3]];
|
|
177
200
|
}
|
|
178
201
|
var F64_SIGN = 0x8000000000000000n;
|
|
179
202
|
var F64_NAN = 0x7ff0000000000000n;
|
|
180
203
|
var F64_QUIET = 0x8000000000000n;
|
|
181
|
-
|
|
204
|
+
var F64_MEMO = /* @__PURE__ */ new Map();
|
|
205
|
+
function f64(input, out, value, idx) {
|
|
206
|
+
if (typeof input === "string") {
|
|
207
|
+
const m = F64_MEMO.get(input);
|
|
208
|
+
if (m !== void 0) {
|
|
209
|
+
if (out) {
|
|
210
|
+
out.push(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7]);
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
return m.slice();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
182
216
|
if (typeof input === "string" && (idx = input.indexOf("nan")) >= 0) {
|
|
183
217
|
if (input[idx + 3] === ":") {
|
|
184
218
|
const tail = input.slice(idx + 4);
|
|
@@ -191,6 +225,14 @@ function f64(input, value, idx) {
|
|
|
191
225
|
value = typeof input === "string" ? f64.parse(input) : input;
|
|
192
226
|
_f64[0] = value;
|
|
193
227
|
}
|
|
228
|
+
if (typeof input === "string") {
|
|
229
|
+
if (F64_MEMO.size > 65536) F64_MEMO.clear();
|
|
230
|
+
F64_MEMO.set(input, [_u8[0], _u8[1], _u8[2], _u8[3], _u8[4], _u8[5], _u8[6], _u8[7]]);
|
|
231
|
+
}
|
|
232
|
+
if (out) {
|
|
233
|
+
out.push(_u8[0], _u8[1], _u8[2], _u8[3], _u8[4], _u8[5], _u8[6], _u8[7]);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
194
236
|
return [_u8[0], _u8[1], _u8[2], _u8[3], _u8[4], _u8[5], _u8[6], _u8[7]];
|
|
195
237
|
}
|
|
196
238
|
f64.parse = (input, max = Number.MAX_VALUE) => {
|
|
@@ -226,18 +268,18 @@ var v128 = (input) => {
|
|
|
226
268
|
};
|
|
227
269
|
|
|
228
270
|
// src/const.js
|
|
229
|
-
var
|
|
271
|
+
var TABLE = [
|
|
230
272
|
// 0x00-0x0a: control
|
|
231
273
|
"unreachable",
|
|
232
274
|
"nop",
|
|
233
275
|
"block block",
|
|
234
276
|
"loop block",
|
|
235
277
|
"if block",
|
|
236
|
-
"else
|
|
237
|
-
"then
|
|
238
|
-
,
|
|
278
|
+
"else",
|
|
279
|
+
"then",
|
|
280
|
+
8,
|
|
239
281
|
"throw tagidx",
|
|
240
|
-
,
|
|
282
|
+
10,
|
|
241
283
|
"throw_ref",
|
|
242
284
|
// 0x0b-0x19: control
|
|
243
285
|
"end end",
|
|
@@ -251,16 +293,11 @@ var INSTR = [
|
|
|
251
293
|
"return_call_indirect call_indirect",
|
|
252
294
|
"call_ref typeidx",
|
|
253
295
|
"return_call_ref typeidx",
|
|
254
|
-
,
|
|
255
|
-
,
|
|
256
|
-
,
|
|
257
|
-
,
|
|
258
296
|
// 0x1a-0x1f: parametric
|
|
297
|
+
26,
|
|
259
298
|
"drop",
|
|
260
299
|
"select select",
|
|
261
|
-
|
|
262
|
-
,
|
|
263
|
-
,
|
|
300
|
+
31,
|
|
264
301
|
"try_table try_table",
|
|
265
302
|
// 0x20-0x27: variable
|
|
266
303
|
"local.get localidx",
|
|
@@ -270,8 +307,8 @@ var INSTR = [
|
|
|
270
307
|
"global.set globalidx",
|
|
271
308
|
"table.get tableidx",
|
|
272
309
|
"table.set tableidx",
|
|
273
|
-
,
|
|
274
310
|
// 0x28-0x3e: memory
|
|
311
|
+
40,
|
|
275
312
|
"i32.load memarg",
|
|
276
313
|
"i64.load memarg",
|
|
277
314
|
"f32.load memarg",
|
|
@@ -441,18 +478,8 @@ var INSTR = [
|
|
|
441
478
|
"i64.extend8_s",
|
|
442
479
|
"i64.extend16_s",
|
|
443
480
|
"i64.extend32_s",
|
|
444
|
-
,
|
|
445
|
-
,
|
|
446
|
-
,
|
|
447
|
-
,
|
|
448
|
-
,
|
|
449
|
-
,
|
|
450
|
-
,
|
|
451
|
-
,
|
|
452
|
-
,
|
|
453
|
-
,
|
|
454
|
-
,
|
|
455
481
|
// 0xd0-0xd6: reference
|
|
482
|
+
208,
|
|
456
483
|
"ref.null ref_null",
|
|
457
484
|
"ref.is_null",
|
|
458
485
|
"ref.func funcidx",
|
|
@@ -460,16 +487,8 @@ var INSTR = [
|
|
|
460
487
|
"ref.as_non_null",
|
|
461
488
|
"br_on_null labelidx",
|
|
462
489
|
"br_on_non_null labelidx",
|
|
463
|
-
,
|
|
464
|
-
,
|
|
465
|
-
,
|
|
466
|
-
,
|
|
467
|
-
,
|
|
468
|
-
,
|
|
469
|
-
,
|
|
470
|
-
,
|
|
471
|
-
,
|
|
472
490
|
// 0xe0-0xe6: stack switching (Phase 3)
|
|
491
|
+
224,
|
|
473
492
|
"cont.new typeidx",
|
|
474
493
|
"cont.bind cont_bind",
|
|
475
494
|
"suspend tagidx",
|
|
@@ -477,772 +496,534 @@ var INSTR = [
|
|
|
477
496
|
"resume_throw resume_throw",
|
|
478
497
|
"resume_throw_ref resume_throw_ref",
|
|
479
498
|
"switch switch_cont",
|
|
480
|
-
|
|
481
|
-
,
|
|
482
|
-
,
|
|
483
|
-
,
|
|
484
|
-
,
|
|
485
|
-
,
|
|
486
|
-
,
|
|
487
|
-
,
|
|
488
|
-
,
|
|
489
|
-
,
|
|
490
|
-
,
|
|
491
|
-
,
|
|
492
|
-
,
|
|
493
|
-
,
|
|
494
|
-
,
|
|
495
|
-
,
|
|
496
|
-
,
|
|
497
|
-
,
|
|
498
|
-
,
|
|
499
|
-
,
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
"i8x16.lt_u",
|
|
925
|
-
"i8x16.gt_s",
|
|
926
|
-
"i8x16.gt_u",
|
|
927
|
-
"i8x16.le_s",
|
|
928
|
-
"i8x16.le_u",
|
|
929
|
-
"i8x16.ge_s",
|
|
930
|
-
"i8x16.ge_u",
|
|
931
|
-
"i16x8.eq",
|
|
932
|
-
"i16x8.ne",
|
|
933
|
-
"i16x8.lt_s",
|
|
934
|
-
"i16x8.lt_u",
|
|
935
|
-
"i16x8.gt_s",
|
|
936
|
-
"i16x8.gt_u",
|
|
937
|
-
"i16x8.le_s",
|
|
938
|
-
"i16x8.le_u",
|
|
939
|
-
"i16x8.ge_s",
|
|
940
|
-
"i16x8.ge_u",
|
|
941
|
-
"i32x4.eq",
|
|
942
|
-
"i32x4.ne",
|
|
943
|
-
"i32x4.lt_s",
|
|
944
|
-
"i32x4.lt_u",
|
|
945
|
-
"i32x4.gt_s",
|
|
946
|
-
"i32x4.gt_u",
|
|
947
|
-
"i32x4.le_s",
|
|
948
|
-
"i32x4.le_u",
|
|
949
|
-
"i32x4.ge_s",
|
|
950
|
-
"i32x4.ge_u",
|
|
951
|
-
"f32x4.eq",
|
|
952
|
-
"f32x4.ne",
|
|
953
|
-
"f32x4.lt",
|
|
954
|
-
"f32x4.gt",
|
|
955
|
-
"f32x4.le",
|
|
956
|
-
"f32x4.ge",
|
|
957
|
-
"f64x2.eq",
|
|
958
|
-
"f64x2.ne",
|
|
959
|
-
"f64x2.lt",
|
|
960
|
-
"f64x2.gt",
|
|
961
|
-
"f64x2.le",
|
|
962
|
-
"f64x2.ge",
|
|
963
|
-
"v128.not",
|
|
964
|
-
"v128.and",
|
|
965
|
-
"v128.andnot",
|
|
966
|
-
"v128.or",
|
|
967
|
-
"v128.xor",
|
|
968
|
-
"v128.bitselect",
|
|
969
|
-
"v128.any_true",
|
|
970
|
-
"v128.load8_lane memlane",
|
|
971
|
-
"v128.load16_lane memlane",
|
|
972
|
-
"v128.load32_lane memlane",
|
|
973
|
-
"v128.load64_lane memlane",
|
|
974
|
-
"v128.store8_lane memlane",
|
|
975
|
-
"v128.store16_lane memlane",
|
|
976
|
-
"v128.store32_lane memlane",
|
|
977
|
-
"v128.store64_lane memlane",
|
|
978
|
-
"v128.load32_zero memarg",
|
|
979
|
-
"v128.load64_zero memarg",
|
|
980
|
-
"f32x4.demote_f64x2_zero",
|
|
981
|
-
"f64x2.promote_low_f32x4",
|
|
982
|
-
"i8x16.abs",
|
|
983
|
-
"i8x16.neg",
|
|
984
|
-
"i8x16.popcnt",
|
|
985
|
-
"i8x16.all_true",
|
|
986
|
-
"i8x16.bitmask",
|
|
987
|
-
"i8x16.narrow_i16x8_s",
|
|
988
|
-
"i8x16.narrow_i16x8_u",
|
|
989
|
-
"f32x4.ceil",
|
|
990
|
-
"f32x4.floor",
|
|
991
|
-
"f32x4.trunc",
|
|
992
|
-
"f32x4.nearest",
|
|
993
|
-
"i8x16.shl",
|
|
994
|
-
"i8x16.shr_s",
|
|
995
|
-
"i8x16.shr_u",
|
|
996
|
-
"i8x16.add",
|
|
997
|
-
"i8x16.add_sat_s",
|
|
998
|
-
"i8x16.add_sat_u",
|
|
999
|
-
"i8x16.sub",
|
|
1000
|
-
"i8x16.sub_sat_s",
|
|
1001
|
-
"i8x16.sub_sat_u",
|
|
1002
|
-
"f64x2.ceil",
|
|
1003
|
-
"f64x2.floor",
|
|
1004
|
-
"i8x16.min_s",
|
|
1005
|
-
"i8x16.min_u",
|
|
1006
|
-
"i8x16.max_s",
|
|
1007
|
-
"i8x16.max_u",
|
|
1008
|
-
"f64x2.trunc",
|
|
1009
|
-
"i8x16.avgr_u",
|
|
1010
|
-
"i16x8.extadd_pairwise_i8x16_s",
|
|
1011
|
-
"i16x8.extadd_pairwise_i8x16_u",
|
|
1012
|
-
"i32x4.extadd_pairwise_i16x8_s",
|
|
1013
|
-
"i32x4.extadd_pairwise_i16x8_u",
|
|
1014
|
-
"i16x8.abs",
|
|
1015
|
-
"i16x8.neg",
|
|
1016
|
-
"i16x8.q15mulr_sat_s",
|
|
1017
|
-
"i16x8.all_true",
|
|
1018
|
-
"i16x8.bitmask",
|
|
1019
|
-
"i16x8.narrow_i32x4_s",
|
|
1020
|
-
"i16x8.narrow_i32x4_u",
|
|
1021
|
-
"i16x8.extend_low_i8x16_s",
|
|
1022
|
-
"i16x8.extend_high_i8x16_s",
|
|
1023
|
-
"i16x8.extend_low_i8x16_u",
|
|
1024
|
-
"i16x8.extend_high_i8x16_u",
|
|
1025
|
-
"i16x8.shl",
|
|
1026
|
-
"i16x8.shr_s",
|
|
1027
|
-
"i16x8.shr_u",
|
|
1028
|
-
"i16x8.add",
|
|
1029
|
-
"i16x8.add_sat_s",
|
|
1030
|
-
"i16x8.add_sat_u",
|
|
1031
|
-
"i16x8.sub",
|
|
1032
|
-
"i16x8.sub_sat_s",
|
|
1033
|
-
"i16x8.sub_sat_u",
|
|
1034
|
-
"f64x2.nearest",
|
|
1035
|
-
"i16x8.mul",
|
|
1036
|
-
"i16x8.min_s",
|
|
1037
|
-
"i16x8.min_u",
|
|
1038
|
-
"i16x8.max_s",
|
|
1039
|
-
"i16x8.max_u",
|
|
1040
|
-
,
|
|
1041
|
-
"i16x8.avgr_u",
|
|
1042
|
-
"i16x8.extmul_low_i8x16_s",
|
|
1043
|
-
"i16x8.extmul_high_i8x16_s",
|
|
1044
|
-
"i16x8.extmul_low_i8x16_u",
|
|
1045
|
-
"i16x8.extmul_high_i8x16_u",
|
|
1046
|
-
"i32x4.abs",
|
|
1047
|
-
"i32x4.neg",
|
|
1048
|
-
,
|
|
1049
|
-
"i32x4.all_true",
|
|
1050
|
-
"i32x4.bitmask",
|
|
1051
|
-
,
|
|
1052
|
-
,
|
|
1053
|
-
"i32x4.extend_low_i16x8_s",
|
|
1054
|
-
"i32x4.extend_high_i16x8_s",
|
|
1055
|
-
"i32x4.extend_low_i16x8_u",
|
|
1056
|
-
"i32x4.extend_high_i16x8_u",
|
|
1057
|
-
"i32x4.shl",
|
|
1058
|
-
"i32x4.shr_s",
|
|
1059
|
-
"i32x4.shr_u",
|
|
1060
|
-
"i32x4.add",
|
|
1061
|
-
,
|
|
1062
|
-
,
|
|
1063
|
-
"i32x4.sub",
|
|
1064
|
-
,
|
|
1065
|
-
,
|
|
1066
|
-
,
|
|
1067
|
-
"i32x4.mul",
|
|
1068
|
-
"i32x4.min_s",
|
|
1069
|
-
"i32x4.min_u",
|
|
1070
|
-
"i32x4.max_s",
|
|
1071
|
-
"i32x4.max_u",
|
|
1072
|
-
"i32x4.dot_i16x8_s",
|
|
1073
|
-
,
|
|
1074
|
-
"i32x4.extmul_low_i16x8_s",
|
|
1075
|
-
"i32x4.extmul_high_i16x8_s",
|
|
1076
|
-
"i32x4.extmul_low_i16x8_u",
|
|
1077
|
-
"i32x4.extmul_high_i16x8_u",
|
|
1078
|
-
"i64x2.abs",
|
|
1079
|
-
"i64x2.neg",
|
|
1080
|
-
,
|
|
1081
|
-
"i64x2.all_true",
|
|
1082
|
-
"i64x2.bitmask",
|
|
1083
|
-
,
|
|
1084
|
-
,
|
|
1085
|
-
"i64x2.extend_low_i32x4_s",
|
|
1086
|
-
"i64x2.extend_high_i32x4_s",
|
|
1087
|
-
"i64x2.extend_low_i32x4_u",
|
|
1088
|
-
"i64x2.extend_high_i32x4_u",
|
|
1089
|
-
"i64x2.shl",
|
|
1090
|
-
"i64x2.shr_s",
|
|
1091
|
-
"i64x2.shr_u",
|
|
1092
|
-
"i64x2.add",
|
|
1093
|
-
,
|
|
1094
|
-
,
|
|
1095
|
-
"i64x2.sub",
|
|
1096
|
-
,
|
|
1097
|
-
,
|
|
1098
|
-
,
|
|
1099
|
-
"i64x2.mul",
|
|
1100
|
-
"i64x2.eq",
|
|
1101
|
-
"i64x2.ne",
|
|
1102
|
-
"i64x2.lt_s",
|
|
1103
|
-
"i64x2.gt_s",
|
|
1104
|
-
"i64x2.le_s",
|
|
1105
|
-
"i64x2.ge_s",
|
|
1106
|
-
"i64x2.extmul_low_i32x4_s",
|
|
1107
|
-
"i64x2.extmul_high_i32x4_s",
|
|
1108
|
-
"i64x2.extmul_low_i32x4_u",
|
|
1109
|
-
"i64x2.extmul_high_i32x4_u",
|
|
1110
|
-
"f32x4.abs",
|
|
1111
|
-
"f32x4.neg",
|
|
1112
|
-
,
|
|
1113
|
-
"f32x4.sqrt",
|
|
1114
|
-
"f32x4.add",
|
|
1115
|
-
"f32x4.sub",
|
|
1116
|
-
"f32x4.mul",
|
|
1117
|
-
"f32x4.div",
|
|
1118
|
-
"f32x4.min",
|
|
1119
|
-
"f32x4.max",
|
|
1120
|
-
"f32x4.pmin",
|
|
1121
|
-
"f32x4.pmax",
|
|
1122
|
-
"f64x2.abs",
|
|
1123
|
-
"f64x2.neg",
|
|
1124
|
-
,
|
|
1125
|
-
"f64x2.sqrt",
|
|
1126
|
-
"f64x2.add",
|
|
1127
|
-
"f64x2.sub",
|
|
1128
|
-
"f64x2.mul",
|
|
1129
|
-
"f64x2.div",
|
|
1130
|
-
"f64x2.min",
|
|
1131
|
-
"f64x2.max",
|
|
1132
|
-
"f64x2.pmin",
|
|
1133
|
-
"f64x2.pmax",
|
|
1134
|
-
"i32x4.trunc_sat_f32x4_s",
|
|
1135
|
-
"i32x4.trunc_sat_f32x4_u",
|
|
1136
|
-
"f32x4.convert_i32x4_s",
|
|
1137
|
-
"f32x4.convert_i32x4_u",
|
|
1138
|
-
"i32x4.trunc_sat_f64x2_s_zero",
|
|
1139
|
-
"i32x4.trunc_sat_f64x2_u_zero",
|
|
1140
|
-
"f64x2.convert_low_i32x4_s",
|
|
1141
|
-
"f64x2.convert_low_i32x4_u",
|
|
1142
|
-
"i8x16.relaxed_swizzle",
|
|
1143
|
-
"i32x4.relaxed_trunc_f32x4_s",
|
|
1144
|
-
"i32x4.relaxed_trunc_f32x4_u",
|
|
1145
|
-
"i32x4.relaxed_trunc_f64x2_s_zero",
|
|
1146
|
-
"i32x4.relaxed_trunc_f64x2_u_zero",
|
|
1147
|
-
"f32x4.relaxed_madd",
|
|
1148
|
-
"f32x4.relaxed_nmadd",
|
|
1149
|
-
"f64x2.relaxed_madd",
|
|
1150
|
-
"f64x2.relaxed_nmadd",
|
|
1151
|
-
"i8x16.relaxed_laneselect",
|
|
1152
|
-
"i16x8.relaxed_laneselect",
|
|
1153
|
-
"i32x4.relaxed_laneselect",
|
|
1154
|
-
"i64x2.relaxed_laneselect",
|
|
1155
|
-
"f32x4.relaxed_min",
|
|
1156
|
-
"f32x4.relaxed_max",
|
|
1157
|
-
"f64x2.relaxed_min",
|
|
1158
|
-
"f64x2.relaxed_max",
|
|
1159
|
-
"i16x8.relaxed_q15mulr_s",
|
|
1160
|
-
"i16x8.relaxed_dot_i8x16_i7x16_s",
|
|
1161
|
-
"i32x4.relaxed_dot_i8x16_i7x16_add_s"
|
|
1162
|
-
],
|
|
499
|
+
// 0xfb: GC instructions
|
|
500
|
+
16449536,
|
|
501
|
+
"struct.new typeidx",
|
|
502
|
+
"struct.new_default typeidx",
|
|
503
|
+
"struct.get typeidx_field",
|
|
504
|
+
"struct.get_s typeidx_field",
|
|
505
|
+
"struct.get_u typeidx_field",
|
|
506
|
+
"struct.set typeidx_field",
|
|
507
|
+
"array.new typeidx",
|
|
508
|
+
"array.new_default typeidx",
|
|
509
|
+
"array.new_fixed typeidx_multi",
|
|
510
|
+
"array.new_data typeidx_dataidx",
|
|
511
|
+
"array.new_elem typeidx_elemidx",
|
|
512
|
+
"array.get typeidx",
|
|
513
|
+
"array.get_s typeidx",
|
|
514
|
+
"array.get_u typeidx",
|
|
515
|
+
"array.set typeidx",
|
|
516
|
+
"array.len",
|
|
517
|
+
"array.fill typeidx",
|
|
518
|
+
"array.copy typeidx_typeidx",
|
|
519
|
+
"array.init_data typeidx_dataidx",
|
|
520
|
+
"array.init_elem typeidx_elemidx",
|
|
521
|
+
"ref.test reftype",
|
|
522
|
+
"ref.test_null reftype",
|
|
523
|
+
"ref.cast reftype",
|
|
524
|
+
"ref.cast_null reftype",
|
|
525
|
+
"br_on_cast reftype2",
|
|
526
|
+
"br_on_cast_fail reftype2",
|
|
527
|
+
"any.convert_extern",
|
|
528
|
+
"extern.convert_any",
|
|
529
|
+
"ref.i31",
|
|
530
|
+
"i31.get_s",
|
|
531
|
+
"i31.get_u",
|
|
532
|
+
// custom descriptors (Phase 3): 0xFB 0x20-0x26
|
|
533
|
+
16449568,
|
|
534
|
+
"struct.new_desc typeidx",
|
|
535
|
+
"struct.new_default_desc typeidx",
|
|
536
|
+
"ref.get_desc typeidx",
|
|
537
|
+
"ref.cast_desc_eq reftype",
|
|
538
|
+
16449573,
|
|
539
|
+
"br_on_cast_desc_eq reftype2",
|
|
540
|
+
"br_on_cast_desc_eq_fail reftype2",
|
|
541
|
+
// stringref: 0xFB 0x80-0xB7
|
|
542
|
+
16449664,
|
|
543
|
+
"string.new_utf8 memoryidx?",
|
|
544
|
+
"string.new_wtf16 memoryidx?",
|
|
545
|
+
"string.const stringidx",
|
|
546
|
+
"string.measure_utf8",
|
|
547
|
+
"string.measure_wtf8",
|
|
548
|
+
"string.measure_wtf16",
|
|
549
|
+
"string.encode_utf8 memoryidx?",
|
|
550
|
+
"string.encode_wtf16 memoryidx?",
|
|
551
|
+
"string.concat",
|
|
552
|
+
"string.eq",
|
|
553
|
+
"string.is_usv_sequence",
|
|
554
|
+
"string.new_lossy_utf8 memoryidx?",
|
|
555
|
+
"string.new_wtf8 memoryidx?",
|
|
556
|
+
"string.encode_lossy_utf8 memoryidx?",
|
|
557
|
+
"string.encode_wtf8 memoryidx?",
|
|
558
|
+
16449680,
|
|
559
|
+
"string.as_wtf8",
|
|
560
|
+
"stringview_wtf8.advance",
|
|
561
|
+
"stringview_wtf8.encode_utf8 memoryidx?",
|
|
562
|
+
"stringview_wtf8.slice",
|
|
563
|
+
"stringview_wtf8.encode_lossy_utf8 memoryidx?",
|
|
564
|
+
"stringview_wtf8.encode_wtf8 memoryidx?",
|
|
565
|
+
16449688,
|
|
566
|
+
"string.as_wtf16",
|
|
567
|
+
"stringview_wtf16.length",
|
|
568
|
+
"stringview_wtf16.get_codeunit",
|
|
569
|
+
"stringview_wtf16.encode memoryidx?",
|
|
570
|
+
"stringview_wtf16.slice",
|
|
571
|
+
16449696,
|
|
572
|
+
"string.as_iter",
|
|
573
|
+
"stringview_iter.next",
|
|
574
|
+
"stringview_iter.advance",
|
|
575
|
+
"stringview_iter.rewind",
|
|
576
|
+
"stringview_iter.slice",
|
|
577
|
+
16449712,
|
|
578
|
+
"string.new_utf8_array",
|
|
579
|
+
"string.new_wtf16_array",
|
|
580
|
+
"string.encode_utf8_array",
|
|
581
|
+
"string.encode_wtf16_array",
|
|
582
|
+
"string.new_lossy_utf8_array",
|
|
583
|
+
"string.new_wtf8_array",
|
|
584
|
+
"string.encode_lossy_utf8_array",
|
|
585
|
+
"string.encode_wtf8_array",
|
|
586
|
+
// 0xfc: Bulk memory/table operations + rounding mode control
|
|
587
|
+
16515072,
|
|
588
|
+
"i32.trunc_sat_f32_s",
|
|
589
|
+
"i32.trunc_sat_f32_u",
|
|
590
|
+
"i32.trunc_sat_f64_s",
|
|
591
|
+
"i32.trunc_sat_f64_u",
|
|
592
|
+
"i64.trunc_sat_f32_s",
|
|
593
|
+
"i64.trunc_sat_f32_u",
|
|
594
|
+
"i64.trunc_sat_f64_s",
|
|
595
|
+
"i64.trunc_sat_f64_u",
|
|
596
|
+
"memory.init dataidx_memoryidx",
|
|
597
|
+
"data.drop dataidx",
|
|
598
|
+
"memory.copy memoryidx_memoryidx",
|
|
599
|
+
"memory.fill memoryidx?",
|
|
600
|
+
"table.init reversed",
|
|
601
|
+
"elem.drop elemidx",
|
|
602
|
+
"table.copy tableidx_tableidx",
|
|
603
|
+
"table.grow tableidx",
|
|
604
|
+
"table.size tableidx",
|
|
605
|
+
"table.fill tableidx",
|
|
606
|
+
16515091,
|
|
607
|
+
"i64.add128",
|
|
608
|
+
"i64.sub128",
|
|
609
|
+
"i64.mul_wide_s",
|
|
610
|
+
"i64.mul_wide_u",
|
|
611
|
+
// 0x80-0xBB: rounding mode control
|
|
612
|
+
16515200,
|
|
613
|
+
"f32.sqrt_ceil",
|
|
614
|
+
"f32.add_ceil",
|
|
615
|
+
"f32.sub_ceil",
|
|
616
|
+
"f32.mul_ceil",
|
|
617
|
+
"f32.div_ceil",
|
|
618
|
+
"f64.sqrt_ceil",
|
|
619
|
+
"f64.add_ceil",
|
|
620
|
+
"f64.sub_ceil",
|
|
621
|
+
"f64.mul_ceil",
|
|
622
|
+
"f64.div_ceil",
|
|
623
|
+
"f32.convert_ceil_i32_s",
|
|
624
|
+
"f32.convert_ceil_i32_u",
|
|
625
|
+
"f32.convert_ceil_i64_s",
|
|
626
|
+
"f32.convert_ceil_i64_u",
|
|
627
|
+
"f32.demote_ceil_f64",
|
|
628
|
+
"f64.convert_ceil_i32_s",
|
|
629
|
+
"f64.convert_ceil_i32_u",
|
|
630
|
+
"f64.convert_ceil_i64_s",
|
|
631
|
+
"f64.convert_ceil_i64_u",
|
|
632
|
+
"f64.promote_ceil_f32",
|
|
633
|
+
"f32.sqrt_floor",
|
|
634
|
+
"f32.add_floor",
|
|
635
|
+
"f32.sub_floor",
|
|
636
|
+
"f32.mul_floor",
|
|
637
|
+
"f32.div_floor",
|
|
638
|
+
"f64.sqrt_floor",
|
|
639
|
+
"f64.add_floor",
|
|
640
|
+
"f64.sub_floor",
|
|
641
|
+
"f64.mul_floor",
|
|
642
|
+
"f64.div_floor",
|
|
643
|
+
"f32.convert_floor_i32_s",
|
|
644
|
+
"f32.convert_floor_i32_u",
|
|
645
|
+
"f32.convert_floor_i64_s",
|
|
646
|
+
"f32.convert_floor_i64_u",
|
|
647
|
+
"f32.demote_floor_f64",
|
|
648
|
+
"f64.convert_floor_i32_s",
|
|
649
|
+
"f64.convert_floor_i32_u",
|
|
650
|
+
"f64.convert_floor_i64_s",
|
|
651
|
+
"f64.convert_floor_i64_u",
|
|
652
|
+
"f64.promote_floor_f32",
|
|
653
|
+
"f32.sqrt_trunc",
|
|
654
|
+
"f32.add_trunc",
|
|
655
|
+
"f32.sub_trunc",
|
|
656
|
+
"f32.mul_trunc",
|
|
657
|
+
"f32.div_trunc",
|
|
658
|
+
"f64.sqrt_trunc",
|
|
659
|
+
"f64.add_trunc",
|
|
660
|
+
"f64.sub_trunc",
|
|
661
|
+
"f64.mul_trunc",
|
|
662
|
+
"f64.div_trunc",
|
|
663
|
+
"f32.convert_trunc_i32_s",
|
|
664
|
+
"f32.convert_trunc_i32_u",
|
|
665
|
+
"f32.convert_trunc_i64_s",
|
|
666
|
+
"f32.convert_trunc_i64_u",
|
|
667
|
+
"f32.demote_trunc_f64",
|
|
668
|
+
"f64.convert_trunc_i32_s",
|
|
669
|
+
"f64.convert_trunc_i32_u",
|
|
670
|
+
"f64.convert_trunc_i64_s",
|
|
671
|
+
"f64.convert_trunc_i64_u",
|
|
672
|
+
"f64.promote_trunc_f32",
|
|
673
|
+
// 0xfd: SIMD instructions
|
|
674
|
+
16580608,
|
|
675
|
+
"v128.load memarg",
|
|
676
|
+
"v128.load8x8_s memarg",
|
|
677
|
+
"v128.load8x8_u memarg",
|
|
678
|
+
"v128.load16x4_s memarg",
|
|
679
|
+
"v128.load16x4_u memarg",
|
|
680
|
+
"v128.load32x2_s memarg",
|
|
681
|
+
"v128.load32x2_u memarg",
|
|
682
|
+
"v128.load8_splat memarg",
|
|
683
|
+
"v128.load16_splat memarg",
|
|
684
|
+
"v128.load32_splat memarg",
|
|
685
|
+
"v128.load64_splat memarg",
|
|
686
|
+
"v128.store memarg",
|
|
687
|
+
"v128.const v128const",
|
|
688
|
+
"i8x16.shuffle shuffle",
|
|
689
|
+
"i8x16.swizzle",
|
|
690
|
+
"i8x16.splat",
|
|
691
|
+
"i16x8.splat",
|
|
692
|
+
"i32x4.splat",
|
|
693
|
+
"i64x2.splat",
|
|
694
|
+
"f32x4.splat",
|
|
695
|
+
"f64x2.splat",
|
|
696
|
+
"i8x16.extract_lane_s laneidx",
|
|
697
|
+
"i8x16.extract_lane_u laneidx",
|
|
698
|
+
"i8x16.replace_lane laneidx",
|
|
699
|
+
"i16x8.extract_lane_s laneidx",
|
|
700
|
+
"i16x8.extract_lane_u laneidx",
|
|
701
|
+
"i16x8.replace_lane laneidx",
|
|
702
|
+
"i32x4.extract_lane laneidx",
|
|
703
|
+
"i32x4.replace_lane laneidx",
|
|
704
|
+
"i64x2.extract_lane laneidx",
|
|
705
|
+
"i64x2.replace_lane laneidx",
|
|
706
|
+
"f32x4.extract_lane laneidx",
|
|
707
|
+
"f32x4.replace_lane laneidx",
|
|
708
|
+
"f64x2.extract_lane laneidx",
|
|
709
|
+
"f64x2.replace_lane laneidx",
|
|
710
|
+
"i8x16.eq",
|
|
711
|
+
"i8x16.ne",
|
|
712
|
+
"i8x16.lt_s",
|
|
713
|
+
"i8x16.lt_u",
|
|
714
|
+
"i8x16.gt_s",
|
|
715
|
+
"i8x16.gt_u",
|
|
716
|
+
"i8x16.le_s",
|
|
717
|
+
"i8x16.le_u",
|
|
718
|
+
"i8x16.ge_s",
|
|
719
|
+
"i8x16.ge_u",
|
|
720
|
+
"i16x8.eq",
|
|
721
|
+
"i16x8.ne",
|
|
722
|
+
"i16x8.lt_s",
|
|
723
|
+
"i16x8.lt_u",
|
|
724
|
+
"i16x8.gt_s",
|
|
725
|
+
"i16x8.gt_u",
|
|
726
|
+
"i16x8.le_s",
|
|
727
|
+
"i16x8.le_u",
|
|
728
|
+
"i16x8.ge_s",
|
|
729
|
+
"i16x8.ge_u",
|
|
730
|
+
"i32x4.eq",
|
|
731
|
+
"i32x4.ne",
|
|
732
|
+
"i32x4.lt_s",
|
|
733
|
+
"i32x4.lt_u",
|
|
734
|
+
"i32x4.gt_s",
|
|
735
|
+
"i32x4.gt_u",
|
|
736
|
+
"i32x4.le_s",
|
|
737
|
+
"i32x4.le_u",
|
|
738
|
+
"i32x4.ge_s",
|
|
739
|
+
"i32x4.ge_u",
|
|
740
|
+
"f32x4.eq",
|
|
741
|
+
"f32x4.ne",
|
|
742
|
+
"f32x4.lt",
|
|
743
|
+
"f32x4.gt",
|
|
744
|
+
"f32x4.le",
|
|
745
|
+
"f32x4.ge",
|
|
746
|
+
"f64x2.eq",
|
|
747
|
+
"f64x2.ne",
|
|
748
|
+
"f64x2.lt",
|
|
749
|
+
"f64x2.gt",
|
|
750
|
+
"f64x2.le",
|
|
751
|
+
"f64x2.ge",
|
|
752
|
+
"v128.not",
|
|
753
|
+
"v128.and",
|
|
754
|
+
"v128.andnot",
|
|
755
|
+
"v128.or",
|
|
756
|
+
"v128.xor",
|
|
757
|
+
"v128.bitselect",
|
|
758
|
+
"v128.any_true",
|
|
759
|
+
"v128.load8_lane memlane",
|
|
760
|
+
"v128.load16_lane memlane",
|
|
761
|
+
"v128.load32_lane memlane",
|
|
762
|
+
"v128.load64_lane memlane",
|
|
763
|
+
"v128.store8_lane memlane",
|
|
764
|
+
"v128.store16_lane memlane",
|
|
765
|
+
"v128.store32_lane memlane",
|
|
766
|
+
"v128.store64_lane memlane",
|
|
767
|
+
"v128.load32_zero memarg",
|
|
768
|
+
"v128.load64_zero memarg",
|
|
769
|
+
"f32x4.demote_f64x2_zero",
|
|
770
|
+
"f64x2.promote_low_f32x4",
|
|
771
|
+
"i8x16.abs",
|
|
772
|
+
"i8x16.neg",
|
|
773
|
+
"i8x16.popcnt",
|
|
774
|
+
"i8x16.all_true",
|
|
775
|
+
"i8x16.bitmask",
|
|
776
|
+
"i8x16.narrow_i16x8_s",
|
|
777
|
+
"i8x16.narrow_i16x8_u",
|
|
778
|
+
"f32x4.ceil",
|
|
779
|
+
"f32x4.floor",
|
|
780
|
+
"f32x4.trunc",
|
|
781
|
+
"f32x4.nearest",
|
|
782
|
+
"i8x16.shl",
|
|
783
|
+
"i8x16.shr_s",
|
|
784
|
+
"i8x16.shr_u",
|
|
785
|
+
"i8x16.add",
|
|
786
|
+
"i8x16.add_sat_s",
|
|
787
|
+
"i8x16.add_sat_u",
|
|
788
|
+
"i8x16.sub",
|
|
789
|
+
"i8x16.sub_sat_s",
|
|
790
|
+
"i8x16.sub_sat_u",
|
|
791
|
+
"f64x2.ceil",
|
|
792
|
+
"f64x2.floor",
|
|
793
|
+
"i8x16.min_s",
|
|
794
|
+
"i8x16.min_u",
|
|
795
|
+
"i8x16.max_s",
|
|
796
|
+
"i8x16.max_u",
|
|
797
|
+
"f64x2.trunc",
|
|
798
|
+
"i8x16.avgr_u",
|
|
799
|
+
"i16x8.extadd_pairwise_i8x16_s",
|
|
800
|
+
"i16x8.extadd_pairwise_i8x16_u",
|
|
801
|
+
"i32x4.extadd_pairwise_i16x8_s",
|
|
802
|
+
"i32x4.extadd_pairwise_i16x8_u",
|
|
803
|
+
"i16x8.abs",
|
|
804
|
+
"i16x8.neg",
|
|
805
|
+
"i16x8.q15mulr_sat_s",
|
|
806
|
+
"i16x8.all_true",
|
|
807
|
+
"i16x8.bitmask",
|
|
808
|
+
"i16x8.narrow_i32x4_s",
|
|
809
|
+
"i16x8.narrow_i32x4_u",
|
|
810
|
+
"i16x8.extend_low_i8x16_s",
|
|
811
|
+
"i16x8.extend_high_i8x16_s",
|
|
812
|
+
"i16x8.extend_low_i8x16_u",
|
|
813
|
+
"i16x8.extend_high_i8x16_u",
|
|
814
|
+
"i16x8.shl",
|
|
815
|
+
"i16x8.shr_s",
|
|
816
|
+
"i16x8.shr_u",
|
|
817
|
+
"i16x8.add",
|
|
818
|
+
"i16x8.add_sat_s",
|
|
819
|
+
"i16x8.add_sat_u",
|
|
820
|
+
"i16x8.sub",
|
|
821
|
+
"i16x8.sub_sat_s",
|
|
822
|
+
"i16x8.sub_sat_u",
|
|
823
|
+
"f64x2.nearest",
|
|
824
|
+
"i16x8.mul",
|
|
825
|
+
"i16x8.min_s",
|
|
826
|
+
"i16x8.min_u",
|
|
827
|
+
"i16x8.max_s",
|
|
828
|
+
"i16x8.max_u",
|
|
829
|
+
16580763,
|
|
830
|
+
"i16x8.avgr_u",
|
|
831
|
+
"i16x8.extmul_low_i8x16_s",
|
|
832
|
+
"i16x8.extmul_high_i8x16_s",
|
|
833
|
+
"i16x8.extmul_low_i8x16_u",
|
|
834
|
+
"i16x8.extmul_high_i8x16_u",
|
|
835
|
+
"i32x4.abs",
|
|
836
|
+
"i32x4.neg",
|
|
837
|
+
16580771,
|
|
838
|
+
"i32x4.all_true",
|
|
839
|
+
"i32x4.bitmask",
|
|
840
|
+
16580775,
|
|
841
|
+
"i32x4.extend_low_i16x8_s",
|
|
842
|
+
"i32x4.extend_high_i16x8_s",
|
|
843
|
+
"i32x4.extend_low_i16x8_u",
|
|
844
|
+
"i32x4.extend_high_i16x8_u",
|
|
845
|
+
"i32x4.shl",
|
|
846
|
+
"i32x4.shr_s",
|
|
847
|
+
"i32x4.shr_u",
|
|
848
|
+
"i32x4.add",
|
|
849
|
+
16580785,
|
|
850
|
+
"i32x4.sub",
|
|
851
|
+
16580789,
|
|
852
|
+
"i32x4.mul",
|
|
853
|
+
"i32x4.min_s",
|
|
854
|
+
"i32x4.min_u",
|
|
855
|
+
"i32x4.max_s",
|
|
856
|
+
"i32x4.max_u",
|
|
857
|
+
"i32x4.dot_i16x8_s",
|
|
858
|
+
16580796,
|
|
859
|
+
"i32x4.extmul_low_i16x8_s",
|
|
860
|
+
"i32x4.extmul_high_i16x8_s",
|
|
861
|
+
"i32x4.extmul_low_i16x8_u",
|
|
862
|
+
"i32x4.extmul_high_i16x8_u",
|
|
863
|
+
"i64x2.abs",
|
|
864
|
+
"i64x2.neg",
|
|
865
|
+
16580803,
|
|
866
|
+
"i64x2.all_true",
|
|
867
|
+
"i64x2.bitmask",
|
|
868
|
+
16580807,
|
|
869
|
+
"i64x2.extend_low_i32x4_s",
|
|
870
|
+
"i64x2.extend_high_i32x4_s",
|
|
871
|
+
"i64x2.extend_low_i32x4_u",
|
|
872
|
+
"i64x2.extend_high_i32x4_u",
|
|
873
|
+
"i64x2.shl",
|
|
874
|
+
"i64x2.shr_s",
|
|
875
|
+
"i64x2.shr_u",
|
|
876
|
+
"i64x2.add",
|
|
877
|
+
16580817,
|
|
878
|
+
"i64x2.sub",
|
|
879
|
+
16580821,
|
|
880
|
+
"i64x2.mul",
|
|
881
|
+
"i64x2.eq",
|
|
882
|
+
"i64x2.ne",
|
|
883
|
+
"i64x2.lt_s",
|
|
884
|
+
"i64x2.gt_s",
|
|
885
|
+
"i64x2.le_s",
|
|
886
|
+
"i64x2.ge_s",
|
|
887
|
+
"i64x2.extmul_low_i32x4_s",
|
|
888
|
+
"i64x2.extmul_high_i32x4_s",
|
|
889
|
+
"i64x2.extmul_low_i32x4_u",
|
|
890
|
+
"i64x2.extmul_high_i32x4_u",
|
|
891
|
+
"f32x4.abs",
|
|
892
|
+
"f32x4.neg",
|
|
893
|
+
16580835,
|
|
894
|
+
"f32x4.sqrt",
|
|
895
|
+
"f32x4.add",
|
|
896
|
+
"f32x4.sub",
|
|
897
|
+
"f32x4.mul",
|
|
898
|
+
"f32x4.div",
|
|
899
|
+
"f32x4.min",
|
|
900
|
+
"f32x4.max",
|
|
901
|
+
"f32x4.pmin",
|
|
902
|
+
"f32x4.pmax",
|
|
903
|
+
"f64x2.abs",
|
|
904
|
+
"f64x2.neg",
|
|
905
|
+
16580847,
|
|
906
|
+
"f64x2.sqrt",
|
|
907
|
+
"f64x2.add",
|
|
908
|
+
"f64x2.sub",
|
|
909
|
+
"f64x2.mul",
|
|
910
|
+
"f64x2.div",
|
|
911
|
+
"f64x2.min",
|
|
912
|
+
"f64x2.max",
|
|
913
|
+
"f64x2.pmin",
|
|
914
|
+
"f64x2.pmax",
|
|
915
|
+
"i32x4.trunc_sat_f32x4_s",
|
|
916
|
+
"i32x4.trunc_sat_f32x4_u",
|
|
917
|
+
"f32x4.convert_i32x4_s",
|
|
918
|
+
"f32x4.convert_i32x4_u",
|
|
919
|
+
"i32x4.trunc_sat_f64x2_s_zero",
|
|
920
|
+
"i32x4.trunc_sat_f64x2_u_zero",
|
|
921
|
+
"f64x2.convert_low_i32x4_s",
|
|
922
|
+
"f64x2.convert_low_i32x4_u",
|
|
923
|
+
"i8x16.relaxed_swizzle",
|
|
924
|
+
"i32x4.relaxed_trunc_f32x4_s",
|
|
925
|
+
"i32x4.relaxed_trunc_f32x4_u",
|
|
926
|
+
"i32x4.relaxed_trunc_f64x2_s_zero",
|
|
927
|
+
"i32x4.relaxed_trunc_f64x2_u_zero",
|
|
928
|
+
"f32x4.relaxed_madd",
|
|
929
|
+
"f32x4.relaxed_nmadd",
|
|
930
|
+
"f64x2.relaxed_madd",
|
|
931
|
+
"f64x2.relaxed_nmadd",
|
|
932
|
+
"i8x16.relaxed_laneselect",
|
|
933
|
+
"i16x8.relaxed_laneselect",
|
|
934
|
+
"i32x4.relaxed_laneselect",
|
|
935
|
+
"i64x2.relaxed_laneselect",
|
|
936
|
+
"f32x4.relaxed_min",
|
|
937
|
+
"f32x4.relaxed_max",
|
|
938
|
+
"f64x2.relaxed_min",
|
|
939
|
+
"f64x2.relaxed_max",
|
|
940
|
+
"i16x8.relaxed_q15mulr_s",
|
|
941
|
+
"i16x8.relaxed_dot_i8x16_i7x16_s",
|
|
942
|
+
"i32x4.relaxed_dot_i8x16_i7x16_add_s",
|
|
1163
943
|
// 0xfe: atomic/thread instructions
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
"i32.atomic.rmw16.xchg_u memarg",
|
|
1234
|
-
"i64.atomic.rmw8.xchg_u memarg",
|
|
1235
|
-
"i64.atomic.rmw16.xchg_u memarg",
|
|
1236
|
-
"i64.atomic.rmw32.xchg_u memarg",
|
|
1237
|
-
"i32.atomic.rmw.cmpxchg memarg",
|
|
1238
|
-
"i64.atomic.rmw.cmpxchg memarg",
|
|
1239
|
-
"i32.atomic.rmw8.cmpxchg_u memarg",
|
|
1240
|
-
"i32.atomic.rmw16.cmpxchg_u memarg",
|
|
1241
|
-
"i64.atomic.rmw8.cmpxchg_u memarg",
|
|
1242
|
-
"i64.atomic.rmw16.cmpxchg_u memarg",
|
|
1243
|
-
"i64.atomic.rmw32.cmpxchg_u memarg"
|
|
1244
|
-
]
|
|
944
|
+
16646144,
|
|
945
|
+
"memory.atomic.notify memarg",
|
|
946
|
+
"memory.atomic.wait32 memarg",
|
|
947
|
+
"memory.atomic.wait64 memarg",
|
|
948
|
+
"atomic.fence opt_memory",
|
|
949
|
+
16646160,
|
|
950
|
+
"i32.atomic.load memarg",
|
|
951
|
+
"i64.atomic.load memarg",
|
|
952
|
+
"i32.atomic.load8_u memarg",
|
|
953
|
+
"i32.atomic.load16_u memarg",
|
|
954
|
+
"i64.atomic.load8_u memarg",
|
|
955
|
+
"i64.atomic.load16_u memarg",
|
|
956
|
+
"i64.atomic.load32_u memarg",
|
|
957
|
+
"i32.atomic.store memarg",
|
|
958
|
+
"i64.atomic.store memarg",
|
|
959
|
+
"i32.atomic.store8 memarg",
|
|
960
|
+
"i32.atomic.store16 memarg",
|
|
961
|
+
"i64.atomic.store8 memarg",
|
|
962
|
+
"i64.atomic.store16 memarg",
|
|
963
|
+
"i64.atomic.store32 memarg",
|
|
964
|
+
"i32.atomic.rmw.add memarg",
|
|
965
|
+
"i64.atomic.rmw.add memarg",
|
|
966
|
+
"i32.atomic.rmw8.add_u memarg",
|
|
967
|
+
"i32.atomic.rmw16.add_u memarg",
|
|
968
|
+
"i64.atomic.rmw8.add_u memarg",
|
|
969
|
+
"i64.atomic.rmw16.add_u memarg",
|
|
970
|
+
"i64.atomic.rmw32.add_u memarg",
|
|
971
|
+
"i32.atomic.rmw.sub memarg",
|
|
972
|
+
"i64.atomic.rmw.sub memarg",
|
|
973
|
+
"i32.atomic.rmw8.sub_u memarg",
|
|
974
|
+
"i32.atomic.rmw16.sub_u memarg",
|
|
975
|
+
"i64.atomic.rmw8.sub_u memarg",
|
|
976
|
+
"i64.atomic.rmw16.sub_u memarg",
|
|
977
|
+
"i64.atomic.rmw32.sub_u memarg",
|
|
978
|
+
"i32.atomic.rmw.and memarg",
|
|
979
|
+
"i64.atomic.rmw.and memarg",
|
|
980
|
+
"i32.atomic.rmw8.and_u memarg",
|
|
981
|
+
"i32.atomic.rmw16.and_u memarg",
|
|
982
|
+
"i64.atomic.rmw8.and_u memarg",
|
|
983
|
+
"i64.atomic.rmw16.and_u memarg",
|
|
984
|
+
"i64.atomic.rmw32.and_u memarg",
|
|
985
|
+
"i32.atomic.rmw.or memarg",
|
|
986
|
+
"i64.atomic.rmw.or memarg",
|
|
987
|
+
"i32.atomic.rmw8.or_u memarg",
|
|
988
|
+
"i32.atomic.rmw16.or_u memarg",
|
|
989
|
+
"i64.atomic.rmw8.or_u memarg",
|
|
990
|
+
"i64.atomic.rmw16.or_u memarg",
|
|
991
|
+
"i64.atomic.rmw32.or_u memarg",
|
|
992
|
+
"i32.atomic.rmw.xor memarg",
|
|
993
|
+
"i64.atomic.rmw.xor memarg",
|
|
994
|
+
"i32.atomic.rmw8.xor_u memarg",
|
|
995
|
+
"i32.atomic.rmw16.xor_u memarg",
|
|
996
|
+
"i64.atomic.rmw8.xor_u memarg",
|
|
997
|
+
"i64.atomic.rmw16.xor_u memarg",
|
|
998
|
+
"i64.atomic.rmw32.xor_u memarg",
|
|
999
|
+
"i32.atomic.rmw.xchg memarg",
|
|
1000
|
+
"i64.atomic.rmw.xchg memarg",
|
|
1001
|
+
"i32.atomic.rmw8.xchg_u memarg",
|
|
1002
|
+
"i32.atomic.rmw16.xchg_u memarg",
|
|
1003
|
+
"i64.atomic.rmw8.xchg_u memarg",
|
|
1004
|
+
"i64.atomic.rmw16.xchg_u memarg",
|
|
1005
|
+
"i64.atomic.rmw32.xchg_u memarg",
|
|
1006
|
+
"i32.atomic.rmw.cmpxchg memarg",
|
|
1007
|
+
"i64.atomic.rmw.cmpxchg memarg",
|
|
1008
|
+
"i32.atomic.rmw8.cmpxchg_u memarg",
|
|
1009
|
+
"i32.atomic.rmw16.cmpxchg_u memarg",
|
|
1010
|
+
"i64.atomic.rmw8.cmpxchg_u memarg",
|
|
1011
|
+
"i64.atomic.rmw16.cmpxchg_u memarg",
|
|
1012
|
+
"i64.atomic.rmw32.cmpxchg_u memarg"
|
|
1245
1013
|
];
|
|
1014
|
+
var OPCODE = {};
|
|
1015
|
+
var IMM = {};
|
|
1016
|
+
for (let i = 0, code = 0; i < TABLE.length; i++) {
|
|
1017
|
+
const item = TABLE[i];
|
|
1018
|
+
if (typeof item === "number") {
|
|
1019
|
+
code = item;
|
|
1020
|
+
continue;
|
|
1021
|
+
}
|
|
1022
|
+
const sp = item.indexOf(" ");
|
|
1023
|
+
const nm = sp < 0 ? item : item.slice(0, sp);
|
|
1024
|
+
if (sp >= 0) IMM[nm] = item.slice(sp + 1);
|
|
1025
|
+
OPCODE[nm] = code++;
|
|
1026
|
+
}
|
|
1246
1027
|
var resultType = (op) => {
|
|
1247
1028
|
if (typeof op !== "string") return null;
|
|
1248
1029
|
const dot = op.indexOf(".");
|
|
@@ -1356,7 +1137,7 @@ var parse_default = (str2) => {
|
|
|
1356
1137
|
};
|
|
1357
1138
|
|
|
1358
1139
|
// src/compile.js
|
|
1359
|
-
var isDroppable = (n) => typeof n === "string" && (n[0] === ";" || n[1] === ";") || Array.isArray(n) && n[0]?.[0] === "@" && n[0] !== "@custom" && !n[0]?.startsWith?.("@metadata.code.");
|
|
1140
|
+
var isDroppable = (n) => typeof n === "string" && (n[0] === ";" || n[0] === "(" && n[1] === ";") || Array.isArray(n) && n[0]?.[0] === "@" && n[0] !== "@custom" && !n[0]?.startsWith?.("@metadata.code.");
|
|
1360
1141
|
var cleanup = (node, result) => {
|
|
1361
1142
|
if (typeof node === "string") return (
|
|
1362
1143
|
// normalize quoted ids: $"name" -> $name (if no escapes), else $unescaped
|
|
@@ -1371,9 +1152,9 @@ var cleanup = (node, result) => {
|
|
|
1371
1152
|
return result.length === 1 && result[0]?.[0] === "module" ? result[0] : result;
|
|
1372
1153
|
};
|
|
1373
1154
|
function assemble(nodes, sizeOnly) {
|
|
1374
|
-
if (typeof nodes === "string")
|
|
1375
|
-
else
|
|
1376
|
-
|
|
1155
|
+
if (typeof nodes === "string") setErrSrc(nodes), nodes = parse_default(nodes) || [];
|
|
1156
|
+
else setErrSrc("");
|
|
1157
|
+
setErrLoc(0);
|
|
1377
1158
|
nodes = isDroppable(nodes) ? [] : cleanup(nodes) ?? [];
|
|
1378
1159
|
let idx = 0;
|
|
1379
1160
|
if (nodes[0] === "module") idx++, isId(nodes[idx]) && idx++;
|
|
@@ -1399,7 +1180,7 @@ function assemble(nodes, sizeOnly) {
|
|
|
1399
1180
|
ctx.metadata = {};
|
|
1400
1181
|
nodes.slice(idx).filter((n) => {
|
|
1401
1182
|
if (!Array.isArray(n)) {
|
|
1402
|
-
let pos =
|
|
1183
|
+
let pos = getErrLoc(), src = getErrSrc(), c;
|
|
1403
1184
|
while ((pos = src.indexOf(n, pos)) >= 0) {
|
|
1404
1185
|
c = src.charCodeAt(pos - 1);
|
|
1405
1186
|
if (pos > 0 && (c > 47 && c < 58 || c > 64 && c < 91 || c > 96 && c < 123 || c === 95 || c === 36)) {
|
|
@@ -1413,11 +1194,11 @@ function assemble(nodes, sizeOnly) {
|
|
|
1413
1194
|
}
|
|
1414
1195
|
break;
|
|
1415
1196
|
}
|
|
1416
|
-
if (pos >= 0)
|
|
1197
|
+
if (pos >= 0) setErrLoc(pos);
|
|
1417
1198
|
err(`Unexpected token ${n}`);
|
|
1418
1199
|
}
|
|
1419
1200
|
let [kind, ...node] = n;
|
|
1420
|
-
|
|
1201
|
+
setErrLoc(n.loc);
|
|
1421
1202
|
if (kind === "@custom") {
|
|
1422
1203
|
ctx.custom.push(node);
|
|
1423
1204
|
} else if (kind === "rec") {
|
|
@@ -1441,7 +1222,7 @@ function assemble(nodes, sizeOnly) {
|
|
|
1441
1222
|
else return true;
|
|
1442
1223
|
}).forEach((n) => {
|
|
1443
1224
|
let [kind, ...node] = n;
|
|
1444
|
-
|
|
1225
|
+
setErrLoc(n.loc);
|
|
1445
1226
|
let imported;
|
|
1446
1227
|
if (kind === "import") [kind, ...node] = (imported = node).pop();
|
|
1447
1228
|
let items = ctx[kind];
|
|
@@ -1522,7 +1303,13 @@ function assemble(nodes, sizeOnly) {
|
|
|
1522
1303
|
return 8 + codeSecLen + others.reduce((s, sec) => s + sec.length, 0);
|
|
1523
1304
|
}
|
|
1524
1305
|
const codeItems = ctx.code.filter(Boolean).map((item) => build[SECTION.code](item, ctx)).filter(Boolean);
|
|
1525
|
-
|
|
1306
|
+
let codeSection = [];
|
|
1307
|
+
if (codeItems.length) {
|
|
1308
|
+
const inner = uleb(codeItems.length);
|
|
1309
|
+
for (const it of codeItems) for (let i = 0; i < it.length; i++) inner.push(it[i]);
|
|
1310
|
+
codeSection = [SECTION.code, ...uleb(inner.length)];
|
|
1311
|
+
for (let i = 0; i < inner.length; i++) codeSection.push(inner[i]);
|
|
1312
|
+
}
|
|
1526
1313
|
const metaSection = binMeta();
|
|
1527
1314
|
const dataSection = bin(SECTION.data);
|
|
1528
1315
|
const stringsSection = ctx.strings.length ? [SECTION.strings, ...vec([0, ...vec(ctx.strings.map((s) => vec(s)))])] : [];
|
|
@@ -1544,19 +1331,17 @@ function assemble(nodes, sizeOnly) {
|
|
|
1544
1331
|
metaSection,
|
|
1545
1332
|
dataSection
|
|
1546
1333
|
];
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
...sections.flat()
|
|
1559
|
-
]);
|
|
1334
|
+
let total = 8;
|
|
1335
|
+
for (const sec of sections) total += sec.length;
|
|
1336
|
+
const wasm = new Uint8Array(total);
|
|
1337
|
+
wasm.set([0, 97, 115, 109, 1, 0, 0, 0]);
|
|
1338
|
+
let off = 8;
|
|
1339
|
+
for (const sec of sections) {
|
|
1340
|
+
if (sec.length) {
|
|
1341
|
+
wasm.set(sec, off);
|
|
1342
|
+
off += sec.length;
|
|
1343
|
+
}
|
|
1344
|
+
}
|
|
1560
1345
|
const md = metadataOffsets();
|
|
1561
1346
|
if (md) wasm.metadata = md;
|
|
1562
1347
|
return wasm;
|
|
@@ -1568,9 +1353,9 @@ function assemble(nodes, sizeOnly) {
|
|
|
1568
1353
|
const codeBase = 8 + sections.slice(0, sections.indexOf(codeSection)).reduce((n, s) => n + s.length, 0);
|
|
1569
1354
|
const itemsBase = codeBase + codeSection.length - codeItems.reduce((n, it) => n + it.length, 0);
|
|
1570
1355
|
const bodyBase = [];
|
|
1571
|
-
for (let i = 0,
|
|
1572
|
-
bodyBase[i] =
|
|
1573
|
-
|
|
1356
|
+
for (let i = 0, off2 = itemsBase; i < codeItems.length; i++) {
|
|
1357
|
+
bodyBase[i] = off2 + (ctx.codeSizePrefix?.[i] ?? 0);
|
|
1358
|
+
off2 += codeItems[i].length;
|
|
1574
1359
|
}
|
|
1575
1360
|
const importedFuncs = ctx.import.filter((imp) => imp[2][0] === "func").length;
|
|
1576
1361
|
for (const type in ctx.metadata) {
|
|
@@ -1590,41 +1375,61 @@ function compile(nodes) {
|
|
|
1590
1375
|
var isIdx = (n) => n?.[0] === "$" || !isNaN(n);
|
|
1591
1376
|
var isId = (n) => n?.[0] === "$";
|
|
1592
1377
|
var isMemParam = (n) => n?.[0] === "a" || n?.[0] === "o";
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1378
|
+
var NCLS = null;
|
|
1379
|
+
var nclsOf = (op) => {
|
|
1380
|
+
if (!NCLS) {
|
|
1381
|
+
NCLS = /* @__PURE__ */ Object.create(null);
|
|
1382
|
+
for (const k in OPCODE) {
|
|
1383
|
+
if (k === "block" || k === "if" || k === "loop") NCLS[k] = 1;
|
|
1384
|
+
else if (k === "else" || k === "end") NCLS[k] = 2;
|
|
1385
|
+
else if (k === "select") NCLS[k] = 3;
|
|
1386
|
+
else if (k.endsWith("call_indirect")) NCLS[k] = 4;
|
|
1387
|
+
else if (k === "table.init") NCLS[k] = 5;
|
|
1388
|
+
else if (k === "table.copy" || k === "memory.copy") NCLS[k] = 6;
|
|
1389
|
+
else if (k.startsWith("table.")) NCLS[k] = 7;
|
|
1390
|
+
else if (k === "memory.init") NCLS[k] = 8;
|
|
1391
|
+
else if (k === "data.drop" || k === "array.new_data" || k === "array.init_data") NCLS[k] = 9;
|
|
1392
|
+
else if (k.startsWith("memory.") || k.endsWith("load") || k.endsWith("store")) NCLS[k] = 10;
|
|
1393
|
+
}
|
|
1394
|
+
}
|
|
1395
|
+
return NCLS[op];
|
|
1396
|
+
};
|
|
1397
|
+
function normalize(nodes, ctx, out = [], owned = false) {
|
|
1398
|
+
if (!owned) nodes = [...nodes];
|
|
1596
1399
|
while (nodes.length) {
|
|
1597
1400
|
let node = nodes.shift();
|
|
1598
1401
|
if (typeof node === "string") {
|
|
1599
1402
|
out.push(node);
|
|
1600
|
-
|
|
1403
|
+
const cls = nclsOf(node);
|
|
1404
|
+
if (cls === void 0) continue;
|
|
1405
|
+
if (cls === 1) {
|
|
1601
1406
|
if (isId(nodes[0])) out.push(nodes.shift());
|
|
1602
1407
|
out.push(blocktype(nodes, ctx));
|
|
1603
|
-
} else if (
|
|
1408
|
+
} else if (cls === 2) {
|
|
1604
1409
|
if (isId(nodes[0])) nodes.shift();
|
|
1605
|
-
} else if (
|
|
1606
|
-
else if (
|
|
1410
|
+
} else if (cls === 3) out.push(paramres(nodes)[1]);
|
|
1411
|
+
else if (cls === 4) {
|
|
1607
1412
|
let tableidx = isIdx(nodes[0]) ? nodes.shift() : 0, [idx, param, result] = typeuse(nodes, ctx);
|
|
1608
1413
|
out.push(tableidx, ["type", idx ?? regtype(param, result, ctx)]);
|
|
1609
|
-
} else if (
|
|
1610
|
-
else if (
|
|
1611
|
-
else if (
|
|
1612
|
-
else if (
|
|
1414
|
+
} else if (cls === 5) out.push(isIdx(nodes[1]) ? nodes.shift() : 0, nodes.shift());
|
|
1415
|
+
else if (cls === 6) out.push(isIdx(nodes[0]) ? nodes.shift() : 0, isIdx(nodes[0]) ? nodes.shift() : 0);
|
|
1416
|
+
else if (cls === 7) out.push(isIdx(nodes[0]) ? nodes.shift() : 0);
|
|
1417
|
+
else if (cls === 8) {
|
|
1613
1418
|
out.push(...isIdx(nodes[1]) ? [nodes.shift(), nodes.shift()].reverse() : [nodes.shift(), 0]);
|
|
1614
1419
|
ctx.datacount && (ctx.datacount[0] = true);
|
|
1615
|
-
} else if (
|
|
1420
|
+
} else if (cls === 9) {
|
|
1616
1421
|
node === "data.drop" && out.push(nodes.shift());
|
|
1617
1422
|
ctx.datacount && (ctx.datacount[0] = true);
|
|
1618
|
-
} else if (
|
|
1423
|
+
} else if (isIdx(nodes[0])) out.push(nodes.shift());
|
|
1619
1424
|
} else if (Array.isArray(node)) {
|
|
1620
1425
|
let op = node[0];
|
|
1621
|
-
node.loc != null && (
|
|
1426
|
+
node.loc != null && setErrLoc(node.loc);
|
|
1622
1427
|
if (op?.startsWith?.("@metadata.code.")) {
|
|
1623
1428
|
let type = op.slice(15);
|
|
1624
1429
|
out.push(["@metadata", type, node[1]]);
|
|
1625
1430
|
continue;
|
|
1626
1431
|
}
|
|
1627
|
-
if (typeof op !== "string" ||
|
|
1432
|
+
if (typeof op !== "string" || typeof OPCODE[op] !== "number") {
|
|
1628
1433
|
out.push(node);
|
|
1629
1434
|
continue;
|
|
1630
1435
|
}
|
|
@@ -1632,16 +1437,23 @@ function normalize(nodes, ctx) {
|
|
|
1632
1437
|
if (op === "block" || op === "loop") {
|
|
1633
1438
|
out.push(op);
|
|
1634
1439
|
if (isId(parts[0])) out.push(parts.shift());
|
|
1635
|
-
out.push(blocktype(parts, ctx)
|
|
1440
|
+
out.push(blocktype(parts, ctx));
|
|
1441
|
+
normalize(parts, ctx, out, true);
|
|
1442
|
+
out.push("end");
|
|
1636
1443
|
} else if (op === "if") {
|
|
1637
1444
|
let then = [], els = [];
|
|
1638
|
-
if (parts.at(-1)?.[0] === "else") els = normalize(parts.pop().slice(1), ctx);
|
|
1639
|
-
if (parts.at(-1)?.[0] === "then") then = normalize(parts.pop().slice(1), ctx);
|
|
1445
|
+
if (parts.at(-1)?.[0] === "else") els = normalize(parts.pop().slice(1), ctx, [], true);
|
|
1446
|
+
if (parts.at(-1)?.[0] === "then") then = normalize(parts.pop().slice(1), ctx, [], true);
|
|
1640
1447
|
let immed = [op];
|
|
1641
1448
|
if (isId(parts[0])) immed.push(parts.shift());
|
|
1642
1449
|
immed.push(blocktype(parts, ctx));
|
|
1643
|
-
|
|
1644
|
-
|
|
1450
|
+
normalize(parts, ctx, out, true);
|
|
1451
|
+
for (let i = 0; i < immed.length; i++) out.push(immed[i]);
|
|
1452
|
+
for (let i = 0; i < then.length; i++) out.push(then[i]);
|
|
1453
|
+
if (els.length) {
|
|
1454
|
+
out.push("else");
|
|
1455
|
+
for (let i = 0; i < els.length; i++) out.push(els[i]);
|
|
1456
|
+
}
|
|
1645
1457
|
out.push("end");
|
|
1646
1458
|
} else if (op === "try_table") {
|
|
1647
1459
|
out.push(op);
|
|
@@ -1650,17 +1462,20 @@ function normalize(nodes, ctx) {
|
|
|
1650
1462
|
while (parts[0]?.[0] === "catch" || parts[0]?.[0] === "catch_ref" || parts[0]?.[0] === "catch_all" || parts[0]?.[0] === "catch_all_ref") {
|
|
1651
1463
|
out.push(parts.shift());
|
|
1652
1464
|
}
|
|
1653
|
-
|
|
1465
|
+
normalize(parts, ctx, out, true);
|
|
1466
|
+
out.push("end");
|
|
1654
1467
|
} else if (op === "ref.test" || op === "ref.cast") {
|
|
1655
1468
|
const type = parts[0];
|
|
1656
1469
|
const isNullable = !Array.isArray(type) || type[1] === "null" || type[0] !== "ref";
|
|
1657
1470
|
if (isNullable) op += "_null";
|
|
1658
|
-
|
|
1471
|
+
normalize(parts.slice(1), ctx, out, true);
|
|
1472
|
+
out.push(op, type);
|
|
1659
1473
|
nodes.unshift(...out.splice(out.length - 2));
|
|
1660
1474
|
} else {
|
|
1661
1475
|
const imm = [];
|
|
1662
1476
|
while (parts.length && (!Array.isArray(parts[0]) || parts[0].valueOf !== Array.prototype.valueOf || "type,param,result,ref,exact,on".includes(parts[0][0]))) imm.push(parts.shift());
|
|
1663
|
-
|
|
1477
|
+
normalize(parts, ctx, out, true);
|
|
1478
|
+
out.push(op, ...imm);
|
|
1664
1479
|
nodes.unshift(...out.splice(out.length - 1 - imm.length));
|
|
1665
1480
|
}
|
|
1666
1481
|
} else out.push(node);
|
|
@@ -1887,8 +1702,10 @@ var build = [
|
|
|
1887
1702
|
((ctx.metadata ??= {})[type] ??= []).push([funcIdx, ctx.meta[type]]);
|
|
1888
1703
|
}
|
|
1889
1704
|
ctx.local = ctx.block = ctx.meta = null;
|
|
1890
|
-
const item =
|
|
1891
|
-
(ctx.codeSizePrefix ??= [])[codeIdx] = item.length
|
|
1705
|
+
const item = uleb(locals.length + bytes.length);
|
|
1706
|
+
(ctx.codeSizePrefix ??= [])[codeIdx] = item.length;
|
|
1707
|
+
for (let i = 0; i < locals.length; i++) item.push(locals[i]);
|
|
1708
|
+
for (let i = 0; i < bytes.length; i++) item.push(bytes[i]);
|
|
1892
1709
|
return item;
|
|
1893
1710
|
},
|
|
1894
1711
|
// (data (i32.const 0) "\aa" "\bb"?)
|
|
@@ -1936,17 +1753,28 @@ var reftype = (t, ctx) => t[0] === "ref" ? t[1] == "null" ? (
|
|
|
1936
1753
|
[TYPE[t] ?? err(`Unknown type ${t}`)]
|
|
1937
1754
|
);
|
|
1938
1755
|
var fieldtype = (t, ctx, mut = t[0] === "mut" ? 1 : 0) => [...reftype(mut ? t[1] : t, ctx), mut];
|
|
1939
|
-
var
|
|
1940
|
-
|
|
1756
|
+
var wleb = (v, out) => {
|
|
1757
|
+
if (out) {
|
|
1758
|
+
uleb(v, out);
|
|
1759
|
+
return;
|
|
1760
|
+
}
|
|
1761
|
+
return uleb(v);
|
|
1762
|
+
};
|
|
1763
|
+
var HANDLER = {
|
|
1941
1764
|
reversed: (n, c) => {
|
|
1942
1765
|
let t = n.shift(), e = n.shift();
|
|
1943
1766
|
return [...uleb(id(e, c.elem)), ...uleb(id(t, c.table))];
|
|
1944
1767
|
},
|
|
1945
|
-
block: (n, c) => {
|
|
1768
|
+
block: (n, c, op, out) => {
|
|
1946
1769
|
c.block.push(1);
|
|
1947
1770
|
isId(n[0]) && (c.block[n.shift()] = c.block.length);
|
|
1948
1771
|
let t = n.shift();
|
|
1949
|
-
|
|
1772
|
+
const b = !t ? [TYPE.void] : t[0] === "result" ? reftype(t[1], c) : uleb(id(t[1], c.type));
|
|
1773
|
+
if (out) {
|
|
1774
|
+
for (let i = 0; i < b.length; i++) out.push(b[i]);
|
|
1775
|
+
return;
|
|
1776
|
+
}
|
|
1777
|
+
return b;
|
|
1950
1778
|
},
|
|
1951
1779
|
try_table: (n, c) => {
|
|
1952
1780
|
isId(n[0]) && (c.block[n.shift()] = c.block.length + 1);
|
|
@@ -1964,8 +1792,13 @@ var IMM = {
|
|
|
1964
1792
|
return [...result, ...uleb(count), ...catches];
|
|
1965
1793
|
},
|
|
1966
1794
|
end: (_n, c) => (c.block.pop(), []),
|
|
1967
|
-
call_indirect: (n, c) => {
|
|
1795
|
+
call_indirect: (n, c, op, out) => {
|
|
1968
1796
|
let t = n.shift(), [, idx] = n.shift();
|
|
1797
|
+
if (out) {
|
|
1798
|
+
uleb(id(idx, c.type), out);
|
|
1799
|
+
uleb(id(t, c.table), out);
|
|
1800
|
+
return;
|
|
1801
|
+
}
|
|
1969
1802
|
return [...uleb(id(idx, c.type)), ...uleb(id(t, c.table))];
|
|
1970
1803
|
},
|
|
1971
1804
|
br_table: (n, c) => {
|
|
@@ -1981,8 +1814,8 @@ var IMM = {
|
|
|
1981
1814
|
let t = n.shift();
|
|
1982
1815
|
return Array.isArray(t) && t[0] === "exact" ? [98, ...uleb(id(t[1], c.type))] : TYPE[t] ? [TYPE[t]] : uleb(id(t, c.type));
|
|
1983
1816
|
},
|
|
1984
|
-
memarg: (n, c, op) => memargEnc(n, op, isIdx(n[0]) && !isMemParam(n[0]) ? id(n.shift(), c.memory) : 0),
|
|
1985
|
-
opt_memory: (n, c) =>
|
|
1817
|
+
memarg: (n, c, op, out) => memargEnc(n, op, isIdx(n[0]) && !isMemParam(n[0]) ? id(n.shift(), c.memory) : 0, out),
|
|
1818
|
+
opt_memory: (n, c, op, out) => wleb(id(isIdx(n[0]) ? n.shift() : 0, c.memory), out),
|
|
1986
1819
|
reftype: (n, c) => {
|
|
1987
1820
|
let ht = reftype(n.shift(), c);
|
|
1988
1821
|
return ht.length > 1 ? ht.slice(1) : ht;
|
|
@@ -2013,30 +1846,50 @@ var IMM = {
|
|
|
2013
1846
|
const memIdx = isId(n[0]) || isIdx(n[0]) && (isMemParam(n[1]) || isIdx(n[1])) ? id(n.shift(), c.memory) : 0;
|
|
2014
1847
|
return [...memargEnc(n, op, memIdx), ...uleb(parseUint(n.shift()))];
|
|
2015
1848
|
},
|
|
2016
|
-
|
|
2017
|
-
//
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
|
|
1849
|
+
// *idx types — write-mode (out present) pushes in place and returns undefined;
|
|
1850
|
+
// return-mode hands back a fresh array. The sentinel is EXPLICIT: a boxed-
|
|
1851
|
+
// pointer identity compare (`returned !== out`) misfires under the jz kernel.
|
|
1852
|
+
labelidx: (n, c, op, out) => wleb(blockid(n.shift(), c.block), out),
|
|
1853
|
+
laneidx: (n, c, op, out) => {
|
|
1854
|
+
const v = parseUint(n.shift(), 255);
|
|
1855
|
+
if (out) {
|
|
1856
|
+
out.push(v);
|
|
1857
|
+
return;
|
|
1858
|
+
}
|
|
1859
|
+
return [v];
|
|
1860
|
+
},
|
|
1861
|
+
funcidx: (n, c, op, out) => wleb(id(n.shift(), c.func), out),
|
|
1862
|
+
typeidx: (n, c, op, out) => wleb(id(n.shift(), c.type), out),
|
|
1863
|
+
tableidx: (n, c, op, out) => wleb(id(n.shift(), c.table), out),
|
|
1864
|
+
memoryidx: (n, c, op, out) => wleb(id(n.shift(), c.memory), out),
|
|
1865
|
+
globalidx: (n, c, op, out) => wleb(id(n.shift(), c.global), out),
|
|
1866
|
+
localidx: (n, c, op, out) => wleb(id(n.shift(), c.local), out),
|
|
1867
|
+
dataidx: (n, c, op, out) => wleb(id(n.shift(), c.data), out),
|
|
1868
|
+
elemidx: (n, c, op, out) => wleb(id(n.shift(), c.elem), out),
|
|
1869
|
+
tagidx: (n, c, op, out) => wleb(id(n.shift(), c.tag), out),
|
|
1870
|
+
"memoryidx?": (n, c, op, out) => wleb(id(isIdx(n[0]) ? n.shift() : 0, c.memory), out),
|
|
1871
|
+
stringidx: (n, c, op, out) => {
|
|
2031
1872
|
let s = n.shift(), key = s.valueOf(), idx = c.strings.findIndex((x) => x.valueOf() === key);
|
|
2032
1873
|
if (idx < 0) idx = c.strings.push(s) - 1;
|
|
2033
|
-
return
|
|
1874
|
+
return wleb(idx, out);
|
|
2034
1875
|
},
|
|
2035
1876
|
// Value type
|
|
2036
|
-
i32: (n) =>
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
1877
|
+
i32: (n, c, op, out) => {
|
|
1878
|
+
if (out) {
|
|
1879
|
+
i32(n.shift(), out);
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
return i32(n.shift());
|
|
1883
|
+
},
|
|
1884
|
+
i64: (n, c, op, out) => {
|
|
1885
|
+
if (out) {
|
|
1886
|
+
i64(n.shift(), out);
|
|
1887
|
+
return;
|
|
1888
|
+
}
|
|
1889
|
+
return i64(n.shift());
|
|
1890
|
+
},
|
|
1891
|
+
f32: (n, c, op, out) => f32(n.shift(), out),
|
|
1892
|
+
f64: (n, c, op, out) => f64(n.shift(), out),
|
|
2040
1893
|
v128: (n) => v128(n.shift()),
|
|
2041
1894
|
// Combinations
|
|
2042
1895
|
typeidx_field: (n, c) => {
|
|
@@ -2091,13 +1944,6 @@ var IMM = {
|
|
|
2091
1944
|
return [...typeidx, ...uleb(cnt), ...handlers];
|
|
2092
1945
|
}
|
|
2093
1946
|
};
|
|
2094
|
-
var HANDLER = {};
|
|
2095
|
-
(function populate(items, pre) {
|
|
2096
|
-
for (let op = 0, item, nm, imm; op < items.length; op++) if (item = items[op]) {
|
|
2097
|
-
if (Array.isArray(item)) populate(item, op);
|
|
2098
|
-
else [nm, imm] = item.split(" "), INSTR[nm] = pre ? [pre, ...uleb(op)] : [op], imm && (HANDLER[nm] = IMM[imm]);
|
|
2099
|
-
}
|
|
2100
|
-
})(INSTR);
|
|
2101
1947
|
var instr = (nodes, ctx) => {
|
|
2102
1948
|
let out = [], meta = [];
|
|
2103
1949
|
while (nodes?.length) {
|
|
@@ -2107,26 +1953,91 @@ var instr = (nodes, ctx) => {
|
|
|
2107
1953
|
continue;
|
|
2108
1954
|
}
|
|
2109
1955
|
if (Array.isArray(op)) {
|
|
2110
|
-
op.loc != null && (
|
|
1956
|
+
op.loc != null && setErrLoc(op.loc);
|
|
2111
1957
|
err(`Unknown instruction ${op[0]}`);
|
|
2112
1958
|
}
|
|
2113
|
-
|
|
2114
|
-
if (
|
|
2115
|
-
if (op === "select" && nodes[0]?.length) bytes[0]++;
|
|
2116
|
-
else if (HANDLER[op] === IMM.reftype && !op.endsWith("_null") && (nodes[0][1] === "null" || nodes[0][0] !== "ref")) {
|
|
2117
|
-
bytes[bytes.length - 1]++;
|
|
2118
|
-
}
|
|
2119
|
-
bytes.push(...HANDLER[op](nodes, ctx, op));
|
|
2120
|
-
}
|
|
1959
|
+
const code = OPCODE[op];
|
|
1960
|
+
if (typeof code !== "number") err(`Unknown instruction ${op}`);
|
|
2121
1961
|
if (meta.length) {
|
|
2122
1962
|
for (const [type, data] of meta) (ctx.meta[type] ??= []).push([out.length, data]);
|
|
2123
1963
|
meta = [];
|
|
2124
1964
|
}
|
|
2125
|
-
out.
|
|
1965
|
+
const at = out.length;
|
|
1966
|
+
if (code > 65535) {
|
|
1967
|
+
out.push(code >>> 16);
|
|
1968
|
+
uleb(code & 65535, out);
|
|
1969
|
+
} else out.push(code);
|
|
1970
|
+
const imm = IMM[op];
|
|
1971
|
+
if (imm) {
|
|
1972
|
+
if (op === "select" && nodes[0]?.length) out[at]++;
|
|
1973
|
+
else if (imm === "reftype" && !op.endsWith("_null") && (nodes[0][1] === "null" || nodes[0][0] !== "ref")) {
|
|
1974
|
+
out[out.length - 1]++;
|
|
1975
|
+
}
|
|
1976
|
+
const b = HANDLER[imm](nodes, ctx, op, out);
|
|
1977
|
+
if (b) for (let i = 0; i < b.length; i++) out.push(b[i]);
|
|
1978
|
+
}
|
|
2126
1979
|
}
|
|
2127
1980
|
return out.push(11), out;
|
|
2128
1981
|
};
|
|
2129
|
-
var ulebSize = (n) =>
|
|
1982
|
+
var ulebSize = (n) => {
|
|
1983
|
+
if (typeof n !== "number" || n < 0) return uleb(n).length;
|
|
1984
|
+
let k = 1;
|
|
1985
|
+
n >>>= 7;
|
|
1986
|
+
while (n) k++, n >>>= 7;
|
|
1987
|
+
return k;
|
|
1988
|
+
};
|
|
1989
|
+
var slebSize32 = (n) => {
|
|
1990
|
+
if (typeof n === "string") n = i32.parse(n);
|
|
1991
|
+
let k = 1;
|
|
1992
|
+
while (true) {
|
|
1993
|
+
const byte = n & 127;
|
|
1994
|
+
n >>= 7;
|
|
1995
|
+
if (n === 0 && (byte & 64) === 0 || n === -1 && (byte & 64) !== 0) return k;
|
|
1996
|
+
k++;
|
|
1997
|
+
}
|
|
1998
|
+
};
|
|
1999
|
+
var memargSize = (nodes, op, memIdx = 0) => {
|
|
2000
|
+
const [a, o] = memarg(nodes), alignVal = (a ?? align(op)) | (memIdx && 64);
|
|
2001
|
+
return memIdx ? ulebSize(alignVal) + ulebSize(memIdx) + ulebSize(o ?? 0) : ulebSize(alignVal) + ulebSize(o ?? 0);
|
|
2002
|
+
};
|
|
2003
|
+
var SIZE_HANDLER = {};
|
|
2004
|
+
for (const k in HANDLER) SIZE_HANDLER[k] = (n, c, op) => HANDLER[k](n, c, op).length;
|
|
2005
|
+
Object.assign(SIZE_HANDLER, {
|
|
2006
|
+
i32: (n) => slebSize32(n.shift()),
|
|
2007
|
+
f32: (n) => (n.shift(), 4),
|
|
2008
|
+
f64: (n) => (n.shift(), 8),
|
|
2009
|
+
localidx: (n, c) => ulebSize(id(n.shift(), c.local)),
|
|
2010
|
+
funcidx: (n, c) => ulebSize(id(n.shift(), c.func)),
|
|
2011
|
+
typeidx: (n, c) => ulebSize(id(n.shift(), c.type)),
|
|
2012
|
+
tableidx: (n, c) => ulebSize(id(n.shift(), c.table)),
|
|
2013
|
+
memoryidx: (n, c) => ulebSize(id(n.shift(), c.memory)),
|
|
2014
|
+
globalidx: (n, c) => ulebSize(id(n.shift(), c.global)),
|
|
2015
|
+
dataidx: (n, c) => ulebSize(id(n.shift(), c.data)),
|
|
2016
|
+
elemidx: (n, c) => ulebSize(id(n.shift(), c.elem)),
|
|
2017
|
+
tagidx: (n, c) => ulebSize(id(n.shift(), c.tag)),
|
|
2018
|
+
labelidx: (n, c) => ulebSize(blockid(n.shift(), c.block)),
|
|
2019
|
+
laneidx: (n) => (parseUint(n.shift(), 255), 1),
|
|
2020
|
+
memarg: (n, c, op) => memargSize(n, op, isIdx(n[0]) && !isMemParam(n[0]) ? id(n.shift(), c.memory) : 0),
|
|
2021
|
+
opt_memory: (n, c) => ulebSize(id(isIdx(n[0]) ? n.shift() : 0, c.memory)),
|
|
2022
|
+
"memoryidx?": (n, c) => ulebSize(id(isIdx(n[0]) ? n.shift() : 0, c.memory)),
|
|
2023
|
+
call_indirect: (n, c) => {
|
|
2024
|
+
const t = n.shift(), [, ti] = n.shift();
|
|
2025
|
+
return ulebSize(id(ti, c.type)) + ulebSize(id(t, c.table));
|
|
2026
|
+
},
|
|
2027
|
+
block: (n, c) => {
|
|
2028
|
+
c.block.push(1);
|
|
2029
|
+
isId(n[0]) && (c.block[n.shift()] = c.block.length);
|
|
2030
|
+
const t = n.shift();
|
|
2031
|
+
return !t ? 1 : t[0] === "result" ? reftype(t[1], c).length : ulebSize(id(t[1], c.type));
|
|
2032
|
+
},
|
|
2033
|
+
end: (_n, c) => (c.block.pop(), 0),
|
|
2034
|
+
stringidx: (n, c) => {
|
|
2035
|
+
const str2 = n.shift(), key = str2.valueOf();
|
|
2036
|
+
let idx = c.strings.findIndex((x) => x.valueOf() === key);
|
|
2037
|
+
if (idx < 0) idx = c.strings.push(str2) - 1;
|
|
2038
|
+
return ulebSize(idx);
|
|
2039
|
+
}
|
|
2040
|
+
});
|
|
2130
2041
|
var instrSize = (nodes, ctx) => {
|
|
2131
2042
|
let size = 0, meta = [];
|
|
2132
2043
|
while (nodes?.length) {
|
|
@@ -2136,12 +2047,13 @@ var instrSize = (nodes, ctx) => {
|
|
|
2136
2047
|
continue;
|
|
2137
2048
|
}
|
|
2138
2049
|
if (Array.isArray(op)) {
|
|
2139
|
-
op.loc != null && (
|
|
2050
|
+
op.loc != null && setErrLoc(op.loc);
|
|
2140
2051
|
err(`Unknown instruction ${op[0]}`);
|
|
2141
2052
|
}
|
|
2142
|
-
const
|
|
2143
|
-
|
|
2144
|
-
|
|
2053
|
+
const code = OPCODE[op];
|
|
2054
|
+
if (typeof code !== "number") err(`Unknown instruction ${op}`);
|
|
2055
|
+
let n = code > 65535 ? 1 + ulebSize(code & 65535) : 1;
|
|
2056
|
+
if (IMM[op]) n += SIZE_HANDLER[IMM[op]](nodes, ctx, op);
|
|
2145
2057
|
if (meta.length) {
|
|
2146
2058
|
for (const [type, data] of meta) (ctx.meta[type] ??= []).push([size, data]);
|
|
2147
2059
|
meta = [];
|
|
@@ -2183,7 +2095,7 @@ var codeItemSize = (body, ctx) => {
|
|
|
2183
2095
|
return ulebSize(bodyLen) + bodyLen;
|
|
2184
2096
|
};
|
|
2185
2097
|
var expr = (node, ctx) => instr(normalize([node], ctx), ctx);
|
|
2186
|
-
var id = (nm, list, n) => (n = isId(nm) ? list[nm] : +nm, n in list ? n : err(`Unknown ${list.name} ${nm}`));
|
|
2098
|
+
var id = (nm, list, n) => (n = isId(nm) ? list[nm] : +nm, n >= 0 && n < list.length ? n : n in list ? n : err(`Unknown ${list.name} ${nm}`));
|
|
2187
2099
|
var blockid = (nm, block, i) => (i = isId(nm) ? block.length - block[nm] : +nm, isNaN(i) || i > block.length ? err(`Bad label ${nm}`) : i);
|
|
2188
2100
|
var memarg = (args) => {
|
|
2189
2101
|
let align2, offset, k, v;
|
|
@@ -2193,8 +2105,14 @@ var memarg = (args) => {
|
|
|
2193
2105
|
if (align2) (align2 = Math.log2(align2)) % 1 && err(`Bad align ${align2}`);
|
|
2194
2106
|
return [align2, offset];
|
|
2195
2107
|
};
|
|
2196
|
-
var memargEnc = (nodes, op, memIdx = 0) => {
|
|
2108
|
+
var memargEnc = (nodes, op, memIdx = 0, out) => {
|
|
2197
2109
|
const [a, o] = memarg(nodes), alignVal = (a ?? align(op)) | (memIdx && 64);
|
|
2110
|
+
if (out) {
|
|
2111
|
+
uleb(alignVal, out);
|
|
2112
|
+
if (memIdx) uleb(memIdx, out);
|
|
2113
|
+
uleb(o ?? 0, out);
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2198
2116
|
return memIdx ? [...uleb(alignVal), ...uleb(memIdx), ...uleb(o ?? 0)] : [...uleb(alignVal), ...uleb(o ?? 0)];
|
|
2199
2117
|
};
|
|
2200
2118
|
var align = (op) => {
|
|
@@ -2253,7 +2171,7 @@ function print(tree, options = {}) {
|
|
|
2253
2171
|
if (typeof tree[0] === "string" && tree[0][0] !== ";") return printNode(tree);
|
|
2254
2172
|
return tree.filter((node) => comments || !isComment(node)).map((node) => printNode(node)).join(newline);
|
|
2255
2173
|
function isComment(node) {
|
|
2256
|
-
return typeof node === "string" && node[1] === ";";
|
|
2174
|
+
return typeof node === "string" && (node[0] === ";" || node[0] === "(" && node[1] === ";");
|
|
2257
2175
|
}
|
|
2258
2176
|
function printNode(node, level = 0) {
|
|
2259
2177
|
if (!Array.isArray(node)) return node;
|
|
@@ -2272,7 +2190,7 @@ function print(tree, options = {}) {
|
|
|
2272
2190
|
let curIndent = indent.repeat(level + 1);
|
|
2273
2191
|
for (let i = 1; i < node.length; i++) {
|
|
2274
2192
|
const sub = node[i]?.valueOf?.() ?? node[i];
|
|
2275
|
-
if (typeof sub === "string" && sub[1] === ";") {
|
|
2193
|
+
if (typeof sub === "string" && (sub[0] === ";" || sub[0] === "(" && sub[1] === ";")) {
|
|
2276
2194
|
if (!comments) continue;
|
|
2277
2195
|
if (sub[0] === ";") {
|
|
2278
2196
|
if (newline) {
|