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
//! WebAssembly instruction set.
use crate;
/// WebAssembly code consists of sequences of instructions.
/// Its computational model is based on a stack machine in that instructions manipulate values on
/// an implicit operand stack, consuming (popping) argument values and producing or returning
/// (pushing) result values.
/// In addition to dynamic operands from the stack,
/// some instructions also have static immediate arguments,
/// typically indices or type annotations, which are part of the instruction itself.
/// Some instructions are structured in that they bracket nested sequences of instructions.
/// The following sections group instructions into a number of different categories.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#instructions>
///
/// # Examples
/// See the specific instruction types for examples.
/// Numeric instructions provide basic operations over numeric values of specific type.
/// These operations closely match respective operations available in hardware.
///
/// Some integer instructions come in two flavors,
/// where a signedness annotation sx distinguishes whether the operands are to be interpreted as
/// unsigned or signed integers. For the other integer instructions, the use of twoβs complement
/// for the signed interpretation means that they behave the same regardless of signedness.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#numeric-instructions>
///
/// # Examples
/// ## Constant
/// ```rust
/// use wasm_ast::{NumericInstruction, Instruction};
///
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::I32Constant(42)),
/// 42i32.into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::I64Constant(42i64)),
/// 42i64.into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::F32Constant(0.1)),
/// 0.1f32.into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::F64Constant(0.2)),
/// 0.2f64.into()
/// );
/// ```
///
/// ## Integer
/// ```rust
/// use wasm_ast::{NumericInstruction, Instruction, IntegerType, SignExtension};
///
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::CountLeadingZeros(IntegerType::I32)),
/// NumericInstruction::CountLeadingZeros(IntegerType::I32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::CountTrailingZeros(IntegerType::I64)),
/// NumericInstruction::CountTrailingZeros(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::CountOnes(IntegerType::I64)),
/// NumericInstruction::CountOnes(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::DivideInteger(IntegerType::I64, SignExtension::Unsigned)),
/// NumericInstruction::DivideInteger(IntegerType::I64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Remainder(IntegerType::I64, SignExtension::Unsigned)),
/// NumericInstruction::Remainder(IntegerType::I64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::And(IntegerType::I64)),
/// NumericInstruction::And(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Or(IntegerType::I64)),
/// NumericInstruction::Or(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Xor(IntegerType::I64)),
/// NumericInstruction::Xor(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ShiftLeft(IntegerType::I64)),
/// NumericInstruction::ShiftLeft(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ShiftRight(IntegerType::I64, SignExtension::Unsigned)),
/// NumericInstruction::ShiftRight(IntegerType::I64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::RotateLeft(IntegerType::I64)),
/// NumericInstruction::RotateLeft(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::RotateRight(IntegerType::I64)),
/// NumericInstruction::RotateRight(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::EqualToZero(IntegerType::I64)),
/// NumericInstruction::EqualToZero(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::LessThanInteger(IntegerType::I64, SignExtension::Unsigned)),
/// NumericInstruction::LessThanInteger(IntegerType::I64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::GreaterThanInteger(IntegerType::I64, SignExtension::Unsigned)),
/// NumericInstruction::GreaterThanInteger(IntegerType::I64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::LessThanOrEqualToInteger(IntegerType::I64, SignExtension::Unsigned)),
/// NumericInstruction::LessThanOrEqualToInteger(IntegerType::I64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::GreaterThanOrEqualToInteger(IntegerType::I64, SignExtension::Unsigned)),
/// NumericInstruction::GreaterThanOrEqualToInteger(IntegerType::I64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ExtendSigned8(IntegerType::I64)),
/// NumericInstruction::ExtendSigned8(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ExtendSigned16(IntegerType::I64)),
/// NumericInstruction::ExtendSigned16(IntegerType::I64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ExtendSigned32),
/// NumericInstruction::ExtendSigned32.into()
/// );
/// ```
///
/// ## Float
/// ```rust
/// use wasm_ast::{NumericInstruction, Instruction, FloatType};
///
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::AbsoluteValue(FloatType::F32)),
/// NumericInstruction::AbsoluteValue(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Negate(FloatType::F64)),
/// NumericInstruction::Negate(FloatType::F64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::SquareRoot(FloatType::F64)),
/// NumericInstruction::SquareRoot(FloatType::F64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Ceiling(FloatType::F32)),
/// NumericInstruction::Ceiling(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Floor(FloatType::F64)),
/// NumericInstruction::Floor(FloatType::F64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Truncate(FloatType::F64)),
/// NumericInstruction::Truncate(FloatType::F64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Nearest(FloatType::F64)),
/// NumericInstruction::Nearest(FloatType::F64).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::DivideFloat(FloatType::F32)),
/// NumericInstruction::DivideFloat(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Minimum(FloatType::F32)),
/// NumericInstruction::Minimum(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Maximum(FloatType::F32)),
/// NumericInstruction::Maximum(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::CopySign(FloatType::F32)),
/// NumericInstruction::CopySign(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::LessThanFloat(FloatType::F32)),
/// NumericInstruction::LessThanFloat(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::GreaterThanFloat(FloatType::F32)),
/// NumericInstruction::GreaterThanFloat(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::LessThanOrEqualToFloat(FloatType::F32)),
/// NumericInstruction::LessThanOrEqualToFloat(FloatType::F32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::GreaterThanOrEqualToFloat(FloatType::F32)),
/// NumericInstruction::GreaterThanOrEqualToFloat(FloatType::F32).into()
/// );
/// ```
///
/// ## Number
/// ```rust
/// use wasm_ast::{NumericInstruction, Instruction, NumberType};
///
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Add(NumberType::I32)),
/// NumericInstruction::Add(NumberType::I32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Subtract(NumberType::I32)),
/// NumericInstruction::Subtract(NumberType::I32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Multiply(NumberType::I32)),
/// NumericInstruction::Multiply(NumberType::I32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Equal(NumberType::I32)),
/// NumericInstruction::Equal(NumberType::I32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::NotEqual(NumberType::I32)),
/// NumericInstruction::NotEqual(NumberType::I32).into()
/// );
/// ```
///
/// ## Convert
/// ```rust
/// use wasm_ast::{NumericInstruction, Instruction, NumberType, SignExtension, IntegerType, FloatType};
///
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Wrap),
/// NumericInstruction::Wrap.into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ExtendWithSignExtension(SignExtension::Signed)),
/// NumericInstruction::ExtendWithSignExtension(SignExtension::Signed).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ConvertAndTruncate(IntegerType::I32, FloatType::F64, SignExtension::Unsigned)),
/// NumericInstruction::ConvertAndTruncate(IntegerType::I32, FloatType::F64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ConvertAndTruncateWithSaturation(IntegerType::I32, FloatType::F64, SignExtension::Unsigned)),
/// NumericInstruction::ConvertAndTruncateWithSaturation(IntegerType::I32, FloatType::F64, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Demote),
/// NumericInstruction::Demote.into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Promote),
/// NumericInstruction::Promote.into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::Convert(FloatType::F64, IntegerType::I32, SignExtension::Unsigned)),
/// NumericInstruction::Convert(FloatType::F64, IntegerType::I32, SignExtension::Unsigned).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ReinterpretFloat(IntegerType::I32)),
/// NumericInstruction::ReinterpretFloat(IntegerType::I32).into()
/// );
/// assert_eq!(
/// Instruction::Numeric(NumericInstruction::ReinterpretInteger(FloatType::F64)),
/// NumericInstruction::ReinterpretInteger(FloatType::F64).into()
/// );
/// ```
/// Instructions in this group are concerned with accessing references.
/// These instruction produce a null value, check for a null value, or produce a reference to a given function, respectively.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#reference-instructions>
///
/// # Examples
/// ```rust
/// use wasm_ast::{ReferenceInstruction, Instruction, ReferenceType};
///
/// assert_eq!(
/// Instruction::Reference(ReferenceInstruction::Null(ReferenceType::External)),
/// ReferenceInstruction::Null(ReferenceType::External).into()
/// );
/// assert_eq!(
/// Instruction::Reference(ReferenceInstruction::IsNull),
/// ReferenceInstruction::IsNull.into()
/// );
/// assert_eq!(
/// Instruction::Reference(ReferenceInstruction::Function(3)),
/// ReferenceInstruction::Function(3).into()
/// );
/// ```
/// Instructions in this group can operate on operands of any value type.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#parametric-instructions>
///
/// # Examples
/// ```rust
/// use wasm_ast::{ParametricInstruction, Instruction, ValueType};
///
/// assert_eq!(
/// Instruction::Parametric(ParametricInstruction::Drop),
/// ParametricInstruction::Drop.into()
/// );
/// assert_eq!(
/// Instruction::Parametric(ParametricInstruction::Select(Some(vec![ValueType::I32]))),
/// ParametricInstruction::Select(Some(vec![ValueType::I32])).into()
/// );
/// assert_eq!(
/// Instruction::Parametric(ParametricInstruction::Select(Some(vec![]))),
/// ParametricInstruction::Select(Some(vec![])).into()
/// );
/// assert_eq!(
/// Instruction::Parametric(ParametricInstruction::Select(None)),
/// ParametricInstruction::Select(None).into()
/// );
/// ```
/// Variable instructions are concerned with access to local or global variables.
/// These instructions get or set the values of variables, respectively.
/// The π
ππΌπΊπ
.ππΎπΎ instruction is like π
ππΌπΊπ
.ππΎπ but also returns its argument.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#variable-instructions>
///
/// # Examples
/// ```rust
/// use wasm_ast::{VariableInstruction, Instruction, ValueType};
///
/// assert_eq!(
/// Instruction::Variable(VariableInstruction::LocalGet(0)),
/// VariableInstruction::LocalGet(0).into()
/// );
/// assert_eq!(
/// Instruction::Variable(VariableInstruction::LocalSet(1)),
/// VariableInstruction::LocalSet(1).into()
/// );
/// assert_eq!(
/// Instruction::Variable(VariableInstruction::LocalTee(1)),
/// VariableInstruction::LocalTee(1).into()
/// );
/// assert_eq!(
/// Instruction::Variable(VariableInstruction::GlobalGet(0)),
/// VariableInstruction::GlobalGet(0).into()
/// );
/// assert_eq!(
/// Instruction::Variable(VariableInstruction::GlobalSet(1)),
/// VariableInstruction::GlobalSet(1).into()
/// );
/// ```
/// Instructions in this group are concerned with tables table.
/// An additional instruction that accesses a table is the control instruction πΌπΊπ
π
_πππ½πππΎπΌπ.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#table-instructions>
///
/// # Examples
/// ```rust
/// use wasm_ast::{TableInstruction, Instruction};
///
/// assert_eq!(
/// Instruction::Table(TableInstruction::Get(1)),
/// TableInstruction::Get(1).into()
/// );
/// assert_eq!(
/// Instruction::Table(TableInstruction::Set(1)),
/// TableInstruction::Set(1).into()
/// );
/// assert_eq!(
/// Instruction::Table(TableInstruction::Size(1)),
/// TableInstruction::Size(1).into()
/// );
/// assert_eq!(
/// Instruction::Table(TableInstruction::Grow(1)),
/// TableInstruction::Grow(1).into()
/// );
/// assert_eq!(
/// Instruction::Table(TableInstruction::Fill(1)),
/// TableInstruction::Fill(1).into()
/// );
/// assert_eq!(
/// Instruction::Table(TableInstruction::Copy(0, 1)),
/// TableInstruction::Copy(0, 1).into()
/// );
/// assert_eq!(
/// Instruction::Table(TableInstruction::Init(0, 0)),
/// TableInstruction::Init(0, 0).into()
/// );
/// assert_eq!(
/// Instruction::Table(TableInstruction::ElementDrop(0)),
/// TableInstruction::ElementDrop(0).into()
/// );
/// ```
/// Instructions in this group are concerned with linear memory.
/// Memory is accessed with π
ππΊπ½ and πππππΎ instructions for the different value types.
/// They all take a memory immediate memarg that contains an address offset and
/// the expected alignment (expressed as the exponent of a power of 2).
/// Integer loads and stores can optionally specify a storage size that is smaller than
/// the bit width of the respective value type.
/// In the case of loads, a sign extension mode sx is then required to select appropriate behavior.
///
/// The static address offset is added to the dynamic address operand,
/// yielding a 33 bit effective address that is the zero-based index at which the memory is accessed.
/// All values are read and written in little endian byte order.
/// A trap results if any of the accessed memory bytes lies outside the address range implied by
/// the memoryβs current size.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#memory-instructions>
///
/// # Examples
/// ```rust
/// use wasm_ast::{MemoryInstruction, Instruction, NumberType, MemoryArgument, IntegerType, SignExtension};
///
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Load(NumberType::I32, MemoryArgument::default_offset(4))),
/// MemoryInstruction::Load(NumberType::I32, MemoryArgument::default_offset(4)).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Load8(IntegerType::I32, SignExtension::Signed, MemoryArgument::default_offset(1))),
/// MemoryInstruction::Load8(IntegerType::I32, SignExtension::Signed, MemoryArgument::default_offset(1)).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Load16(IntegerType::I64, SignExtension::Unsigned, MemoryArgument::default_offset(2))),
/// MemoryInstruction::Load16(IntegerType::I64, SignExtension::Unsigned, MemoryArgument::default_offset(2)).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Load32(SignExtension::Signed, MemoryArgument::default_offset(4))),
/// MemoryInstruction::Load32(SignExtension::Signed, MemoryArgument::default_offset(4)).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Store(NumberType::F64, MemoryArgument::default_offset(8))),
/// MemoryInstruction::Store(NumberType::F64, MemoryArgument::new(8, 0)).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Store8(IntegerType::I32, MemoryArgument::default_offset(1))),
/// MemoryInstruction::Store8(IntegerType::I32, MemoryArgument::default_offset(1)).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Store16(IntegerType::I64, MemoryArgument::default_offset(2))),
/// MemoryInstruction::Store16(IntegerType::I64, MemoryArgument::default_offset(2)).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Store32(MemoryArgument::default_offset(4))),
/// MemoryInstruction::Store32(MemoryArgument::default_offset(4)).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Size),
/// MemoryInstruction::Size.into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Grow),
/// MemoryInstruction::Grow.into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Fill),
/// MemoryInstruction::Fill.into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Copy),
/// MemoryInstruction::Copy.into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::Init(1)),
/// MemoryInstruction::Init(1).into()
/// );
/// assert_eq!(
/// Instruction::Memory(MemoryInstruction::DataDrop(0)),
/// MemoryInstruction::DataDrop(0).into()
/// );
/// ```
/// Instructions in this group affect the flow of control.
/// The π»π
ππΌπ, π
πππ and ππΏ instructions are structured instructions.
/// They bracket nested sequences of instructions, called blocks, terminated with, or separated by,
/// πΎππ½ or πΎπ
ππΎ pseudo-instructions. As the grammar prescribes, they must be well-nested.
///
/// A structured instruction can consume input and produce output on the operand stack according to
/// its annotated block type. It is given either as a type index that refers to a suitable function
/// type, or as an optional value type inline,
/// which is a shorthand for the function type []β[valtype?].
///
/// Each structured control instruction introduces an implicit label.
/// Labels are targets for branch instructions that reference them with label indices.
/// Unlike with other index spaces, indexing of labels is relative by nesting depth, that is,
/// label 0 refers to the innermost structured control instruction enclosing the referring branch
/// instruction, while increasing indices refer to those farther out.
/// Consequently, labels can only be referenced from within the associated structured control
/// instruction. This also implies that branches can only be directed outwards,
/// βbreakingβ from the block of the control construct they target.
/// The exact effect depends on that control construct.
/// In case of π»π
ππΌπ or ππΏ it is a forward jump, resuming execution after the matching πΎππ½.
/// In case of π
πππ it is a backward jump to the beginning of the loop.
///
/// Taking a branch unwinds the operand stack up to the height where the targeted structured
/// control instruction was entered. However, branches may additionally consume operands themselves,
/// which they push back on the operand stack after unwinding.
/// Forward branches require operands according to the output of the targeted blockβs type, i.e.,
/// represent the values produced by the terminated block.
/// Backward branches require operands according to the input of the targeted blockβs type, i.e.,
/// represent the values consumed by the restarted block.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#control-instructions>
///
/// # Examples
/// ## Simple
/// ```rust
/// use wasm_ast::{ControlInstruction, Instruction};
///
/// assert_eq!(Instruction::Control(ControlInstruction::Nop), ControlInstruction::Nop.into());
/// assert_eq!(Instruction::Control(ControlInstruction::Unreachable), ControlInstruction::Unreachable.into());
/// assert_eq!(Instruction::Control(ControlInstruction::Branch(0)), ControlInstruction::Branch(0).into());
/// assert_eq!(Instruction::Control(ControlInstruction::BranchIf(1)), ControlInstruction::BranchIf(1).into());
/// assert_eq!(Instruction::Control(ControlInstruction::BranchTable(vec![0], 1)), ControlInstruction::BranchTable(vec![0], 1).into());
/// assert_eq!(Instruction::Control(ControlInstruction::Return), ControlInstruction::Return.into());
/// assert_eq!(Instruction::Control(ControlInstruction::Call(1)), ControlInstruction::Call(1).into());
/// assert_eq!(Instruction::Control(ControlInstruction::CallIndirect(0, 1)), ControlInstruction::CallIndirect(0, 1).into());
/// ```
///
/// ## Block
/// ```rust
/// use wasm_ast::{ControlInstruction, Instruction, Expression, BlockType, ValueType};
///
/// let expression = Expression::new(vec![ControlInstruction::Nop.into(), 0i32.into()]);
///
/// assert_eq!(
/// Instruction::Control(ControlInstruction::Block(BlockType::ValueType(ValueType::I32), expression.clone())),
/// ControlInstruction::Block(BlockType::ValueType(ValueType::I32), expression.clone()).into()
/// );
/// ```
///
/// ## Loop
/// ```rust
/// use wasm_ast::{ControlInstruction, Instruction, BlockType, Expression};
/// let expression = Expression::new(vec![ControlInstruction::Nop.into(), 0i32.into()]);
///
/// assert_eq!(
/// Instruction::Control(ControlInstruction::Loop(BlockType::Index(0), expression.clone())),
/// ControlInstruction::Loop(BlockType::Index(0), expression.clone()).into()
/// );
/// ```
///
/// ## If
/// ```rust
/// use wasm_ast::{ControlInstruction, Instruction, Expression, BlockType};
/// let expression = Expression::new(vec![ControlInstruction::Nop.into()]);
///
/// assert_eq!(
/// Instruction::Control(ControlInstruction::If(BlockType::None, expression.clone(), None)),
/// ControlInstruction::If(BlockType::None, expression.clone(), None).into()
/// );
///
/// assert_eq!(
/// Instruction::Control(ControlInstruction::If(BlockType::None, expression.clone(), Some(expression.clone()))),
/// ControlInstruction::If(BlockType::None, expression.clone(), Some(expression.clone())).into()
/// );
/// ```
/// A structured instruction can consume input and produce output on the operand stack according to
/// its annotated block type.
/// It is given either as a type index that refers to a suitable function type,
/// or as an optional value type inline, which is a shorthand for the function type []β[valtype?].
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#control-instructions>
/// Argument to load and store instructions that contains an address offset and
/// the expected alignment (expressed as the exponent of a power of 2).
///
/// The static address offset is added to the dynamic address operand,
/// yielding a 33 bit effective address that is the zero-based index at which the memory is accessed.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#memory-instructions>
///
/// # Examples
/// ## With Offset & Alignment
/// ```rust
/// use wasm_ast::MemoryArgument;
///
/// let argument = MemoryArgument::new(4, 42);
///
/// assert_eq!(argument.offset(), 42);
/// assert_eq!(argument.align(), 4);
/// ```
///
/// ## With Offset Only
/// ```rust
/// use wasm_ast::MemoryArgument;
///
/// let argument = MemoryArgument::new(1, 42);
///
/// assert_eq!(argument.offset(), 42);
/// assert_eq!(argument.align(), 1);
/// ```
///
/// ## With Alignment Only
/// ```rust
/// use wasm_ast::MemoryArgument;
///
/// let argument = MemoryArgument::default_offset(4);
///
/// assert_eq!(argument.offset(), 0);
/// assert_eq!(argument.align(), 4);
/// ```
///
/// ## Default
/// ```rust
/// use wasm_ast::MemoryArgument;
///
/// let argument = MemoryArgument::default_offset(1);
///
/// assert_eq!(argument.offset(), 0);
/// assert_eq!(argument.align(), 1);
/// ```
/// Some integer instructions come in two flavors, where a signedness annotation sx distinguishes
/// whether the operands are to be interpreted as unsigned or signed integers.
/// For the other integer instructions, the use of twoβs complement for the signed interpretation
/// means that they behave the same regardless of signedness.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#numeric-instructions>
/// Function bodies, initialization values for globals,
/// and offsets of element or data segments are given as expressions, which are sequences of instructions terminated by an πΎππ½ marker.
/// In some places, validation restricts expressions to be constant,
/// which limits the set of allowable instructions.
///
/// See <https://webassembly.github.io/spec/core/syntax/instructions.html#expressions>
///
/// # Examples
/// ## Non-Empty
/// ```rust
/// use wasm_ast::{Expression, ControlInstruction, NumericInstruction, Instruction};
///
/// let expression = Expression::new(vec![0i32.into(), ControlInstruction::Nop.into()]);
///
/// assert_eq!(
/// expression,
/// Expression::new(vec![
/// Instruction::Numeric(NumericInstruction::I32Constant(0 as i32)),
/// Instruction::Control(ControlInstruction::Nop),
/// ])
/// );
/// assert_eq!(expression.instructions(), &[
/// Instruction::Numeric(NumericInstruction::I32Constant(0)),
/// Instruction::Control(ControlInstruction::Nop),
/// ]);
/// assert_eq!(expression.len(), 2);
/// assert!(!expression.is_empty());
/// assert_eq!(
/// expression,
/// vec![
/// Instruction::Numeric(NumericInstruction::I32Constant(0)),
/// Instruction::Control(ControlInstruction::Nop),
/// ].into()
/// );
/// ```
///
/// ## Empty
/// ```rust
/// use wasm_ast::Expression;
///
/// let expression = Expression::new(vec![]);
///
/// assert_eq!(expression, Expression::empty());
/// assert_eq!(expression, vec![].into());
/// assert_eq!(expression.instructions(), &[]);
/// assert_eq!(expression.len(), 0);
/// assert!(expression.is_empty());
/// ```