wasi_virt_layer-cli 0.5.4

CLI for the wasi_virt_layer crate
Documentation
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
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
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
#![allow(missing_docs)]
use eyre::Result;
use wasm_encoder::Instruction;
pub trait Rebind {
    fn function(&self, index: u32) -> u32 {
        index
    }
    fn global(&self, index: u32) -> u32 {
        index
    }
    fn memory(&self, index: u32) -> u32 {
        index
    }
    fn table(&self, index: u32) -> u32 {
        index
    }
    fn ty(&self, index: u32) -> u32 {
        index
    }
    fn data(&self, index: u32) -> u32 {
        index
    }
    fn elem(&self, index: u32) -> u32 {
        index
    }
    fn tag(&self, index: u32) -> u32 {
        index
    }
}

pub fn translate_memory_type(t: wasmparser::MemoryType) -> wasm_encoder::MemoryType {
    wasm_encoder::MemoryType {
        minimum: t.initial,
        maximum: t.maximum,
        memory64: t.memory64,
        shared: t.shared,
        page_size_log2: t.page_size_log2,
    }
}

pub fn translate_table_type<R: Rebind>(
    t: wasmparser::TableType,
    rebinder: &R,
) -> wasm_encoder::TableType {
    wasm_encoder::TableType {
        element_type: translate_ref_type(t.element_type, rebinder),
        minimum: t.initial,
        maximum: t.maximum,
        shared: t.shared,
        table64: t.table64,
    }
}

pub fn translate_global_type<R: Rebind>(
    t: wasmparser::GlobalType,
    rebinder: &R,
) -> wasm_encoder::GlobalType {
    wasm_encoder::GlobalType {
        val_type: translate_val_type(t.content_type, rebinder),
        mutable: t.mutable,
        shared: false,
    }
}

pub fn translate_tag_type(t: wasmparser::TagType) -> wasm_encoder::TagType {
    wasm_encoder::TagType {
        kind: match t.kind {
            wasmparser::TagKind::Exception => wasm_encoder::TagKind::Exception,
        },
        func_type_idx: t.func_type_idx,
    }
}

pub fn translate_ref_type<R: Rebind>(
    r: wasmparser::RefType,
    rebinder: &R,
) -> wasm_encoder::RefType {
    wasm_encoder::RefType {
        nullable: r.is_nullable(),
        heap_type: translate_heap_type(r.heap_type(), rebinder),
    }
}

pub fn translate_heap_type<R: Rebind>(
    h: wasmparser::HeapType,
    rebinder: &R,
) -> wasm_encoder::HeapType {
    match h {
        wasmparser::HeapType::Abstract { shared, ty } => wasm_encoder::HeapType::Abstract {
            shared,
            ty: translate_abstract_heap_type(ty),
        },
        wasmparser::HeapType::Concrete(wasmparser::UnpackedIndex::Module(idx)) => {
            wasm_encoder::HeapType::Concrete(rebinder.ty(idx))
        }
        wasmparser::HeapType::Concrete(_) => {
            unimplemented!("Concrete heap type other than Module not supported yet")
        }
        wasmparser::HeapType::Exact(wasmparser::UnpackedIndex::Module(idx)) => {
            wasm_encoder::HeapType::Exact(rebinder.ty(idx))
        }
        wasmparser::HeapType::Exact(_) => {
            unimplemented!("Exact heap type other than Module not supported yet")
        }
    }
}

pub fn translate_sub_type<R: Rebind>(
    sub_ty: &wasmparser::SubType,
    rebinder: &R,
) -> wasm_encoder::SubType {
    let composite_type = match &sub_ty.composite_type.inner {
        wasmparser::CompositeInnerType::Func(f) => {
            let params = f
                .params()
                .iter()
                .copied()
                .map(|t| translate_val_type(t, rebinder))
                .collect::<Vec<_>>();
            let results = f
                .results()
                .iter()
                .copied()
                .map(|t| translate_val_type(t, rebinder))
                .collect::<Vec<_>>();
            wasm_encoder::CompositeType {
                inner: wasm_encoder::CompositeInnerType::Func(wasm_encoder::FuncType::new(
                    params, results,
                )),
                shared: sub_ty.composite_type.shared,
                descriptor: sub_ty
                    .composite_type
                    .descriptor_idx
                    .map(|idx| rebinder.ty(idx.as_module_index().unwrap())),
                describes: sub_ty
                    .composite_type
                    .describes_idx
                    .map(|idx| rebinder.ty(idx.as_module_index().unwrap())),
            }
        }
        _ => unimplemented!("translate_sub_type: {:?}", sub_ty),
    };
    wasm_encoder::SubType {
        is_final: sub_ty.is_final,
        supertype_idx: sub_ty
            .supertype_idx
            .map(|idx| rebinder.ty(idx.as_module_index().unwrap())),
        composite_type,
    }
}

pub fn translate_abstract_heap_type(
    t: wasmparser::AbstractHeapType,
) -> wasm_encoder::AbstractHeapType {
    match t {
        wasmparser::AbstractHeapType::Func => wasm_encoder::AbstractHeapType::Func,
        wasmparser::AbstractHeapType::Extern => wasm_encoder::AbstractHeapType::Extern,
        wasmparser::AbstractHeapType::Any => wasm_encoder::AbstractHeapType::Any,
        wasmparser::AbstractHeapType::None => wasm_encoder::AbstractHeapType::None,
        wasmparser::AbstractHeapType::NoExtern => wasm_encoder::AbstractHeapType::NoExtern,
        wasmparser::AbstractHeapType::NoFunc => wasm_encoder::AbstractHeapType::NoFunc,
        wasmparser::AbstractHeapType::Eq => wasm_encoder::AbstractHeapType::Eq,
        wasmparser::AbstractHeapType::Struct => wasm_encoder::AbstractHeapType::Struct,
        wasmparser::AbstractHeapType::Array => wasm_encoder::AbstractHeapType::Array,
        wasmparser::AbstractHeapType::I31 => wasm_encoder::AbstractHeapType::I31,
        wasmparser::AbstractHeapType::Exn => wasm_encoder::AbstractHeapType::Exn,
        wasmparser::AbstractHeapType::NoExn => wasm_encoder::AbstractHeapType::NoExn,
        _ => unimplemented!("translate_abstract_heap_type: {:?}", t),
    }
}

pub struct DefaultRebinder;
impl Rebind for DefaultRebinder {}

