-
Notifications
You must be signed in to change notification settings - Fork 244
/
operations.go
2812 lines (2583 loc) · 106 KB
/
operations.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
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
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package wazeroir
import (
"fmt"
"math"
"strings"
)
// UnsignedInt represents unsigned 32-bit or 64-bit integers.
type UnsignedInt byte
const (
UnsignedInt32 UnsignedInt = iota
UnsignedInt64
)
// String implements fmt.Stringer.
func (s UnsignedInt) String() (ret string) {
switch s {
case UnsignedInt32:
ret = "i32"
case UnsignedInt64:
ret = "i64"
}
return
}
// SignedInt represents signed or unsigned integers.
type SignedInt byte
const (
SignedInt32 SignedInt = iota
SignedInt64
SignedUint32
SignedUint64
)
// String implements fmt.Stringer.
func (s SignedInt) String() (ret string) {
switch s {
case SignedUint32:
ret = "u32"
case SignedUint64:
ret = "u64"
case SignedInt32:
ret = "s32"
case SignedInt64:
ret = "s64"
}
return
}
// Float represents the scalar double or single precision floating points.
type Float byte
const (
Float32 Float = iota
Float64
)
// String implements fmt.Stringer.
func (s Float) String() (ret string) {
switch s {
case Float32:
ret = "f32"
case Float64:
ret = "f64"
}
return
}
// UnsignedType is the union of UnsignedInt, Float and V128 vector type.
type UnsignedType byte
const (
UnsignedTypeI32 UnsignedType = iota
UnsignedTypeI64
UnsignedTypeF32
UnsignedTypeF64
UnsignedTypeV128
UnsignedTypeUnknown
)
// String implements fmt.Stringer.
func (s UnsignedType) String() (ret string) {
switch s {
case UnsignedTypeI32:
ret = "i32"
case UnsignedTypeI64:
ret = "i64"
case UnsignedTypeF32:
ret = "f32"
case UnsignedTypeF64:
ret = "f64"
case UnsignedTypeV128:
ret = "v128"
case UnsignedTypeUnknown:
ret = "unknown"
}
return
}
// SignedType is the union of SignedInt and Float types.
type SignedType byte
const (
SignedTypeInt32 SignedType = iota
SignedTypeUint32
SignedTypeInt64
SignedTypeUint64
SignedTypeFloat32
SignedTypeFloat64
)
// String implements fmt.Stringer.
func (s SignedType) String() (ret string) {
switch s {
case SignedTypeInt32:
ret = "s32"
case SignedTypeUint32:
ret = "u32"
case SignedTypeInt64:
ret = "s64"
case SignedTypeUint64:
ret = "u64"
case SignedTypeFloat32:
ret = "f32"
case SignedTypeFloat64:
ret = "f64"
}
return
}
// OperationKind is the Kind of each implementation of Operation interface.
type OperationKind uint16
// String implements fmt.Stringer.
func (o OperationKind) String() (ret string) {
switch o {
case OperationKindUnreachable:
ret = "Unreachable"
case OperationKindLabel:
ret = "label"
case OperationKindBr:
ret = "Br"
case OperationKindBrIf:
ret = "BrIf"
case OperationKindBrTable:
ret = "BrTable"
case OperationKindCall:
ret = "Call"
case OperationKindCallIndirect:
ret = "CallIndirect"
case OperationKindDrop:
ret = "Drop"
case OperationKindSelect:
ret = "Select"
case OperationKindPick:
ret = "Pick"
case OperationKindSet:
ret = "Swap"
case OperationKindGlobalGet:
ret = "GlobalGet"
case OperationKindGlobalSet:
ret = "GlobalSet"
case OperationKindLoad:
ret = "Load"
case OperationKindLoad8:
ret = "Load8"
case OperationKindLoad16:
ret = "Load16"
case OperationKindLoad32:
ret = "Load32"
case OperationKindStore:
ret = "Store"
case OperationKindStore8:
ret = "Store8"
case OperationKindStore16:
ret = "Store16"
case OperationKindStore32:
ret = "Store32"
case OperationKindMemorySize:
ret = "MemorySize"
case OperationKindMemoryGrow:
ret = "MemoryGrow"
case OperationKindConstI32:
ret = "ConstI32"
case OperationKindConstI64:
ret = "ConstI64"
case OperationKindConstF32:
ret = "ConstF32"
case OperationKindConstF64:
ret = "ConstF64"
case OperationKindEq:
ret = "Eq"
case OperationKindNe:
ret = "Ne"
case OperationKindEqz:
ret = "Eqz"
case OperationKindLt:
ret = "Lt"
case OperationKindGt:
ret = "Gt"
case OperationKindLe:
ret = "Le"
case OperationKindGe:
ret = "Ge"
case OperationKindAdd:
ret = "Add"
case OperationKindSub:
ret = "Sub"
case OperationKindMul:
ret = "Mul"
case OperationKindClz:
ret = "Clz"
case OperationKindCtz:
ret = "Ctz"
case OperationKindPopcnt:
ret = "Popcnt"
case OperationKindDiv:
ret = "Div"
case OperationKindRem:
ret = "Rem"
case OperationKindAnd:
ret = "And"
case OperationKindOr:
ret = "Or"
case OperationKindXor:
ret = "Xor"
case OperationKindShl:
ret = "Shl"
case OperationKindShr:
ret = "Shr"
case OperationKindRotl:
ret = "Rotl"
case OperationKindRotr:
ret = "Rotr"
case OperationKindAbs:
ret = "Abs"
case OperationKindNeg:
ret = "Neg"
case OperationKindCeil:
ret = "Ceil"
case OperationKindFloor:
ret = "Floor"
case OperationKindTrunc:
ret = "Trunc"
case OperationKindNearest:
ret = "Nearest"
case OperationKindSqrt:
ret = "Sqrt"
case OperationKindMin:
ret = "Min"
case OperationKindMax:
ret = "Max"
case OperationKindCopysign:
ret = "Copysign"
case OperationKindI32WrapFromI64:
ret = "I32WrapFromI64"
case OperationKindITruncFromF:
ret = "ITruncFromF"
case OperationKindFConvertFromI:
ret = "FConvertFromI"
case OperationKindF32DemoteFromF64:
ret = "F32DemoteFromF64"
case OperationKindF64PromoteFromF32:
ret = "F64PromoteFromF32"
case OperationKindI32ReinterpretFromF32:
ret = "I32ReinterpretFromF32"
case OperationKindI64ReinterpretFromF64:
ret = "I64ReinterpretFromF64"
case OperationKindF32ReinterpretFromI32:
ret = "F32ReinterpretFromI32"
case OperationKindF64ReinterpretFromI64:
ret = "F64ReinterpretFromI64"
case OperationKindExtend:
ret = "Extend"
case OperationKindMemoryInit:
ret = "MemoryInit"
case OperationKindDataDrop:
ret = "DataDrop"
case OperationKindMemoryCopy:
ret = "MemoryCopy"
case OperationKindMemoryFill:
ret = "MemoryFill"
case OperationKindTableInit:
ret = "TableInit"
case OperationKindElemDrop:
ret = "ElemDrop"
case OperationKindTableCopy:
ret = "TableCopy"
case OperationKindRefFunc:
ret = "RefFunc"
case OperationKindTableGet:
ret = "TableGet"
case OperationKindTableSet:
ret = "TableSet"
case OperationKindTableSize:
ret = "TableSize"
case OperationKindTableGrow:
ret = "TableGrow"
case OperationKindTableFill:
ret = "TableFill"
case OperationKindV128Const:
ret = "ConstV128"
case OperationKindV128Add:
ret = "V128Add"
case OperationKindV128Sub:
ret = "V128Sub"
case OperationKindV128Load:
ret = "V128Load"
case OperationKindV128LoadLane:
ret = "V128LoadLane"
case OperationKindV128Store:
ret = "V128Store"
case OperationKindV128StoreLane:
ret = "V128StoreLane"
case OperationKindV128ExtractLane:
ret = "V128ExtractLane"
case OperationKindV128ReplaceLane:
ret = "V128ReplaceLane"
case OperationKindV128Splat:
ret = "V128Splat"
case OperationKindV128Shuffle:
ret = "V128Shuffle"
case OperationKindV128Swizzle:
ret = "V128Swizzle"
case OperationKindV128AnyTrue:
ret = "V128AnyTrue"
case OperationKindV128AllTrue:
ret = "V128AllTrue"
case OperationKindV128And:
ret = "V128And"
case OperationKindV128Not:
ret = "V128Not"
case OperationKindV128Or:
ret = "V128Or"
case OperationKindV128Xor:
ret = "V128Xor"
case OperationKindV128Bitselect:
ret = "V128Bitselect"
case OperationKindV128AndNot:
ret = "V128AndNot"
case OperationKindV128BitMask:
ret = "V128BitMask"
case OperationKindV128Shl:
ret = "V128Shl"
case OperationKindV128Shr:
ret = "V128Shr"
case OperationKindV128Cmp:
ret = "V128Cmp"
case OperationKindSignExtend32From8:
ret = "SignExtend32From8"
case OperationKindSignExtend32From16:
ret = "SignExtend32From16"
case OperationKindSignExtend64From8:
ret = "SignExtend64From8"
case OperationKindSignExtend64From16:
ret = "SignExtend64From16"
case OperationKindSignExtend64From32:
ret = "SignExtend64From32"
case OperationKindV128AddSat:
ret = "V128AddSat"
case OperationKindV128SubSat:
ret = "V128SubSat"
case OperationKindV128Mul:
ret = "V128Mul"
case OperationKindV128Div:
ret = "V128Div"
case OperationKindV128Neg:
ret = "V128Neg"
case OperationKindV128Sqrt:
ret = "V128Sqrt"
case OperationKindV128Abs:
ret = "V128Abs"
case OperationKindV128Popcnt:
ret = "V128Popcnt"
case OperationKindV128Min:
ret = "V128Min"
case OperationKindV128Max:
ret = "V128Max"
case OperationKindV128AvgrU:
ret = "V128AvgrU"
case OperationKindV128Ceil:
ret = "V128Ceil"
case OperationKindV128Floor:
ret = "V128Floor"
case OperationKindV128Trunc:
ret = "V128Trunc"
case OperationKindV128Nearest:
ret = "V128Nearest"
case OperationKindV128Pmin:
ret = "V128Pmin"
case OperationKindV128Pmax:
ret = "V128Pmax"
case OperationKindV128Extend:
ret = "V128Extend"
case OperationKindV128ExtMul:
ret = "V128ExtMul"
case OperationKindV128Q15mulrSatS:
ret = "V128Q15mulrSatS"
case OperationKindV128ExtAddPairwise:
ret = "V128ExtAddPairwise"
case OperationKindV128FloatPromote:
ret = "V128FloatPromote"
case OperationKindV128FloatDemote:
ret = "V128FloatDemote"
case OperationKindV128FConvertFromI:
ret = "V128FConvertFromI"
case OperationKindV128Dot:
ret = "V128Dot"
case OperationKindV128Narrow:
ret = "V128Narrow"
case OperationKindV128ITruncSatFromF:
ret = "V128ITruncSatFromF"
case OperationKindBuiltinFunctionCheckExitCode:
ret = "BuiltinFunctionCheckExitCode"
case OperationKindAtomicMemoryWait:
ret = "OperationKindAtomicMemoryWait"
case OperationKindAtomicMemoryNotify:
ret = "OperationKindAtomicMemoryNotify"
case OperationKindAtomicFence:
ret = "OperationKindAtomicFence"
case OperationKindAtomicLoad:
ret = "OperationKindAtomicLoad"
case OperationKindAtomicLoad8:
ret = "OperationKindAtomicLoad8"
case OperationKindAtomicLoad16:
ret = "OperationKindAtomicLoad16"
case OperationKindAtomicStore:
ret = "OperationKindAtomicStore"
case OperationKindAtomicStore8:
ret = "OperationKindAtomicStore8"
case OperationKindAtomicStore16:
ret = "OperationKindAtomicStore16"
case OperationKindAtomicRMW:
ret = "OperationKindAtomicRMW"
case OperationKindAtomicRMW8:
ret = "OperationKindAtomicRMW8"
case OperationKindAtomicRMW16:
ret = "OperationKindAtomicRMW16"
case OperationKindAtomicRMWCmpxchg:
ret = "OperationKindAtomicRMWCmpxchg"
case OperationKindAtomicRMW8Cmpxchg:
ret = "OperationKindAtomicRMW8Cmpxchg"
case OperationKindAtomicRMW16Cmpxchg:
ret = "OperationKindAtomicRMW16Cmpxchg"
default:
panic(fmt.Errorf("unknown operation %d", o))
}
return
}
const (
// OperationKindUnreachable is the Kind for NewOperationUnreachable.
OperationKindUnreachable OperationKind = iota
// OperationKindLabel is the Kind for NewOperationLabel.
OperationKindLabel
// OperationKindBr is the Kind for NewOperationBr.
OperationKindBr
// OperationKindBrIf is the Kind for NewOperationBrIf.
OperationKindBrIf
// OperationKindBrTable is the Kind for NewOperationBrTable.
OperationKindBrTable
// OperationKindCall is the Kind for NewOperationCall.
OperationKindCall
// OperationKindCallIndirect is the Kind for NewOperationCallIndirect.
OperationKindCallIndirect
// OperationKindDrop is the Kind for NewOperationDrop.
OperationKindDrop
// OperationKindSelect is the Kind for NewOperationSelect.
OperationKindSelect
// OperationKindPick is the Kind for NewOperationPick.
OperationKindPick
// OperationKindSet is the Kind for NewOperationSet.
OperationKindSet
// OperationKindGlobalGet is the Kind for NewOperationGlobalGet.
OperationKindGlobalGet
// OperationKindGlobalSet is the Kind for NewOperationGlobalSet.
OperationKindGlobalSet
// OperationKindLoad is the Kind for NewOperationLoad.
OperationKindLoad
// OperationKindLoad8 is the Kind for NewOperationLoad8.
OperationKindLoad8
// OperationKindLoad16 is the Kind for NewOperationLoad16.
OperationKindLoad16
// OperationKindLoad32 is the Kind for NewOperationLoad32.
OperationKindLoad32
// OperationKindStore is the Kind for NewOperationStore.
OperationKindStore
// OperationKindStore8 is the Kind for NewOperationStore8.
OperationKindStore8
// OperationKindStore16 is the Kind for NewOperationStore16.
OperationKindStore16
// OperationKindStore32 is the Kind for NewOperationStore32.
OperationKindStore32
// OperationKindMemorySize is the Kind for NewOperationMemorySize.
OperationKindMemorySize
// OperationKindMemoryGrow is the Kind for NewOperationMemoryGrow.
OperationKindMemoryGrow
// OperationKindConstI32 is the Kind for NewOperationConstI32.
OperationKindConstI32
// OperationKindConstI64 is the Kind for NewOperationConstI64.
OperationKindConstI64
// OperationKindConstF32 is the Kind for NewOperationConstF32.
OperationKindConstF32
// OperationKindConstF64 is the Kind for NewOperationConstF64.
OperationKindConstF64
// OperationKindEq is the Kind for NewOperationEq.
OperationKindEq
// OperationKindNe is the Kind for NewOperationNe.
OperationKindNe
// OperationKindEqz is the Kind for NewOperationEqz.
OperationKindEqz
// OperationKindLt is the Kind for NewOperationLt.
OperationKindLt
// OperationKindGt is the Kind for NewOperationGt.
OperationKindGt
// OperationKindLe is the Kind for NewOperationLe.
OperationKindLe
// OperationKindGe is the Kind for NewOperationGe.
OperationKindGe
// OperationKindAdd is the Kind for NewOperationAdd.
OperationKindAdd
// OperationKindSub is the Kind for NewOperationSub.
OperationKindSub
// OperationKindMul is the Kind for NewOperationMul.
OperationKindMul
// OperationKindClz is the Kind for NewOperationClz.
OperationKindClz
// OperationKindCtz is the Kind for NewOperationCtz.
OperationKindCtz
// OperationKindPopcnt is the Kind for NewOperationPopcnt.
OperationKindPopcnt
// OperationKindDiv is the Kind for NewOperationDiv.
OperationKindDiv
// OperationKindRem is the Kind for NewOperationRem.
OperationKindRem
// OperationKindAnd is the Kind for NewOperationAnd.
OperationKindAnd
// OperationKindOr is the Kind for NewOperationOr.
OperationKindOr
// OperationKindXor is the Kind for NewOperationXor.
OperationKindXor
// OperationKindShl is the Kind for NewOperationShl.
OperationKindShl
// OperationKindShr is the Kind for NewOperationShr.
OperationKindShr
// OperationKindRotl is the Kind for NewOperationRotl.
OperationKindRotl
// OperationKindRotr is the Kind for NewOperationRotr.
OperationKindRotr
// OperationKindAbs is the Kind for NewOperationAbs.
OperationKindAbs
// OperationKindNeg is the Kind for NewOperationNeg.
OperationKindNeg
// OperationKindCeil is the Kind for NewOperationCeil.
OperationKindCeil
// OperationKindFloor is the Kind for NewOperationFloor.
OperationKindFloor
// OperationKindTrunc is the Kind for NewOperationTrunc.
OperationKindTrunc
// OperationKindNearest is the Kind for NewOperationNearest.
OperationKindNearest
// OperationKindSqrt is the Kind for NewOperationSqrt.
OperationKindSqrt
// OperationKindMin is the Kind for NewOperationMin.
OperationKindMin
// OperationKindMax is the Kind for NewOperationMax.
OperationKindMax
// OperationKindCopysign is the Kind for NewOperationCopysign.
OperationKindCopysign
// OperationKindI32WrapFromI64 is the Kind for NewOperationI32WrapFromI64.
OperationKindI32WrapFromI64
// OperationKindITruncFromF is the Kind for NewOperationITruncFromF.
OperationKindITruncFromF
// OperationKindFConvertFromI is the Kind for NewOperationFConvertFromI.
OperationKindFConvertFromI
// OperationKindF32DemoteFromF64 is the Kind for NewOperationF32DemoteFromF64.
OperationKindF32DemoteFromF64
// OperationKindF64PromoteFromF32 is the Kind for NewOperationF64PromoteFromF32.
OperationKindF64PromoteFromF32
// OperationKindI32ReinterpretFromF32 is the Kind for NewOperationI32ReinterpretFromF32.
OperationKindI32ReinterpretFromF32
// OperationKindI64ReinterpretFromF64 is the Kind for NewOperationI64ReinterpretFromF64.
OperationKindI64ReinterpretFromF64
// OperationKindF32ReinterpretFromI32 is the Kind for NewOperationF32ReinterpretFromI32.
OperationKindF32ReinterpretFromI32
// OperationKindF64ReinterpretFromI64 is the Kind for NewOperationF64ReinterpretFromI64.
OperationKindF64ReinterpretFromI64
// OperationKindExtend is the Kind for NewOperationExtend.
OperationKindExtend
// OperationKindSignExtend32From8 is the Kind for NewOperationSignExtend32From8.
OperationKindSignExtend32From8
// OperationKindSignExtend32From16 is the Kind for NewOperationSignExtend32From16.
OperationKindSignExtend32From16
// OperationKindSignExtend64From8 is the Kind for NewOperationSignExtend64From8.
OperationKindSignExtend64From8
// OperationKindSignExtend64From16 is the Kind for NewOperationSignExtend64From16.
OperationKindSignExtend64From16
// OperationKindSignExtend64From32 is the Kind for NewOperationSignExtend64From32.
OperationKindSignExtend64From32
// OperationKindMemoryInit is the Kind for NewOperationMemoryInit.
OperationKindMemoryInit
// OperationKindDataDrop is the Kind for NewOperationDataDrop.
OperationKindDataDrop
// OperationKindMemoryCopy is the Kind for NewOperationMemoryCopy.
OperationKindMemoryCopy
// OperationKindMemoryFill is the Kind for NewOperationMemoryFill.
OperationKindMemoryFill
// OperationKindTableInit is the Kind for NewOperationTableInit.
OperationKindTableInit
// OperationKindElemDrop is the Kind for NewOperationElemDrop.
OperationKindElemDrop
// OperationKindTableCopy is the Kind for NewOperationTableCopy.
OperationKindTableCopy
// OperationKindRefFunc is the Kind for NewOperationRefFunc.
OperationKindRefFunc
// OperationKindTableGet is the Kind for NewOperationTableGet.
OperationKindTableGet
// OperationKindTableSet is the Kind for NewOperationTableSet.
OperationKindTableSet
// OperationKindTableSize is the Kind for NewOperationTableSize.
OperationKindTableSize
// OperationKindTableGrow is the Kind for NewOperationTableGrow.
OperationKindTableGrow
// OperationKindTableFill is the Kind for NewOperationTableFill.
OperationKindTableFill
// Vector value related instructions are prefixed by V128.
// OperationKindV128Const is the Kind for NewOperationV128Const.
OperationKindV128Const
// OperationKindV128Add is the Kind for NewOperationV128Add.
OperationKindV128Add
// OperationKindV128Sub is the Kind for NewOperationV128Sub.
OperationKindV128Sub
// OperationKindV128Load is the Kind for NewOperationV128Load.
OperationKindV128Load
// OperationKindV128LoadLane is the Kind for NewOperationV128LoadLane.
OperationKindV128LoadLane
// OperationKindV128Store is the Kind for NewOperationV128Store.
OperationKindV128Store
// OperationKindV128StoreLane is the Kind for NewOperationV128StoreLane.
OperationKindV128StoreLane
// OperationKindV128ExtractLane is the Kind for NewOperationV128ExtractLane.
OperationKindV128ExtractLane
// OperationKindV128ReplaceLane is the Kind for NewOperationV128ReplaceLane.
OperationKindV128ReplaceLane
// OperationKindV128Splat is the Kind for NewOperationV128Splat.
OperationKindV128Splat
// OperationKindV128Shuffle is the Kind for NewOperationV128Shuffle.
OperationKindV128Shuffle
// OperationKindV128Swizzle is the Kind for NewOperationV128Swizzle.
OperationKindV128Swizzle
// OperationKindV128AnyTrue is the Kind for NewOperationV128AnyTrue.
OperationKindV128AnyTrue
// OperationKindV128AllTrue is the Kind for NewOperationV128AllTrue.
OperationKindV128AllTrue
// OperationKindV128BitMask is the Kind for NewOperationV128BitMask.
OperationKindV128BitMask
// OperationKindV128And is the Kind for NewOperationV128And.
OperationKindV128And
// OperationKindV128Not is the Kind for NewOperationV128Not.
OperationKindV128Not
// OperationKindV128Or is the Kind for NewOperationV128Or.
OperationKindV128Or
// OperationKindV128Xor is the Kind for NewOperationV128Xor.
OperationKindV128Xor
// OperationKindV128Bitselect is the Kind for NewOperationV128Bitselect.
OperationKindV128Bitselect
// OperationKindV128AndNot is the Kind for NewOperationV128AndNot.
OperationKindV128AndNot
// OperationKindV128Shl is the Kind for NewOperationV128Shl.
OperationKindV128Shl
// OperationKindV128Shr is the Kind for NewOperationV128Shr.
OperationKindV128Shr
// OperationKindV128Cmp is the Kind for NewOperationV128Cmp.
OperationKindV128Cmp
// OperationKindV128AddSat is the Kind for NewOperationV128AddSat.
OperationKindV128AddSat
// OperationKindV128SubSat is the Kind for NewOperationV128SubSat.
OperationKindV128SubSat
// OperationKindV128Mul is the Kind for NewOperationV128Mul.
OperationKindV128Mul
// OperationKindV128Div is the Kind for NewOperationV128Div.
OperationKindV128Div
// OperationKindV128Neg is the Kind for NewOperationV128Neg.
OperationKindV128Neg
// OperationKindV128Sqrt is the Kind for NewOperationV128Sqrt.
OperationKindV128Sqrt
// OperationKindV128Abs is the Kind for NewOperationV128Abs.
OperationKindV128Abs
// OperationKindV128Popcnt is the Kind for NewOperationV128Popcnt.
OperationKindV128Popcnt
// OperationKindV128Min is the Kind for NewOperationV128Min.
OperationKindV128Min
// OperationKindV128Max is the Kind for NewOperationV128Max.
OperationKindV128Max
// OperationKindV128AvgrU is the Kind for NewOperationV128AvgrU.
OperationKindV128AvgrU
// OperationKindV128Pmin is the Kind for NewOperationV128Pmin.
OperationKindV128Pmin
// OperationKindV128Pmax is the Kind for NewOperationV128Pmax.
OperationKindV128Pmax
// OperationKindV128Ceil is the Kind for NewOperationV128Ceil.
OperationKindV128Ceil
// OperationKindV128Floor is the Kind for NewOperationV128Floor.
OperationKindV128Floor
// OperationKindV128Trunc is the Kind for NewOperationV128Trunc.
OperationKindV128Trunc
// OperationKindV128Nearest is the Kind for NewOperationV128Nearest.
OperationKindV128Nearest
// OperationKindV128Extend is the Kind for NewOperationV128Extend.
OperationKindV128Extend
// OperationKindV128ExtMul is the Kind for NewOperationV128ExtMul.
OperationKindV128ExtMul
// OperationKindV128Q15mulrSatS is the Kind for NewOperationV128Q15mulrSatS.
OperationKindV128Q15mulrSatS
// OperationKindV128ExtAddPairwise is the Kind for NewOperationV128ExtAddPairwise.
OperationKindV128ExtAddPairwise
// OperationKindV128FloatPromote is the Kind for NewOperationV128FloatPromote.
OperationKindV128FloatPromote
// OperationKindV128FloatDemote is the Kind for NewOperationV128FloatDemote.
OperationKindV128FloatDemote
// OperationKindV128FConvertFromI is the Kind for NewOperationV128FConvertFromI.
OperationKindV128FConvertFromI
// OperationKindV128Dot is the Kind for NewOperationV128Dot.
OperationKindV128Dot
// OperationKindV128Narrow is the Kind for NewOperationV128Narrow.
OperationKindV128Narrow
// OperationKindV128ITruncSatFromF is the Kind for NewOperationV128ITruncSatFromF.
OperationKindV128ITruncSatFromF
// OperationKindBuiltinFunctionCheckExitCode is the Kind for NewOperationBuiltinFunctionCheckExitCode.
OperationKindBuiltinFunctionCheckExitCode
// OperationKindAtomicMemoryWait is the kind for NewOperationAtomicMemoryWait.
OperationKindAtomicMemoryWait
// OperationKindAtomicMemoryNotify is the kind for NewOperationAtomicMemoryNotify.
OperationKindAtomicMemoryNotify
// OperationKindAtomicFence is the kind for NewOperationAtomicFence.
OperationKindAtomicFence
// OperationKindAtomicLoad is the kind for NewOperationAtomicLoad.
OperationKindAtomicLoad
// OperationKindAtomicLoad8 is the kind for NewOperationAtomicLoad8.
OperationKindAtomicLoad8
// OperationKindAtomicLoad16 is the kind for NewOperationAtomicLoad16.
OperationKindAtomicLoad16
// OperationKindAtomicStore is the kind for NewOperationAtomicStore.
OperationKindAtomicStore
// OperationKindAtomicStore8 is the kind for NewOperationAtomicStore8.
OperationKindAtomicStore8
// OperationKindAtomicStore16 is the kind for NewOperationAtomicStore16.
OperationKindAtomicStore16
// OperationKindAtomicRMW is the kind for NewOperationAtomicRMW.
OperationKindAtomicRMW
// OperationKindAtomicRMW8 is the kind for NewOperationAtomicRMW8.
OperationKindAtomicRMW8
// OperationKindAtomicRMW16 is the kind for NewOperationAtomicRMW16.
OperationKindAtomicRMW16
// OperationKindAtomicRMWCmpxchg is the kind for NewOperationAtomicRMWCmpxchg.
OperationKindAtomicRMWCmpxchg
// OperationKindAtomicRMW8Cmpxchg is the kind for NewOperationAtomicRMW8Cmpxchg.
OperationKindAtomicRMW8Cmpxchg
// OperationKindAtomicRMW16Cmpxchg is the kind for NewOperationAtomicRMW16Cmpxchg.
OperationKindAtomicRMW16Cmpxchg
// operationKindEnd is always placed at the bottom of this iota definition to be used in the test.
operationKindEnd
)
// NewOperationBuiltinFunctionCheckExitCode is a constructor for UnionOperation with Kind OperationKindBuiltinFunctionCheckExitCode.
//
// OperationBuiltinFunctionCheckExitCode corresponds to the instruction to check the api.Module is already closed due to
// context.DeadlineExceeded, context.Canceled, or the explicit call of CloseWithExitCode on api.Module.
func NewOperationBuiltinFunctionCheckExitCode() UnionOperation {
return UnionOperation{Kind: OperationKindBuiltinFunctionCheckExitCode}
}
// Label is the unique identifier for each block in a single function in wazeroir
// where "block" consists of multiple operations, and must End with branching operations
// (e.g. OperationKindBr or OperationKindBrIf).
type Label uint64
// Kind returns the LabelKind encoded in this Label.
func (l Label) Kind() LabelKind {
return LabelKind(uint32(l))
}
// FrameID returns the frame id encoded in this Label.
func (l Label) FrameID() int {
return int(uint32(l >> 32))
}
// NewLabel is a constructor for a Label.
func NewLabel(kind LabelKind, frameID uint32) Label {
return Label(kind) | Label(frameID)<<32
}
// String implements fmt.Stringer.
func (l Label) String() (ret string) {
frameID := l.FrameID()
switch l.Kind() {
case LabelKindHeader:
ret = fmt.Sprintf(".L%d", frameID)
case LabelKindElse:
ret = fmt.Sprintf(".L%d_else", frameID)
case LabelKindContinuation:
ret = fmt.Sprintf(".L%d_cont", frameID)
case LabelKindReturn:
return ".return"
}
return
}
func (l Label) IsReturnTarget() bool {
return l.Kind() == LabelKindReturn
}
// LabelKind is the Kind of the label.
type LabelKind = byte
const (
// LabelKindHeader is the header for various blocks. For example, the "then" block of
// wasm.OpcodeIfName in Wasm has the label of this Kind.
LabelKindHeader LabelKind = iota
// LabelKindElse is the Kind of label for "else" block of wasm.OpcodeIfName in Wasm.
LabelKindElse
// LabelKindContinuation is the Kind of label which is the continuation of blocks.
// For example, for wasm text like
// (func
// ....
// (if (local.get 0) (then (nop)) (else (nop)))
// return
// )
// we have the continuation block (of if-block) corresponding to "return" opcode.
LabelKindContinuation
LabelKindReturn
LabelKindNum
)
// UnionOperation implements Operation and is the compilation (engine.lowerIR) result of a wazeroir.Operation.
//
// Not all operations result in a UnionOperation, e.g. wazeroir.OperationI32ReinterpretFromF32, and some operations are
// more complex than others, e.g. wazeroir.NewOperationBrTable.
//
// Note: This is a form of union type as it can store fields needed for any operation. Hence, most fields are opaque and
// only relevant when in context of its kind.
type UnionOperation struct {
// Kind determines how to interpret the other fields in this struct.
Kind OperationKind
B1, B2 byte
B3 bool
U1, U2 uint64
U3 uint64
Us []uint64
}
// String implements fmt.Stringer.
func (o UnionOperation) String() string {
switch o.Kind {
case OperationKindUnreachable,
OperationKindSelect,
OperationKindMemorySize,
OperationKindMemoryGrow,
OperationKindI32WrapFromI64,
OperationKindF32DemoteFromF64,
OperationKindF64PromoteFromF32,
OperationKindI32ReinterpretFromF32,
OperationKindI64ReinterpretFromF64,
OperationKindF32ReinterpretFromI32,
OperationKindF64ReinterpretFromI64,
OperationKindSignExtend32From8,
OperationKindSignExtend32From16,
OperationKindSignExtend64From8,
OperationKindSignExtend64From16,
OperationKindSignExtend64From32,
OperationKindMemoryInit,
OperationKindDataDrop,
OperationKindMemoryCopy,
OperationKindMemoryFill,
OperationKindTableInit,
OperationKindElemDrop,
OperationKindTableCopy,
OperationKindRefFunc,
OperationKindTableGet,
OperationKindTableSet,
OperationKindTableSize,
OperationKindTableGrow,
OperationKindTableFill,
OperationKindBuiltinFunctionCheckExitCode:
return o.Kind.String()
case OperationKindCall,
OperationKindGlobalGet,
OperationKindGlobalSet:
return fmt.Sprintf("%s %d", o.Kind, o.B1)
case OperationKindLabel:
return Label(o.U1).String()
case OperationKindBr:
return fmt.Sprintf("%s %s", o.Kind, Label(o.U1).String())
case OperationKindBrIf:
thenTarget := Label(o.U1)
elseTarget := Label(o.U2)
return fmt.Sprintf("%s %s, %s", o.Kind, thenTarget, elseTarget)
case OperationKindBrTable:
var targets []string
var defaultLabel Label
if len(o.Us) > 0 {
targets = make([]string, len(o.Us)-1)
for i, t := range o.Us[1:] {
targets[i] = Label(t).String()
}
defaultLabel = Label(o.Us[0])
}
return fmt.Sprintf("%s [%s] %s", o.Kind, strings.Join(targets, ","), defaultLabel)
case OperationKindCallIndirect:
return fmt.Sprintf("%s: type=%d, table=%d", o.Kind, o.U1, o.U2)
case OperationKindDrop:
start := int64(o.U1)
end := int64(o.U2)
return fmt.Sprintf("%s %d..%d", o.Kind, start, end)
case OperationKindPick, OperationKindSet:
return fmt.Sprintf("%s %d (is_vector=%v)", o.Kind, o.U1, o.B3)
case OperationKindLoad, OperationKindStore:
return fmt.Sprintf("%s.%s (align=%d, offset=%d)", UnsignedType(o.B1), o.Kind, o.U1, o.U2)
case OperationKindLoad8,
OperationKindLoad16:
return fmt.Sprintf("%s.%s (align=%d, offset=%d)", SignedType(o.B1), o.Kind, o.U1, o.U2)
case OperationKindStore8,
OperationKindStore16,
OperationKindStore32:
return fmt.Sprintf("%s (align=%d, offset=%d)", o.Kind, o.U1, o.U2)
case OperationKindLoad32:
var t string
if o.B1 == 1 {
t = "i64"
} else {
t = "u64"
}
return fmt.Sprintf("%s.%s (align=%d, offset=%d)", t, o.Kind, o.U1, o.U2)
case OperationKindEq,
OperationKindNe,
OperationKindAdd,
OperationKindSub,
OperationKindMul:
return fmt.Sprintf("%s.%s", UnsignedType(o.B1), o.Kind)
case OperationKindEqz,
OperationKindClz,
OperationKindCtz,
OperationKindPopcnt,
OperationKindAnd,
OperationKindOr,
OperationKindXor,
OperationKindShl,
OperationKindRotl,
OperationKindRotr:
return fmt.Sprintf("%s.%s", UnsignedInt(o.B1), o.Kind)
case OperationKindRem, OperationKindShr:
return fmt.Sprintf("%s.%s", SignedInt(o.B1), o.Kind)
case OperationKindLt,
OperationKindGt,
OperationKindLe,
OperationKindGe,
OperationKindDiv:
return fmt.Sprintf("%s.%s", SignedType(o.B1), o.Kind)
case OperationKindAbs,
OperationKindNeg,
OperationKindCeil,
OperationKindFloor,
OperationKindTrunc,
OperationKindNearest,
OperationKindSqrt,
OperationKindMin,
OperationKindMax,
OperationKindCopysign:
return fmt.Sprintf("%s.%s", Float(o.B1), o.Kind)
case OperationKindConstI32,
OperationKindConstI64:
return fmt.Sprintf("%s %#x", o.Kind, o.U1)