@@ -1465,7 +1465,7 @@ impl Module {
1465
1465
}
1466
1466
1467
1467
fn arbitrary_valtype ( & self , u : & mut Unstructured ) -> Result < ValType > {
1468
- #[ derive( Arbitrary ) ]
1468
+ #[ derive( PartialEq , Eq , PartialOrd , Ord ) ]
1469
1469
enum ValTypeClass {
1470
1470
I32 ,
1471
1471
I64 ,
@@ -1475,25 +1475,28 @@ impl Module {
1475
1475
Ref ,
1476
1476
}
1477
1477
1478
- match u. arbitrary :: < ValTypeClass > ( ) ? {
1478
+ let mut val_classes: Vec < _ > = self
1479
+ . valtypes
1480
+ . iter ( )
1481
+ . map ( |vt| match vt {
1482
+ ValType :: I32 => ValTypeClass :: I32 ,
1483
+ ValType :: I64 => ValTypeClass :: I64 ,
1484
+ ValType :: F32 => ValTypeClass :: F32 ,
1485
+ ValType :: F64 => ValTypeClass :: F64 ,
1486
+ ValType :: V128 => ValTypeClass :: V128 ,
1487
+ ValType :: Ref ( _) => ValTypeClass :: Ref ,
1488
+ } )
1489
+ . collect ( ) ;
1490
+ val_classes. sort_unstable ( ) ;
1491
+ val_classes. dedup ( ) ;
1492
+
1493
+ match u. choose ( & val_classes) ? {
1479
1494
ValTypeClass :: I32 => Ok ( ValType :: I32 ) ,
1480
1495
ValTypeClass :: I64 => Ok ( ValType :: I64 ) ,
1481
1496
ValTypeClass :: F32 => Ok ( ValType :: F32 ) ,
1482
1497
ValTypeClass :: F64 => Ok ( ValType :: F64 ) ,
1483
- ValTypeClass :: V128 => {
1484
- if self . config . simd_enabled {
1485
- Ok ( ValType :: V128 )
1486
- } else {
1487
- Ok ( ValType :: I32 )
1488
- }
1489
- }
1490
- ValTypeClass :: Ref => {
1491
- if self . config . reference_types_enabled {
1492
- Ok ( ValType :: Ref ( self . arbitrary_ref_type ( u) ?) )
1493
- } else {
1494
- Ok ( ValType :: I32 )
1495
- }
1496
- }
1498
+ ValTypeClass :: V128 => Ok ( ValType :: V128 ) ,
1499
+ ValTypeClass :: Ref => Ok ( ValType :: Ref ( self . arbitrary_ref_type ( u) ?) ) ,
1497
1500
}
1498
1501
}
1499
1502
@@ -2482,12 +2485,14 @@ pub(crate) fn configured_valtypes(config: &Config) -> Vec<ValType> {
2482
2485
let mut valtypes = Vec :: with_capacity ( 25 ) ;
2483
2486
valtypes. push ( ValType :: I32 ) ;
2484
2487
valtypes. push ( ValType :: I64 ) ;
2485
- valtypes. push ( ValType :: F32 ) ;
2486
- valtypes. push ( ValType :: F64 ) ;
2488
+ if config. allow_floats {
2489
+ valtypes. push ( ValType :: F32 ) ;
2490
+ valtypes. push ( ValType :: F64 ) ;
2491
+ }
2487
2492
if config. simd_enabled {
2488
2493
valtypes. push ( ValType :: V128 ) ;
2489
2494
}
2490
- if config. gc_enabled {
2495
+ if config. gc_enabled && config . reference_types_enabled {
2491
2496
for nullable in [
2492
2497
// TODO: For now, only create allow nullable reference
2493
2498
// types. Eventually we should support non-nullable reference types,
@@ -2808,6 +2813,24 @@ impl InstructionKinds {
2808
2813
pub fn contains ( & self , kind : InstructionKind ) -> bool {
2809
2814
self . 0 . contains ( kind)
2810
2815
}
2816
+
2817
+ /// Restrict each [InstructionKind] to its subset not involving floats
2818
+ pub fn without_floats ( & self ) -> Self {
2819
+ let mut floatless = self . 0 ;
2820
+ if floatless. contains ( InstructionKind :: Numeric ) {
2821
+ floatless -= InstructionKind :: Numeric ;
2822
+ floatless |= InstructionKind :: NumericInt ;
2823
+ }
2824
+ if floatless. contains ( InstructionKind :: Vector ) {
2825
+ floatless -= InstructionKind :: Vector ;
2826
+ floatless |= InstructionKind :: VectorInt ;
2827
+ }
2828
+ if floatless. contains ( InstructionKind :: Memory ) {
2829
+ floatless -= InstructionKind :: Memory ;
2830
+ floatless |= InstructionKind :: MemoryInt ;
2831
+ }
2832
+ Self ( floatless)
2833
+ }
2811
2834
}
2812
2835
2813
2836
flags ! {
@@ -2816,15 +2839,18 @@ flags! {
2816
2839
#[ allow( missing_docs) ]
2817
2840
#[ cfg_attr( feature = "_internal_cli" , derive( serde_derive:: Deserialize ) ) ]
2818
2841
pub enum InstructionKind : u16 {
2819
- Numeric ,
2820
- Vector ,
2821
- Reference ,
2822
- Parametric ,
2823
- Variable ,
2824
- Table ,
2825
- Memory ,
2826
- Control ,
2827
- Aggregate ,
2842
+ NumericInt = 1 << 0 ,
2843
+ Numeric = ( 1 << 1 ) | ( 1 << 0 ) ,
2844
+ VectorInt = 1 << 2 ,
2845
+ Vector = ( 1 << 3 ) | ( 1 << 2 ) ,
2846
+ Reference = 1 << 4 ,
2847
+ Parametric = 1 << 5 ,
2848
+ Variable = 1 << 6 ,
2849
+ Table = 1 << 7 ,
2850
+ MemoryInt = 1 << 8 ,
2851
+ Memory = ( 1 << 9 ) | ( 1 << 8 ) ,
2852
+ Control = 1 << 10 ,
2853
+ Aggregate = 1 << 11 ,
2828
2854
}
2829
2855
}
2830
2856
@@ -2844,12 +2870,15 @@ impl FromStr for InstructionKind {
2844
2870
type Err = String ;
2845
2871
fn from_str ( s : & str ) -> std:: result:: Result < Self , Self :: Err > {
2846
2872
match s. to_lowercase ( ) . as_str ( ) {
2873
+ "numeric_non_float" => Ok ( InstructionKind :: NumericInt ) ,
2847
2874
"numeric" => Ok ( InstructionKind :: Numeric ) ,
2875
+ "vector_non_float" => Ok ( InstructionKind :: VectorInt ) ,
2848
2876
"vector" => Ok ( InstructionKind :: Vector ) ,
2849
2877
"reference" => Ok ( InstructionKind :: Reference ) ,
2850
2878
"parametric" => Ok ( InstructionKind :: Parametric ) ,
2851
2879
"variable" => Ok ( InstructionKind :: Variable ) ,
2852
2880
"table" => Ok ( InstructionKind :: Table ) ,
2881
+ "memory_non_float" => Ok ( InstructionKind :: MemoryInt ) ,
2853
2882
"memory" => Ok ( InstructionKind :: Memory ) ,
2854
2883
"control" => Ok ( InstructionKind :: Control ) ,
2855
2884
_ => Err ( format ! ( "unknown instruction kind: {}" , s) ) ,
0 commit comments