pub fn translate<'a, R: Rebind>(op: &wasmparser::Operator<'a>, rebinder: &R) -> Instruction<'a> {
    match op {
        wasmparser::Operator::Unreachable => Instruction::Unreachable,
        wasmparser::Operator::Nop => Instruction::Nop,
        wasmparser::Operator::Block { blockty } => {
            Instruction::Block(translate_block_type(*blockty, rebinder))
        }
        wasmparser::Operator::Loop { blockty } => {
            Instruction::Loop(translate_block_type(*blockty, rebinder))
        }
        wasmparser::Operator::If { blockty } => {
            Instruction::If(translate_block_type(*blockty, rebinder))
        }
        wasmparser::Operator::Else => Instruction::Else,
        wasmparser::Operator::End => Instruction::End,
        wasmparser::Operator::Br { relative_depth } => Instruction::Br(*relative_depth),
        wasmparser::Operator::BrIf { relative_depth } => Instruction::BrIf(*relative_depth),
        wasmparser::Operator::BrTable { targets } => {
            let t: Vec<u32> = targets.targets().collect::<Result<Vec<_>, _>>().unwrap();
            Instruction::BrTable(std::borrow::Cow::Owned(t), targets.default())
        }
        wasmparser::Operator::Return => Instruction::Return,
        wasmparser::Operator::Call { function_index } => {
            Instruction::Call(rebinder.function(*function_index))
        }
        wasmparser::Operator::CallIndirect {
            type_index,
            table_index,
            ..
        } => Instruction::CallIndirect {
            type_index: rebinder.ty(*type_index),
            table_index: rebinder.table(*table_index),
        },
        wasmparser::Operator::Drop => Instruction::Drop,
        wasmparser::Operator::Select => Instruction::Select,
        wasmparser::Operator::LocalGet { local_index } => Instruction::LocalGet(*local_index),
        wasmparser::Operator::LocalSet { local_index } => Instruction::LocalSet(*local_index),
        wasmparser::Operator::LocalTee { local_index } => Instruction::LocalTee(*local_index),
        wasmparser::Operator::GlobalGet { global_index } => {
            Instruction::GlobalGet(rebinder.global(*global_index))
        }
        wasmparser::Operator::GlobalSet { global_index } => {
            Instruction::GlobalSet(rebinder.global(*global_index))
        }
        wasmparser::Operator::I32Load { memarg } => {
            Instruction::I32Load(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Load { memarg } => {
            Instruction::I64Load(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::F32Load { memarg } => {
            Instruction::F32Load(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::F64Load { memarg } => {
            Instruction::F64Load(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32Load8S { memarg } => {
            Instruction::I32Load8S(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32Load8U { memarg } => {
            Instruction::I32Load8U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32Load16S { memarg } => {
            Instruction::I32Load16S(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32Load16U { memarg } => {
            Instruction::I32Load16U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Load8S { memarg } => {
            Instruction::I64Load8S(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Load8U { memarg } => {
            Instruction::I64Load8U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Load16S { memarg } => {
            Instruction::I64Load16S(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Load16U { memarg } => {
            Instruction::I64Load16U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Load32S { memarg } => {
            Instruction::I64Load32S(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Load32U { memarg } => {
            Instruction::I64Load32U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32Store { memarg } => {
            Instruction::I32Store(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Store { memarg } => {
            Instruction::I64Store(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::F32Store { memarg } => {
            Instruction::F32Store(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::F64Store { memarg } => {
            Instruction::F64Store(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32Store8 { memarg } => {
            Instruction::I32Store8(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32Store16 { memarg } => {
            Instruction::I32Store16(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Store8 { memarg } => {
            Instruction::I64Store8(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Store16 { memarg } => {
            Instruction::I64Store16(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64Store32 { memarg } => {
            Instruction::I64Store32(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::MemorySize { mem } => Instruction::MemorySize(rebinder.memory(*mem)),
        wasmparser::Operator::MemoryGrow { mem } => Instruction::MemoryGrow(rebinder.memory(*mem)),
        wasmparser::Operator::I32Const { value } => Instruction::I32Const(*value),
        wasmparser::Operator::I64Const { value } => Instruction::I64Const(*value),
        wasmparser::Operator::F32Const { value } => {
            Instruction::F32Const(f32::from_bits(value.bits()).into())
        }
        wasmparser::Operator::F64Const { value } => {
            Instruction::F64Const(f64::from_bits(value.bits()).into())
        }
        wasmparser::Operator::I32Eqz => Instruction::I32Eqz,
        wasmparser::Operator::I32Eq => Instruction::I32Eq,
        wasmparser::Operator::I32Ne => Instruction::I32Ne,
        wasmparser::Operator::I32LtS => Instruction::I32LtS,
        wasmparser::Operator::I32LtU => Instruction::I32LtU,
        wasmparser::Operator::I32GtS => Instruction::I32GtS,
        wasmparser::Operator::I32GtU => Instruction::I32GtU,
        wasmparser::Operator::I32LeS => Instruction::I32LeS,
        wasmparser::Operator::I32LeU => Instruction::I32LeU,
        wasmparser::Operator::I32GeS => Instruction::I32GeS,
        wasmparser::Operator::I32GeU => Instruction::I32GeU,
        wasmparser::Operator::I64Eqz => Instruction::I64Eqz,
        wasmparser::Operator::I64Eq => Instruction::I64Eq,
        wasmparser::Operator::I64Ne => Instruction::I64Ne,
        wasmparser::Operator::I64LtS => Instruction::I64LtS,
        wasmparser::Operator::I64LtU => Instruction::I64LtU,
        wasmparser::Operator::I64GtS => Instruction::I64GtS,
        wasmparser::Operator::I64GtU => Instruction::I64GtU,
        wasmparser::Operator::I64LeS => Instruction::I64LeS,
        wasmparser::Operator::I64LeU => Instruction::I64LeU,
        wasmparser::Operator::I64GeS => Instruction::I64GeS,
        wasmparser::Operator::I64GeU => Instruction::I64GeU,
        wasmparser::Operator::F32Eq => Instruction::F32Eq,
        wasmparser::Operator::F32Ne => Instruction::F32Ne,
        wasmparser::Operator::F32Lt => Instruction::F32Lt,
        wasmparser::Operator::F32Gt => Instruction::F32Gt,
        wasmparser::Operator::F32Le => Instruction::F32Le,
        wasmparser::Operator::F32Ge => Instruction::F32Ge,
        wasmparser::Operator::F64Eq => Instruction::F64Eq,
        wasmparser::Operator::F64Ne => Instruction::F64Ne,
        wasmparser::Operator::F64Lt => Instruction::F64Lt,
        wasmparser::Operator::F64Gt => Instruction::F64Gt,
        wasmparser::Operator::F64Le => Instruction::F64Le,
        wasmparser::Operator::F64Ge => Instruction::F64Ge,
        wasmparser::Operator::I32Clz => Instruction::I32Clz,
        wasmparser::Operator::I32Ctz => Instruction::I32Ctz,
        wasmparser::Operator::I32Popcnt => Instruction::I32Popcnt,
        wasmparser::Operator::I32Add => Instruction::I32Add,
        wasmparser::Operator::I32Sub => Instruction::I32Sub,
        wasmparser::Operator::I32Mul => Instruction::I32Mul,
        wasmparser::Operator::I32DivS => Instruction::I32DivS,
        wasmparser::Operator::I32DivU => Instruction::I32DivU,
        wasmparser::Operator::I32RemS => Instruction::I32RemS,
        wasmparser::Operator::I32RemU => Instruction::I32RemU,
        wasmparser::Operator::I32And => Instruction::I32And,
        wasmparser::Operator::I32Or => Instruction::I32Or,
        wasmparser::Operator::I32Xor => Instruction::I32Xor,
        wasmparser::Operator::I32Shl => Instruction::I32Shl,
        wasmparser::Operator::I32ShrS => Instruction::I32ShrS,
        wasmparser::Operator::I32ShrU => Instruction::I32ShrU,
        wasmparser::Operator::I32Rotl => Instruction::I32Rotl,
        wasmparser::Operator::I32Rotr => Instruction::I32Rotr,
        wasmparser::Operator::I64Clz => Instruction::I64Clz,
        wasmparser::Operator::I64Ctz => Instruction::I64Ctz,
        wasmparser::Operator::I64Popcnt => Instruction::I64Popcnt,
        wasmparser::Operator::I64Add => Instruction::I64Add,
        wasmparser::Operator::I64Sub => Instruction::I64Sub,
        wasmparser::Operator::I64Mul => Instruction::I64Mul,
        wasmparser::Operator::I64DivS => Instruction::I64DivS,
        wasmparser::Operator::I64DivU => Instruction::I64DivU,
        wasmparser::Operator::I64RemS => Instruction::I64RemS,
        wasmparser::Operator::I64RemU => Instruction::I64RemU,
        wasmparser::Operator::I64And => Instruction::I64And,
        wasmparser::Operator::I64Or => Instruction::I64Or,
        wasmparser::Operator::I64Xor => Instruction::I64Xor,
        wasmparser::Operator::I64Shl => Instruction::I64Shl,
        wasmparser::Operator::I64ShrS => Instruction::I64ShrS,
        wasmparser::Operator::I64ShrU => Instruction::I64ShrU,
        wasmparser::Operator::I64Rotl => Instruction::I64Rotl,
        wasmparser::Operator::I64Rotr => Instruction::I64Rotr,
        wasmparser::Operator::F32Abs => Instruction::F32Abs,
        wasmparser::Operator::F32Neg => Instruction::F32Neg,
        wasmparser::Operator::F32Ceil => Instruction::F32Ceil,
        wasmparser::Operator::F32Floor => Instruction::F32Floor,
        wasmparser::Operator::F32Trunc => Instruction::F32Trunc,
        wasmparser::Operator::F32Nearest => Instruction::F32Nearest,
        wasmparser::Operator::F32Sqrt => Instruction::F32Sqrt,
        wasmparser::Operator::F32Add => Instruction::F32Add,
        wasmparser::Operator::F32Sub => Instruction::F32Sub,
        wasmparser::Operator::F32Mul => Instruction::F32Mul,
        wasmparser::Operator::F32Div => Instruction::F32Div,
        wasmparser::Operator::F32Min => Instruction::F32Min,
        wasmparser::Operator::F32Max => Instruction::F32Max,
        wasmparser::Operator::F32Copysign => Instruction::F32Copysign,
        wasmparser::Operator::F64Abs => Instruction::F64Abs,
        wasmparser::Operator::F64Neg => Instruction::F64Neg,
        wasmparser::Operator::F64Ceil => Instruction::F64Ceil,
        wasmparser::Operator::F64Floor => Instruction::F64Floor,
        wasmparser::Operator::F64Trunc => Instruction::F64Trunc,
        wasmparser::Operator::F64Nearest => Instruction::F64Nearest,
        wasmparser::Operator::F64Sqrt => Instruction::F64Sqrt,
        wasmparser::Operator::F64Add => Instruction::F64Add,
        wasmparser::Operator::F64Sub => Instruction::F64Sub,
        wasmparser::Operator::F64Mul => Instruction::F64Mul,
        wasmparser::Operator::F64Div => Instruction::F64Div,
        wasmparser::Operator::F64Min => Instruction::F64Min,
        wasmparser::Operator::F64Max => Instruction::F64Max,
        wasmparser::Operator::F64Copysign => Instruction::F64Copysign,
        wasmparser::Operator::I32WrapI64 => Instruction::I32WrapI64,
        wasmparser::Operator::I32TruncF32S => Instruction::I32TruncF32S,
        wasmparser::Operator::I32TruncF32U => Instruction::I32TruncF32U,
        wasmparser::Operator::I32TruncF64S => Instruction::I32TruncF64S,
        wasmparser::Operator::I32TruncF64U => Instruction::I32TruncF64U,
        wasmparser::Operator::I64ExtendI32S => Instruction::I64ExtendI32S,
        wasmparser::Operator::I64ExtendI32U => Instruction::I64ExtendI32U,
        wasmparser::Operator::I64TruncF32S => Instruction::I64TruncF32S,
        wasmparser::Operator::I64TruncF32U => Instruction::I64TruncF32U,
        wasmparser::Operator::I64TruncF64S => Instruction::I64TruncF64S,
        wasmparser::Operator::I64TruncF64U => Instruction::I64TruncF64U,
        wasmparser::Operator::F32ConvertI32S => Instruction::F32ConvertI32S,
        wasmparser::Operator::F32ConvertI32U => Instruction::F32ConvertI32U,
        wasmparser::Operator::F32ConvertI64S => Instruction::F32ConvertI64S,
        wasmparser::Operator::F32ConvertI64U => Instruction::F32ConvertI64U,
        wasmparser::Operator::F32DemoteF64 => Instruction::F32DemoteF64,
        wasmparser::Operator::F64ConvertI32S => Instruction::F64ConvertI32S,
        wasmparser::Operator::F64ConvertI32U => Instruction::F64ConvertI32U,
        wasmparser::Operator::F64ConvertI64S => Instruction::F64ConvertI64S,
        wasmparser::Operator::F64ConvertI64U => Instruction::F64ConvertI64U,
        wasmparser::Operator::F64PromoteF32 => Instruction::F64PromoteF32,
        wasmparser::Operator::I32ReinterpretF32 => Instruction::I32ReinterpretF32,
        wasmparser::Operator::I64ReinterpretF64 => Instruction::I64ReinterpretF64,
        wasmparser::Operator::F32ReinterpretI32 => Instruction::F32ReinterpretI32,
        wasmparser::Operator::F64ReinterpretI64 => Instruction::F64ReinterpretI64,
        wasmparser::Operator::I32Extend8S => Instruction::I32Extend8S,
        wasmparser::Operator::I32Extend16S => Instruction::I32Extend16S,
        wasmparser::Operator::I64Extend8S => Instruction::I64Extend8S,
        wasmparser::Operator::I64Extend16S => Instruction::I64Extend16S,
        wasmparser::Operator::I64Extend32S => Instruction::I64Extend32S,
        wasmparser::Operator::RefEq => Instruction::RefEq,
        wasmparser::Operator::StructNew { struct_type_index } => {
            Instruction::StructNew(*struct_type_index)
        }
        wasmparser::Operator::StructNewDefault { struct_type_index } => {
            Instruction::StructNewDefault(*struct_type_index)
        }
        wasmparser::Operator::StructGet {
            struct_type_index,
            field_index,
        } => Instruction::StructGet {
            struct_type_index: rebinder.ty(*struct_type_index),
            field_index: *field_index,
        },
        wasmparser::Operator::StructGetS {
            struct_type_index,
            field_index,
        } => Instruction::StructGetS {
            struct_type_index: rebinder.ty(*struct_type_index),
            field_index: *field_index,
        },
        wasmparser::Operator::StructGetU {
            struct_type_index,
            field_index,
        } => Instruction::StructGetU {
            struct_type_index: rebinder.ty(*struct_type_index),
            field_index: *field_index,
        },
        wasmparser::Operator::StructSet {
            struct_type_index,
            field_index,
        } => Instruction::StructSet {
            struct_type_index: rebinder.ty(*struct_type_index),
            field_index: *field_index,
        },
        wasmparser::Operator::ArrayNew { array_type_index } => {
            Instruction::ArrayNew(*array_type_index)
        }
        wasmparser::Operator::ArrayNewDefault { array_type_index } => {
            Instruction::ArrayNewDefault(*array_type_index)
        }
        wasmparser::Operator::ArrayNewFixed {
            array_type_index,
            array_size,
        } => Instruction::ArrayNewFixed {
            array_type_index: rebinder.ty(*array_type_index),
            array_size: *array_size,
        },
        wasmparser::Operator::ArrayNewData {
            array_type_index,
            array_data_index,
        } => Instruction::ArrayNewData {
            array_type_index: rebinder.ty(*array_type_index),
            array_data_index: rebinder.data(*array_data_index),
        },
        wasmparser::Operator::ArrayNewElem {
            array_type_index,
            array_elem_index,
        } => Instruction::ArrayNewElem {
            array_type_index: rebinder.ty(*array_type_index),
            array_elem_index: rebinder.elem(*array_elem_index),
        },
        wasmparser::Operator::ArrayGet { array_type_index } => {
            Instruction::ArrayGet(*array_type_index)
        }
        wasmparser::Operator::ArrayGetS { array_type_index } => {
            Instruction::ArrayGetS(*array_type_index)
        }
        wasmparser::Operator::ArrayGetU { array_type_index } => {
            Instruction::ArrayGetU(*array_type_index)
        }
        wasmparser::Operator::ArraySet { array_type_index } => {
            Instruction::ArraySet(*array_type_index)
        }
        wasmparser::Operator::ArrayLen => Instruction::ArrayLen,
        wasmparser::Operator::ArrayFill { array_type_index } => {
            Instruction::ArrayFill(rebinder.ty(*array_type_index))
        }
        wasmparser::Operator::ArrayCopy {
            array_type_index_dst,
            array_type_index_src,
        } => Instruction::ArrayCopy {
            array_type_index_dst: rebinder.ty(*array_type_index_dst),
            array_type_index_src: rebinder.ty(*array_type_index_src),
        },
        wasmparser::Operator::ArrayInitData {
            array_type_index,
            array_data_index,
        } => Instruction::ArrayInitData {
            array_type_index: rebinder.ty(*array_type_index),
            array_data_index: rebinder.data(*array_data_index),
        },
        wasmparser::Operator::ArrayInitElem {
            array_type_index,
            array_elem_index,
        } => Instruction::ArrayInitElem {
            array_type_index: rebinder.ty(*array_type_index),
            array_elem_index: rebinder.elem(*array_elem_index),
        },
        wasmparser::Operator::RefTestNonNull { hty: _ } => {
            unimplemented!("RefTestNonNull: GC types not supported")
        }
        wasmparser::Operator::RefTestNullable { hty: _ } => {
            unimplemented!("RefTestNullable: GC types not supported")
        }
        wasmparser::Operator::RefCastNonNull { hty: _ } => {
            unimplemented!("RefCastNonNull: GC types not supported")
        }
        wasmparser::Operator::RefCastNullable { hty: _ } => {
            unimplemented!("RefCastNullable: GC types not supported")
        }
        wasmparser::Operator::BrOnCast {
            relative_depth: _,
            from_ref_type: _,
            to_ref_type: _,
        } => unimplemented!("Wasm GC cast not supported"),
        wasmparser::Operator::BrOnCastFail {
            relative_depth: _,
            from_ref_type: _,
            to_ref_type: _,
        } => unimplemented!("Wasm GC cast not supported"),
        wasmparser::Operator::AnyConvertExtern => Instruction::AnyConvertExtern,
        wasmparser::Operator::ExternConvertAny => Instruction::ExternConvertAny,
        wasmparser::Operator::RefI31 => Instruction::RefI31,
        wasmparser::Operator::I31GetS => Instruction::I31GetS,
        wasmparser::Operator::I31GetU => Instruction::I31GetU,
        wasmparser::Operator::StructNewDesc { struct_type_index } => {
            Instruction::StructNewDesc(*struct_type_index)
        }
        wasmparser::Operator::StructNewDefaultDesc { struct_type_index } => {
            Instruction::StructNewDefaultDesc(*struct_type_index)
        }
        wasmparser::Operator::RefGetDesc { type_index } => {
            Instruction::RefGetDesc(rebinder.ty(*type_index))
        }
        wasmparser::Operator::RefCastDescEqNonNull { hty: _ } => {
            unimplemented!("RefCastDescEqNonNull: GC types not supported")
        }
        wasmparser::Operator::RefCastDescEqNullable { hty: _ } => {
            unimplemented!("RefCastDescEqNullable: GC types not supported")
        }
        wasmparser::Operator::BrOnCastDescEq {
            relative_depth: _,
            from_ref_type: _,
            to_ref_type: _,
        } => unimplemented!("BrOnCastDescEq: GC types not supported"),
        wasmparser::Operator::BrOnCastDescEqFail {
            relative_depth: _,
            from_ref_type: _,
            to_ref_type: _,
        } => unimplemented!("BrOnCastDescEqFail: GC types not supported"),
        wasmparser::Operator::I32TruncSatF32S => Instruction::I32TruncSatF32S,
        wasmparser::Operator::I32TruncSatF32U => Instruction::I32TruncSatF32U,
        wasmparser::Operator::I32TruncSatF64S => Instruction::I32TruncSatF64S,
        wasmparser::Operator::I32TruncSatF64U => Instruction::I32TruncSatF64U,
        wasmparser::Operator::I64TruncSatF32S => Instruction::I64TruncSatF32S,
        wasmparser::Operator::I64TruncSatF32U => Instruction::I64TruncSatF32U,
        wasmparser::Operator::I64TruncSatF64S => Instruction::I64TruncSatF64S,
        wasmparser::Operator::I64TruncSatF64U => Instruction::I64TruncSatF64U,
        wasmparser::Operator::MemoryInit { data_index, mem } => Instruction::MemoryInit {
            mem: rebinder.memory(*mem),
            data_index: rebinder.data(*data_index),
        },
        wasmparser::Operator::DataDrop { data_index } => {
            Instruction::DataDrop(rebinder.data(*data_index))
        }
        wasmparser::Operator::MemoryCopy { dst_mem, src_mem } => Instruction::MemoryCopy {
            src_mem: rebinder.memory(*src_mem),
            dst_mem: rebinder.memory(*dst_mem),
        },
        wasmparser::Operator::MemoryFill { mem } => Instruction::MemoryFill(rebinder.memory(*mem)),
        wasmparser::Operator::TableInit { elem_index, table } => Instruction::TableInit {
            table: rebinder.table(*table),
            elem_index: rebinder.elem(*elem_index),
        },
        wasmparser::Operator::ElemDrop { elem_index } => {
            Instruction::ElemDrop(rebinder.elem(*elem_index))
        }
        wasmparser::Operator::TableCopy {
            dst_table,
            src_table,
        } => Instruction::TableCopy {
            src_table: rebinder.table(*src_table),
            dst_table: rebinder.table(*dst_table),
        },
        wasmparser::Operator::TypedSelect { ty } => {
            Instruction::TypedSelect(translate_val_type(*ty, rebinder))
        }
        wasmparser::Operator::TypedSelectMulti { tys: _ } => {
            unimplemented!("TypedSelectMulti: GC types not supported")
        }
        wasmparser::Operator::RefNull { hty: _ } => unimplemented!("RefNull not supported"),
        wasmparser::Operator::RefIsNull => Instruction::RefIsNull,
        wasmparser::Operator::RefFunc { function_index } => {
            Instruction::RefFunc(rebinder.function(*function_index))
        }
        wasmparser::Operator::TableFill { table } => Instruction::TableFill(rebinder.table(*table)),
        wasmparser::Operator::TableGet { table } => Instruction::TableGet(rebinder.table(*table)),
        wasmparser::Operator::TableSet { table } => Instruction::TableSet(rebinder.table(*table)),
        wasmparser::Operator::TableGrow { table } => Instruction::TableGrow(rebinder.table(*table)),
        wasmparser::Operator::TableSize { table } => Instruction::TableSize(rebinder.table(*table)),
        wasmparser::Operator::ReturnCall { function_index } => {
            Instruction::ReturnCall(rebinder.function(*function_index))
        }
        wasmparser::Operator::ReturnCallIndirect {
            type_index,
            table_index,
        } => Instruction::ReturnCallIndirect {
            type_index: rebinder.ty(*type_index),
            table_index: rebinder.table(*table_index),
        },
        wasmparser::Operator::MemoryDiscard { mem } => {
            Instruction::MemoryDiscard(rebinder.memory(*mem))
        }
        wasmparser::Operator::MemoryAtomicNotify { memarg } => {
            Instruction::MemoryAtomicNotify(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::MemoryAtomicWait32 { memarg } => {
            Instruction::MemoryAtomicWait32(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::MemoryAtomicWait64 { memarg } => {
            Instruction::MemoryAtomicWait64(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::AtomicFence => Instruction::AtomicFence,
        wasmparser::Operator::I32AtomicLoad { memarg } => {
            Instruction::I32AtomicLoad(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicLoad { memarg } => {
            Instruction::I64AtomicLoad(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicLoad8U { memarg } => {
            Instruction::I32AtomicLoad8U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicLoad16U { memarg } => {
            Instruction::I32AtomicLoad16U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicLoad8U { memarg } => {
            Instruction::I64AtomicLoad8U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicLoad16U { memarg } => {
            Instruction::I64AtomicLoad16U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicLoad32U { memarg } => {
            Instruction::I64AtomicLoad32U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicStore { memarg } => {
            Instruction::I32AtomicStore(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicStore { memarg } => {
            Instruction::I64AtomicStore(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicStore8 { memarg } => {
            Instruction::I32AtomicStore8(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicStore16 { memarg } => {
            Instruction::I32AtomicStore16(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicStore8 { memarg } => {
            Instruction::I64AtomicStore8(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicStore16 { memarg } => {
            Instruction::I64AtomicStore16(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicStore32 { memarg } => {
            Instruction::I64AtomicStore32(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmwAdd { memarg } => {
            Instruction::I32AtomicRmwAdd(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmwAdd { memarg } => {
            Instruction::I64AtomicRmwAdd(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw8AddU { memarg } => {
            Instruction::I32AtomicRmw8AddU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw16AddU { memarg } => {
            Instruction::I32AtomicRmw16AddU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw8AddU { memarg } => {
            Instruction::I64AtomicRmw8AddU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw16AddU { memarg } => {
            Instruction::I64AtomicRmw16AddU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw32AddU { memarg } => {
            Instruction::I64AtomicRmw32AddU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmwSub { memarg } => {
            Instruction::I32AtomicRmwSub(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmwSub { memarg } => {
            Instruction::I64AtomicRmwSub(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw8SubU { memarg } => {
            Instruction::I32AtomicRmw8SubU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw16SubU { memarg } => {
            Instruction::I32AtomicRmw16SubU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw8SubU { memarg } => {
            Instruction::I64AtomicRmw8SubU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw16SubU { memarg } => {
            Instruction::I64AtomicRmw16SubU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw32SubU { memarg } => {
            Instruction::I64AtomicRmw32SubU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmwAnd { memarg } => {
            Instruction::I32AtomicRmwAnd(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmwAnd { memarg } => {
            Instruction::I64AtomicRmwAnd(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw8AndU { memarg } => {
            Instruction::I32AtomicRmw8AndU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw16AndU { memarg } => {
            Instruction::I32AtomicRmw16AndU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw8AndU { memarg } => {
            Instruction::I64AtomicRmw8AndU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw16AndU { memarg } => {
            Instruction::I64AtomicRmw16AndU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw32AndU { memarg } => {
            Instruction::I64AtomicRmw32AndU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmwOr { memarg } => {
            Instruction::I32AtomicRmwOr(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmwOr { memarg } => {
            Instruction::I64AtomicRmwOr(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw8OrU { memarg } => {
            Instruction::I32AtomicRmw8OrU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw16OrU { memarg } => {
            Instruction::I32AtomicRmw16OrU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw8OrU { memarg } => {
            Instruction::I64AtomicRmw8OrU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw16OrU { memarg } => {
            Instruction::I64AtomicRmw16OrU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw32OrU { memarg } => {
            Instruction::I64AtomicRmw32OrU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmwXor { memarg } => {
            Instruction::I32AtomicRmwXor(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmwXor { memarg } => {
            Instruction::I64AtomicRmwXor(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw8XorU { memarg } => {
            Instruction::I32AtomicRmw8XorU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw16XorU { memarg } => {
            Instruction::I32AtomicRmw16XorU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw8XorU { memarg } => {
            Instruction::I64AtomicRmw8XorU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw16XorU { memarg } => {
            Instruction::I64AtomicRmw16XorU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw32XorU { memarg } => {
            Instruction::I64AtomicRmw32XorU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmwXchg { memarg } => {
            Instruction::I32AtomicRmwXchg(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmwXchg { memarg } => {
            Instruction::I64AtomicRmwXchg(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw8XchgU { memarg } => {
            Instruction::I32AtomicRmw8XchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw16XchgU { memarg } => {
            Instruction::I32AtomicRmw16XchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw8XchgU { memarg } => {
            Instruction::I64AtomicRmw8XchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw16XchgU { memarg } => {
            Instruction::I64AtomicRmw16XchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw32XchgU { memarg } => {
            Instruction::I64AtomicRmw32XchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmwCmpxchg { memarg } => {
            Instruction::I32AtomicRmwCmpxchg(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmwCmpxchg { memarg } => {
            Instruction::I64AtomicRmwCmpxchg(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw8CmpxchgU { memarg } => {
            Instruction::I32AtomicRmw8CmpxchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I32AtomicRmw16CmpxchgU { memarg } => {
            Instruction::I32AtomicRmw16CmpxchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw8CmpxchgU { memarg } => {
            Instruction::I64AtomicRmw8CmpxchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw16CmpxchgU { memarg } => {
            Instruction::I64AtomicRmw16CmpxchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::I64AtomicRmw32CmpxchgU { memarg } => {
            Instruction::I64AtomicRmw32CmpxchgU(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load { memarg } => {
            Instruction::V128Load(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load8x8S { memarg } => {
            Instruction::V128Load8x8S(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load8x8U { memarg } => {
            Instruction::V128Load8x8U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load16x4S { memarg } => {
            Instruction::V128Load16x4S(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load16x4U { memarg } => {
            Instruction::V128Load16x4U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load32x2S { memarg } => {
            Instruction::V128Load32x2S(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load32x2U { memarg } => {
            Instruction::V128Load32x2U(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load8Splat { memarg } => {
            Instruction::V128Load8Splat(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load16Splat { memarg } => {
            Instruction::V128Load16Splat(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load32Splat { memarg } => {
            Instruction::V128Load32Splat(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load64Splat { memarg } => {
            Instruction::V128Load64Splat(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load32Zero { memarg } => {
            Instruction::V128Load32Zero(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load64Zero { memarg } => {
            Instruction::V128Load64Zero(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Store { memarg } => {
            Instruction::V128Store(translate_memarg(memarg, rebinder))
        }
        wasmparser::Operator::V128Load8Lane { memarg, lane } => Instruction::V128Load8Lane {
            memarg: translate_memarg(memarg, rebinder),
            lane: *lane,
        },
        wasmparser::Operator::V128Load16Lane { memarg, lane } => Instruction::V128Load16Lane {
            memarg: translate_memarg(memarg, rebinder),
            lane: *lane,
        },
        wasmparser::Operator::V128Load32Lane { memarg, lane } => Instruction::V128Load32Lane {
            memarg: translate_memarg(memarg, rebinder),
            lane: *lane,
        },
        wasmparser::Operator::V128Load64Lane { memarg, lane } => Instruction::V128Load64Lane {
            memarg: translate_memarg(memarg, rebinder),
            lane: *lane,
        },
        wasmparser::Operator::V128Store8Lane { memarg, lane } => Instruction::V128Store8Lane {
            memarg: translate_memarg(memarg, rebinder),
            lane: *lane,
        },
        wasmparser::Operator::V128Store16Lane { memarg, lane } => Instruction::V128Store16Lane {
            memarg: translate_memarg(memarg, rebinder),
            lane: *lane,
        },
        wasmparser::Operator::V128Store32Lane { memarg, lane } => Instruction::V128Store32Lane {
            memarg: translate_memarg(memarg, rebinder),
            lane: *lane,
        },
        wasmparser::Operator::V128Store64Lane { memarg, lane } => Instruction::V128Store64Lane {
            memarg: translate_memarg(memarg, rebinder),
            lane: *lane,
        },
        wasmparser::Operator::V128Const { value } => Instruction::V128Const(value.i128()),
        wasmparser::Operator::I8x16Shuffle { lanes } => Instruction::I8x16Shuffle(*lanes),
        wasmparser::Operator::I8x16ExtractLaneS { lane } => Instruction::I8x16ExtractLaneS(*lane),
        wasmparser::Operator::I8x16ExtractLaneU { lane } => Instruction::I8x16ExtractLaneU(*lane),
        wasmparser::Operator::I8x16ReplaceLane { lane } => Instruction::I8x16ReplaceLane(*lane),
        wasmparser::Operator::I16x8ExtractLaneS { lane } => Instruction::I16x8ExtractLaneS(*lane),
        wasmparser::Operator::I16x8ExtractLaneU { lane } => Instruction::I16x8ExtractLaneU(*lane),
        wasmparser::Operator::I16x8ReplaceLane { lane } => Instruction::I16x8ReplaceLane(*lane),
        wasmparser::Operator::I32x4ExtractLane { lane } => Instruction::I32x4ExtractLane(*lane),
        wasmparser::Operator::I32x4ReplaceLane { lane } => Instruction::I32x4ReplaceLane(*lane),
        wasmparser::Operator::I64x2ExtractLane { lane } => Instruction::I64x2ExtractLane(*lane),
        wasmparser::Operator::I64x2ReplaceLane { lane } => Instruction::I64x2ReplaceLane(*lane),
        wasmparser::Operator::F32x4ExtractLane { lane } => Instruction::F32x4ExtractLane(*lane),
        wasmparser::Operator::F32x4ReplaceLane { lane } => Instruction::F32x4ReplaceLane(*lane),
        wasmparser::Operator::F64x2ExtractLane { lane } => Instruction::F64x2ExtractLane(*lane),
        wasmparser::Operator::F64x2ReplaceLane { lane } => Instruction::F64x2ReplaceLane(*lane),
        wasmparser::Operator::I8x16Swizzle => Instruction::I8x16Swizzle,
        wasmparser::Operator::I8x16Splat => Instruction::I8x16Splat,
        wasmparser::Operator::I16x8Splat => Instruction::I16x8Splat,
        wasmparser::Operator::I32x4Splat => Instruction::I32x4Splat,
        wasmparser::Operator::I64x2Splat => Instruction::I64x2Splat,
        wasmparser::Operator::F32x4Splat => Instruction::F32x4Splat,
        wasmparser::Operator::F64x2Splat => Instruction::F64x2Splat,
        wasmparser::Operator::I8x16Eq => Instruction::I8x16Eq,
        wasmparser::Operator::I8x16Ne => Instruction::I8x16Ne,
        wasmparser::Operator::I8x16LtS => Instruction::I8x16LtS,
        wasmparser::Operator::I8x16LtU => Instruction::I8x16LtU,
        wasmparser::Operator::I8x16GtS => Instruction::I8x16GtS,
        wasmparser::Operator::I8x16GtU => Instruction::I8x16GtU,
        wasmparser::Operator::I8x16LeS => Instruction::I8x16LeS,
        wasmparser::Operator::I8x16LeU => Instruction::I8x16LeU,
        wasmparser::Operator::I8x16GeS => Instruction::I8x16GeS,
        wasmparser::Operator::I8x16GeU => Instruction::I8x16GeU,
        wasmparser::Operator::I16x8Eq => Instruction::I16x8Eq,
        wasmparser::Operator::I16x8Ne => Instruction::I16x8Ne,
        wasmparser::Operator::I16x8LtS => Instruction::I16x8LtS,
        wasmparser::Operator::I16x8LtU => Instruction::I16x8LtU,
        wasmparser::Operator::I16x8GtS => Instruction::I16x8GtS,
        wasmparser::Operator::I16x8GtU => Instruction::I16x8GtU,
        wasmparser::Operator::I16x8LeS => Instruction::I16x8LeS,
        wasmparser::Operator::I16x8LeU => Instruction::I16x8LeU,
        wasmparser::Operator::I16x8GeS => Instruction::I16x8GeS,
        wasmparser::Operator::I16x8GeU => Instruction::I16x8GeU,
        wasmparser::Operator::I32x4Eq => Instruction::I32x4Eq,
        wasmparser::Operator::I32x4Ne => Instruction::I32x4Ne,
        wasmparser::Operator::I32x4LtS => Instruction::I32x4LtS,
        wasmparser::Operator::I32x4LtU => Instruction::I32x4LtU,
        wasmparser::Operator::I32x4GtS => Instruction::I32x4GtS,
        wasmparser::Operator::I32x4GtU => Instruction::I32x4GtU,
        wasmparser::Operator::I32x4LeS => Instruction::I32x4LeS,
        wasmparser::Operator::I32x4LeU => Instruction::I32x4LeU,
        wasmparser::Operator::I32x4GeS => Instruction::I32x4GeS,
        wasmparser::Operator::I32x4GeU => Instruction::I32x4GeU,
        wasmparser::Operator::I64x2Eq => Instruction::I64x2Eq,
        wasmparser::Operator::I64x2Ne => Instruction::I64x2Ne,
        wasmparser::Operator::I64x2LtS => Instruction::I64x2LtS,
        wasmparser::Operator::I64x2GtS => Instruction::I64x2GtS,
        wasmparser::Operator::I64x2LeS => Instruction::I64x2LeS,
        wasmparser::Operator::I64x2GeS => Instruction::I64x2GeS,
        wasmparser::Operator::F32x4Eq => Instruction::F32x4Eq,
        wasmparser::Operator::F32x4Ne => Instruction::F32x4Ne,
        wasmparser::Operator::F32x4Lt => Instruction::F32x4Lt,
        wasmparser::Operator::F32x4Gt => Instruction::F32x4Gt,
        wasmparser::Operator::F32x4Le => Instruction::F32x4Le,
        wasmparser::Operator::F32x4Ge => Instruction::F32x4Ge,
        wasmparser::Operator::F64x2Eq => Instruction::F64x2Eq,
        wasmparser::Operator::F64x2Ne => Instruction::F64x2Ne,
        wasmparser::Operator::F64x2Lt => Instruction::F64x2Lt,
        wasmparser::Operator::F64x2Gt => Instruction::F64x2Gt,
        wasmparser::Operator::F64x2Le => Instruction::F64x2Le,
        wasmparser::Operator::F64x2Ge => Instruction::F64x2Ge,
        wasmparser::Operator::V128Not => Instruction::V128Not,
        wasmparser::Operator::V128And => Instruction::V128And,
        wasmparser::Operator::V128AndNot => Instruction::V128AndNot,
        wasmparser::Operator::V128Or => Instruction::V128Or,
        wasmparser::Operator::V128Xor => Instruction::V128Xor,
        wasmparser::Operator::V128Bitselect => Instruction::V128Bitselect,
        wasmparser::Operator::V128AnyTrue => Instruction::V128AnyTrue,
        wasmparser::Operator::I8x16Abs => Instruction::I8x16Abs,
        wasmparser::Operator::I8x16Neg => Instruction::I8x16Neg,
        wasmparser::Operator::I8x16Popcnt => Instruction::I8x16Popcnt,
        wasmparser::Operator::I8x16AllTrue => Instruction::I8x16AllTrue,
        wasmparser::Operator::I8x16Bitmask => Instruction::I8x16Bitmask,
        wasmparser::Operator::I8x16NarrowI16x8S => Instruction::I8x16NarrowI16x8S,
        wasmparser::Operator::I8x16NarrowI16x8U => Instruction::I8x16NarrowI16x8U,
        wasmparser::Operator::I8x16Shl => Instruction::I8x16Shl,
        wasmparser::Operator::I8x16ShrS => Instruction::I8x16ShrS,
        wasmparser::Operator::I8x16ShrU => Instruction::I8x16ShrU,
        wasmparser::Operator::I8x16Add => Instruction::I8x16Add,
        wasmparser::Operator::I8x16AddSatS => Instruction::I8x16AddSatS,
        wasmparser::Operator::I8x16AddSatU => Instruction::I8x16AddSatU,
        wasmparser::Operator::I8x16Sub => Instruction::I8x16Sub,
        wasmparser::Operator::I8x16SubSatS => Instruction::I8x16SubSatS,
        wasmparser::Operator::I8x16SubSatU => Instruction::I8x16SubSatU,
        wasmparser::Operator::I8x16MinS => Instruction::I8x16MinS,
        wasmparser::Operator::I8x16MinU => Instruction::I8x16MinU,
        wasmparser::Operator::I8x16MaxS => Instruction::I8x16MaxS,
        wasmparser::Operator::I8x16MaxU => Instruction::I8x16MaxU,
        wasmparser::Operator::I8x16AvgrU => Instruction::I8x16AvgrU,
        wasmparser::Operator::I16x8ExtAddPairwiseI8x16S => Instruction::I16x8ExtAddPairwiseI8x16S,
        wasmparser::Operator::I16x8ExtAddPairwiseI8x16U => Instruction::I16x8ExtAddPairwiseI8x16U,
        wasmparser::Operator::I16x8Abs => Instruction::I16x8Abs,
        wasmparser::Operator::I16x8Neg => Instruction::I16x8Neg,
        wasmparser::Operator::I16x8Q15MulrSatS => Instruction::I16x8Q15MulrSatS,
        wasmparser::Operator::I16x8AllTrue => Instruction::I16x8AllTrue,
        wasmparser::Operator::I16x8Bitmask => Instruction::I16x8Bitmask,
        wasmparser::Operator::I16x8NarrowI32x4S => Instruction::I16x8NarrowI32x4S,
        wasmparser::Operator::I16x8NarrowI32x4U => Instruction::I16x8NarrowI32x4U,
        wasmparser::Operator::I16x8ExtendLowI8x16S => Instruction::I16x8ExtendLowI8x16S,
        wasmparser::Operator::I16x8ExtendHighI8x16S => Instruction::I16x8ExtendHighI8x16S,
        wasmparser::Operator::I16x8ExtendLowI8x16U => Instruction::I16x8ExtendLowI8x16U,
        wasmparser::Operator::I16x8ExtendHighI8x16U => Instruction::I16x8ExtendHighI8x16U,
        wasmparser::Operator::I16x8Shl => Instruction::I16x8Shl,
        wasmparser::Operator::I16x8ShrS => Instruction::I16x8ShrS,
        wasmparser::Operator::I16x8ShrU => Instruction::I16x8ShrU,
        wasmparser::Operator::I16x8Add => Instruction::I16x8Add,
        wasmparser::Operator::I16x8AddSatS => Instruction::I16x8AddSatS,
        wasmparser::Operator::I16x8AddSatU => Instruction::I16x8AddSatU,
        wasmparser::Operator::I16x8Sub => Instruction::I16x8Sub,
        wasmparser::Operator::I16x8SubSatS => Instruction::I16x8SubSatS,
        wasmparser::Operator::I16x8SubSatU => Instruction::I16x8SubSatU,
        wasmparser::Operator::I16x8Mul => Instruction::I16x8Mul,
        wasmparser::Operator::I16x8MinS => Instruction::I16x8MinS,
        wasmparser::Operator::I16x8MinU => Instruction::I16x8MinU,
        wasmparser::Operator::I16x8MaxS => Instruction::I16x8MaxS,
        wasmparser::Operator::I16x8MaxU => Instruction::I16x8MaxU,
        wasmparser::Operator::I16x8AvgrU => Instruction::I16x8AvgrU,
        wasmparser::Operator::I16x8ExtMulLowI8x16S => Instruction::I16x8ExtMulLowI8x16S,
        wasmparser::Operator::I16x8ExtMulHighI8x16S => Instruction::I16x8ExtMulHighI8x16S,
        wasmparser::Operator::I16x8ExtMulLowI8x16U => Instruction::I16x8ExtMulLowI8x16U,
        wasmparser::Operator::I16x8ExtMulHighI8x16U => Instruction::I16x8ExtMulHighI8x16U,
        wasmparser::Operator::I32x4ExtAddPairwiseI16x8S => Instruction::I32x4ExtAddPairwiseI16x8S,
        wasmparser::Operator::I32x4ExtAddPairwiseI16x8U => Instruction::I32x4ExtAddPairwiseI16x8U,
        wasmparser::Operator::I32x4Abs => Instruction::I32x4Abs,
        wasmparser::Operator::I32x4Neg => Instruction::I32x4Neg,
        wasmparser::Operator::I32x4AllTrue => Instruction::I32x4AllTrue,
        wasmparser::Operator::I32x4Bitmask => Instruction::I32x4Bitmask,
        wasmparser::Operator::I32x4ExtendLowI16x8S => Instruction::I32x4ExtendLowI16x8S,
        wasmparser::Operator::I32x4ExtendHighI16x8S => Instruction::I32x4ExtendHighI16x8S,
        wasmparser::Operator::I32x4ExtendLowI16x8U => Instruction::I32x4ExtendLowI16x8U,
        wasmparser::Operator::I32x4ExtendHighI16x8U => Instruction::I32x4ExtendHighI16x8U,
        wasmparser::Operator::I32x4Shl => Instruction::I32x4Shl,
        wasmparser::Operator::I32x4ShrS => Instruction::I32x4ShrS,
        wasmparser::Operator::I32x4ShrU => Instruction::I32x4ShrU,
        wasmparser::Operator::I32x4Add => Instruction::I32x4Add,
        wasmparser::Operator::I32x4Sub => Instruction::I32x4Sub,
        wasmparser::Operator::I32x4Mul => Instruction::I32x4Mul,
        wasmparser::Operator::I32x4MinS => Instruction::I32x4MinS,
        wasmparser::Operator::I32x4MinU => Instruction::I32x4MinU,
        wasmparser::Operator::I32x4MaxS => Instruction::I32x4MaxS,
        wasmparser::Operator::I32x4MaxU => Instruction::I32x4MaxU,
        wasmparser::Operator::I32x4DotI16x8S => Instruction::I32x4DotI16x8S,
        wasmparser::Operator::I32x4ExtMulLowI16x8S => Instruction::I32x4ExtMulLowI16x8S,
        wasmparser::Operator::I32x4ExtMulHighI16x8S => Instruction::I32x4ExtMulHighI16x8S,
        wasmparser::Operator::I32x4ExtMulLowI16x8U => Instruction::I32x4ExtMulLowI16x8U,
        wasmparser::Operator::I32x4ExtMulHighI16x8U => Instruction::I32x4ExtMulHighI16x8U,
        wasmparser::Operator::I64x2Abs => Instruction::I64x2Abs,
        wasmparser::Operator::I64x2Neg => Instruction::I64x2Neg,
        wasmparser::Operator::I64x2AllTrue => Instruction::I64x2AllTrue,
        wasmparser::Operator::I64x2Bitmask => Instruction::I64x2Bitmask,
        wasmparser::Operator::I64x2ExtendLowI32x4S => Instruction::I64x2ExtendLowI32x4S,
        wasmparser::Operator::I64x2ExtendHighI32x4S => Instruction::I64x2ExtendHighI32x4S,
        wasmparser::Operator::I64x2ExtendLowI32x4U => Instruction::I64x2ExtendLowI32x4U,
        wasmparser::Operator::I64x2ExtendHighI32x4U => Instruction::I64x2ExtendHighI32x4U,
        wasmparser::Operator::I64x2Shl => Instruction::I64x2Shl,
        wasmparser::Operator::I64x2ShrS => Instruction::I64x2ShrS,
        wasmparser::Operator::I64x2ShrU => Instruction::I64x2ShrU,
        wasmparser::Operator::I64x2Add => Instruction::I64x2Add,
        wasmparser::Operator::I64x2Sub => Instruction::I64x2Sub,
        wasmparser::Operator::I64x2Mul => Instruction::I64x2Mul,
        wasmparser::Operator::I64x2ExtMulLowI32x4S => Instruction::I64x2ExtMulLowI32x4S,
        wasmparser::Operator::I64x2ExtMulHighI32x4S => Instruction::I64x2ExtMulHighI32x4S,
        wasmparser::Operator::I64x2ExtMulLowI32x4U => Instruction::I64x2ExtMulLowI32x4U,
        wasmparser::Operator::I64x2ExtMulHighI32x4U => Instruction::I64x2ExtMulHighI32x4U,
        wasmparser::Operator::F32x4Ceil => Instruction::F32x4Ceil,
        wasmparser::Operator::F32x4Floor => Instruction::F32x4Floor,
        wasmparser::Operator::F32x4Trunc => Instruction::F32x4Trunc,
        wasmparser::Operator::F32x4Nearest => Instruction::F32x4Nearest,
        wasmparser::Operator::F32x4Abs => Instruction::F32x4Abs,
        wasmparser::Operator::F32x4Neg => Instruction::F32x4Neg,
        wasmparser::Operator::F32x4Sqrt => Instruction::F32x4Sqrt,
        wasmparser::Operator::F32x4Add => Instruction::F32x4Add,
        wasmparser::Operator::F32x4Sub => Instruction::F32x4Sub,
        wasmparser::Operator::F32x4Mul => Instruction::F32x4Mul,
        wasmparser::Operator::F32x4Div => Instruction::F32x4Div,
        wasmparser::Operator::F32x4Min => Instruction::F32x4Min,
        wasmparser::Operator::F32x4Max => Instruction::F32x4Max,
        wasmparser::Operator::F32x4PMin => Instruction::F32x4PMin,
        wasmparser::Operator::F32x4PMax => Instruction::F32x4PMax,
        wasmparser::Operator::F64x2Ceil => Instruction::F64x2Ceil,
        wasmparser::Operator::F64x2Floor => Instruction::F64x2Floor,
        wasmparser::Operator::F64x2Trunc => Instruction::F64x2Trunc,
        wasmparser::Operator::F64x2Nearest => Instruction::F64x2Nearest,
        wasmparser::Operator::F64x2Abs => Instruction::F64x2Abs,
        wasmparser::Operator::F64x2Neg => Instruction::F64x2Neg,
        wasmparser::Operator::F64x2Sqrt => Instruction::F64x2Sqrt,
        wasmparser::Operator::F64x2Add => Instruction::F64x2Add,
        wasmparser::Operator::F64x2Sub => Instruction::F64x2Sub,
        wasmparser::Operator::F64x2Mul => Instruction::F64x2Mul,
        wasmparser::Operator::F64x2Div => Instruction::F64x2Div,
        wasmparser::Operator::F64x2Min => Instruction::F64x2Min,
        wasmparser::Operator::F64x2Max => Instruction::F64x2Max,
        wasmparser::Operator::F64x2PMin => Instruction::F64x2PMin,
        wasmparser::Operator::F64x2PMax => Instruction::F64x2PMax,
        wasmparser::Operator::I32x4TruncSatF32x4S => Instruction::I32x4TruncSatF32x4S,
        wasmparser::Operator::I32x4TruncSatF32x4U => Instruction::I32x4TruncSatF32x4U,
        wasmparser::Operator::F32x4ConvertI32x4S => Instruction::F32x4ConvertI32x4S,
        wasmparser::Operator::F32x4ConvertI32x4U => Instruction::F32x4ConvertI32x4U,
        wasmparser::Operator::I32x4TruncSatF64x2SZero => Instruction::I32x4TruncSatF64x2SZero,
        wasmparser::Operator::I32x4TruncSatF64x2UZero => Instruction::I32x4TruncSatF64x2UZero,
        wasmparser::Operator::F64x2ConvertLowI32x4S => Instruction::F64x2ConvertLowI32x4S,
        wasmparser::Operator::F64x2ConvertLowI32x4U => Instruction::F64x2ConvertLowI32x4U,
        wasmparser::Operator::F32x4DemoteF64x2Zero => Instruction::F32x4DemoteF64x2Zero,
        wasmparser::Operator::F64x2PromoteLowF32x4 => Instruction::F64x2PromoteLowF32x4,
        wasmparser::Operator::I8x16RelaxedSwizzle => Instruction::I8x16RelaxedSwizzle,
        wasmparser::Operator::I32x4RelaxedTruncF32x4S => Instruction::I32x4RelaxedTruncF32x4S,
        wasmparser::Operator::I32x4RelaxedTruncF32x4U => Instruction::I32x4RelaxedTruncF32x4U,
        wasmparser::Operator::I32x4RelaxedTruncF64x2SZero => {
            Instruction::I32x4RelaxedTruncF64x2SZero
        }
        wasmparser::Operator::I32x4RelaxedTruncF64x2UZero => {
            Instruction::I32x4RelaxedTruncF64x2UZero
        }
        wasmparser::Operator::F32x4RelaxedMadd => Instruction::F32x4RelaxedMadd,
        wasmparser::Operator::F32x4RelaxedNmadd => Instruction::F32x4RelaxedNmadd,
        wasmparser::Operator::F64x2RelaxedMadd => Instruction::F64x2RelaxedMadd,
        wasmparser::Operator::F64x2RelaxedNmadd => Instruction::F64x2RelaxedNmadd,
        wasmparser::Operator::I8x16RelaxedLaneselect => Instruction::I8x16RelaxedLaneselect,
        wasmparser::Operator::I16x8RelaxedLaneselect => Instruction::I16x8RelaxedLaneselect,
        wasmparser::Operator::I32x4RelaxedLaneselect => Instruction::I32x4RelaxedLaneselect,
        wasmparser::Operator::I64x2RelaxedLaneselect => Instruction::I64x2RelaxedLaneselect,
        wasmparser::Operator::F32x4RelaxedMin => Instruction::F32x4RelaxedMin,
        wasmparser::Operator::F32x4RelaxedMax => Instruction::F32x4RelaxedMax,
        wasmparser::Operator::F64x2RelaxedMin => Instruction::F64x2RelaxedMin,
        wasmparser::Operator::F64x2RelaxedMax => Instruction::F64x2RelaxedMax,
        wasmparser::Operator::I16x8RelaxedQ15mulrS => Instruction::I16x8RelaxedQ15mulrS,
        wasmparser::Operator::I16x8RelaxedDotI8x16I7x16S => Instruction::I16x8RelaxedDotI8x16I7x16S,
        wasmparser::Operator::I32x4RelaxedDotI8x16I7x16AddS => {
            Instruction::I32x4RelaxedDotI8x16I7x16AddS
        }
        wasmparser::Operator::TryTable { try_table } => Instruction::TryTable(
            translate_block_type(try_table.ty, rebinder),
            std::borrow::Cow::Owned(
                try_table
                    .catches
                    .iter()
                    .map(|c| translate_catch(c, rebinder))
                    .collect(),
            ),
        ),
        wasmparser::Operator::Throw { tag_index } => Instruction::Throw(rebinder.tag(*tag_index)),
        wasmparser::Operator::ThrowRef => Instruction::ThrowRef,
        wasmparser::Operator::Try { blockty } => {
            Instruction::Try(translate_block_type(*blockty, rebinder))
        }
        wasmparser::Operator::Catch { tag_index } => Instruction::Catch(rebinder.tag(*tag_index)),
        wasmparser::Operator::Rethrow { relative_depth } => Instruction::Rethrow(*relative_depth),
        wasmparser::Operator::Delegate { relative_depth } => Instruction::Delegate(*relative_depth),
        wasmparser::Operator::CatchAll => Instruction::CatchAll,
        wasmparser::Operator::GlobalAtomicGet {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicGet"),
        wasmparser::Operator::GlobalAtomicSet {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicSet"),
        wasmparser::Operator::GlobalAtomicRmwAdd {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicRmwAdd"),
        wasmparser::Operator::GlobalAtomicRmwSub {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicRmwSub"),
        wasmparser::Operator::GlobalAtomicRmwAnd {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicRmwAnd"),
        wasmparser::Operator::GlobalAtomicRmwOr {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicRmwOr"),
        wasmparser::Operator::GlobalAtomicRmwXor {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicRmwXor"),
        wasmparser::Operator::GlobalAtomicRmwXchg {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicRmwXchg"),
        wasmparser::Operator::GlobalAtomicRmwCmpxchg {
            ordering: _,
            global_index: _,
        } => unimplemented!("GlobalAtomicRmwCmpxchg"),
        wasmparser::Operator::TableAtomicGet {
            ordering: _,
            table_index: _,
        } => unimplemented!("TableAtomicGet"),
        wasmparser::Operator::TableAtomicSet {
            ordering: _,
            table_index: _,
        } => unimplemented!("TableAtomicSet"),
        wasmparser::Operator::TableAtomicRmwXchg {
            ordering: _,
            table_index: _,
        } => unimplemented!("TableAtomicRmwXchg"),
        wasmparser::Operator::TableAtomicRmwCmpxchg {
            ordering: _,
            table_index: _,
        } => unimplemented!("TableAtomicRmwCmpxchg"),
        wasmparser::Operator::StructAtomicGet {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicGet"),
        wasmparser::Operator::StructAtomicGetS {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicGetS"),
        wasmparser::Operator::StructAtomicGetU {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicGetU"),
        wasmparser::Operator::StructAtomicSet {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicSet"),
        wasmparser::Operator::StructAtomicRmwAdd {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicRmwAdd"),
        wasmparser::Operator::StructAtomicRmwSub {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicRmwSub"),
        wasmparser::Operator::StructAtomicRmwAnd {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicRmwAnd"),
        wasmparser::Operator::StructAtomicRmwOr {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicRmwOr"),
        wasmparser::Operator::StructAtomicRmwXor {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicRmwXor"),
        wasmparser::Operator::StructAtomicRmwXchg {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicRmwXchg"),
        wasmparser::Operator::StructAtomicRmwCmpxchg {
            ordering: _,
            struct_type_index: _,
            field_index: _,
        } => unimplemented!("StructAtomicRmwCmpxchg"),
        wasmparser::Operator::ArrayAtomicGet {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicGet"),
        wasmparser::Operator::ArrayAtomicGetS {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicGetS"),
        wasmparser::Operator::ArrayAtomicGetU {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicGetU"),
        wasmparser::Operator::ArrayAtomicSet {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicSet"),
        wasmparser::Operator::ArrayAtomicRmwAdd {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicRmwAdd"),
        wasmparser::Operator::ArrayAtomicRmwSub {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicRmwSub"),
        wasmparser::Operator::ArrayAtomicRmwAnd {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicRmwAnd"),
        wasmparser::Operator::ArrayAtomicRmwOr {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicRmwOr"),
        wasmparser::Operator::ArrayAtomicRmwXor {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicRmwXor"),
        wasmparser::Operator::ArrayAtomicRmwXchg {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicRmwXchg"),
        wasmparser::Operator::ArrayAtomicRmwCmpxchg {
            ordering: _,
            array_type_index: _,
        } => unimplemented!("ArrayAtomicRmwCmpxchg"),
        wasmparser::Operator::RefI31Shared => unimplemented!("RefI31Shared"),
        wasmparser::Operator::CallRef { type_index } => {
            Instruction::CallRef(rebinder.ty(*type_index))
        }
        wasmparser::Operator::ReturnCallRef { type_index } => {
            Instruction::ReturnCallRef(rebinder.ty(*type_index))
        }
        wasmparser::Operator::RefAsNonNull => unimplemented!("RefAsNonNull"),
        wasmparser::Operator::BrOnNull { relative_depth } => Instruction::BrOnNull(*relative_depth),
        wasmparser::Operator::BrOnNonNull { relative_depth } => {
            Instruction::BrOnNonNull(*relative_depth)
        }
        wasmparser::Operator::ContNew { cont_type_index: _ } => unimplemented!("ContNew"),
        wasmparser::Operator::ContBind {
            argument_index: _,
            result_index: _,
        } => unimplemented!("ContBind"),
        wasmparser::Operator::Suspend { tag_index: _ } => unimplemented!("Suspend"),
        wasmparser::Operator::Resume {
            cont_type_index: _,
            resume_table: _,
        } => unimplemented!("Resume"),
        wasmparser::Operator::ResumeThrow {
            cont_type_index: _,
            tag_index: _,
            resume_table: _,
        } => unimplemented!("ResumeThrow"),
        wasmparser::Operator::ResumeThrowRef {
            cont_type_index: _,
            resume_table: _,
        } => unimplemented!("ResumeThrowRef"),
        wasmparser::Operator::Switch {
            cont_type_index: _,
            tag_index: _,
        } => unimplemented!("Switch"),
        wasmparser::Operator::I64Add128 => unimplemented!("I64Add128"),
        wasmparser::Operator::I64Sub128 => unimplemented!("I64Sub128"),
        wasmparser::Operator::I64MulWideS => unimplemented!("I64MulWideS"),
        wasmparser::Operator::I64MulWideU => unimplemented!("I64MulWideU"),
        _ => unimplemented!("unsupported wasmparser operator"),
    }
}

pub fn translate_val_type<R: Rebind>(
    ty: wasmparser::ValType,
    rebinder: &R,
) -> wasm_encoder::ValType {
    match ty {
        wasmparser::ValType::I32 => wasm_encoder::ValType::I32,
        wasmparser::ValType::I64 => wasm_encoder::ValType::I64,
        wasmparser::ValType::F32 => wasm_encoder::ValType::F32,
        wasmparser::ValType::F64 => wasm_encoder::ValType::F64,
        wasmparser::ValType::V128 => wasm_encoder::ValType::V128,
        wasmparser::ValType::Ref(r) => wasm_encoder::ValType::Ref(translate_ref_type(r, rebinder)),
    }
}

pub fn translate_block_type<R: Rebind>(
    bty: wasmparser::BlockType,
    rebinder: &R,
) -> wasm_encoder::BlockType {
    match bty {
        wasmparser::BlockType::Empty => wasm_encoder::BlockType::Empty,
        wasmparser::BlockType::Type(ty) => {
            wasm_encoder::BlockType::Result(translate_val_type(ty, rebinder))
        }
        wasmparser::BlockType::FuncType(idx) => {
            wasm_encoder::BlockType::FunctionType(rebinder.ty(idx))
        }
    }
}

pub fn translate_catch<R: Rebind>(catch: &wasmparser::Catch, rebinder: &R) -> wasm_encoder::Catch {
    match catch {
        wasmparser::Catch::One { tag, label } => wasm_encoder::Catch::One {
            tag: rebinder.tag(*tag),
            label: *label,
        },
        wasmparser::Catch::OneRef { tag, label } => wasm_encoder::Catch::OneRef {
            tag: rebinder.tag(*tag),
            label: *label,
        },
        wasmparser::Catch::All { label } => wasm_encoder::Catch::All { label: *label },
        wasmparser::Catch::AllRef { label } => wasm_encoder::Catch::AllRef { label: *label },
    }
}

pub fn translate_memarg<R: Rebind>(
    memarg: &wasmparser::MemArg,
    rebinder: &R,
) -> wasm_encoder::MemArg {
    wasm_encoder::MemArg {
        offset: memarg.offset,
        align: memarg.align.into(),
        memory_index: rebinder.memory(memarg.memory),
    }
}

pub fn translate_const_expr<R: Rebind>(
    expr: &wasmparser::ConstExpr,
    rebinder: &R,
) -> Result<wasm_encoder::ConstExpr> {
    let mut reader = expr.get_operators_reader();
    let op = reader.read()?;
    match op {
        wasmparser::Operator::I32Const { value } => Ok(wasm_encoder::ConstExpr::i32_const(value)),
        wasmparser::Operator::I64Const { value } => Ok(wasm_encoder::ConstExpr::i64_const(value)),
        wasmparser::Operator::F32Const { value } => Ok(wasm_encoder::ConstExpr::f32_const(
            f32::from_bits(value.bits()).into(),
        )),
        wasmparser::Operator::F64Const { value } => Ok(wasm_encoder::ConstExpr::f64_const(
            f64::from_bits(value.bits()).into(),
        )),
        wasmparser::Operator::GlobalGet { global_index } => Ok(
            wasm_encoder::ConstExpr::global_get(rebinder.global(global_index)),
        ),
        wasmparser::Operator::RefNull { .. } => unimplemented!("RefNull not supported"),
        wasmparser::Operator::RefFunc { function_index } => Ok(wasm_encoder::ConstExpr::ref_func(
            rebinder.function(function_index),
        )),
        _ => eyre::bail!("Unsupported const expr operator: {:?}", op),
    }
}