1
1
use addr2line:: LookupResult ;
2
2
use anyhow:: { anyhow, Context , Result } ;
3
+ use bitflags:: Flags ;
3
4
use rayon:: prelude:: * ;
4
5
use std:: fmt:: Write ;
5
6
use std:: mem;
@@ -171,38 +172,9 @@ impl Opts {
171
172
fn parse_features ( arg : & str ) -> Result < WasmFeatures > {
172
173
let mut ret = WasmFeatures :: default ( ) ;
173
174
174
- const FEATURES : & [ ( & str , WasmFeatures ) ] = & [
175
- ( "reference-types" , WasmFeatures :: REFERENCE_TYPES ) ,
176
- ( "function-references" , WasmFeatures :: FUNCTION_REFERENCES ) ,
177
- ( "simd" , WasmFeatures :: SIMD ) ,
178
- ( "threads" , WasmFeatures :: THREADS ) ,
179
- (
180
- "shared-everything-threads" ,
181
- WasmFeatures :: SHARED_EVERYTHING_THREADS ,
182
- ) ,
183
- ( "bulk-memory" , WasmFeatures :: BULK_MEMORY ) ,
184
- ( "multi-value" , WasmFeatures :: MULTI_VALUE ) ,
185
- ( "tail-call" , WasmFeatures :: TAIL_CALL ) ,
186
- ( "component-model" , WasmFeatures :: COMPONENT_MODEL ) ,
187
- (
188
- "component-model-values" ,
189
- WasmFeatures :: COMPONENT_MODEL_VALUES ,
190
- ) ,
191
- ( "multi-memory" , WasmFeatures :: MULTI_MEMORY ) ,
192
- ( "exception-handling" , WasmFeatures :: EXCEPTIONS ) ,
193
- ( "memory64" , WasmFeatures :: MEMORY64 ) ,
194
- ( "extended-const" , WasmFeatures :: EXTENDED_CONST ) ,
195
- ( "floats" , WasmFeatures :: FLOATS ) ,
196
- (
197
- "saturating-float-to-int" ,
198
- WasmFeatures :: SATURATING_FLOAT_TO_INT ,
199
- ) ,
200
- ( "sign-extension" , WasmFeatures :: SIGN_EXTENSION ) ,
201
- ( "mutable-global" , WasmFeatures :: MUTABLE_GLOBAL ) ,
202
- ( "relaxed-simd" , WasmFeatures :: RELAXED_SIMD ) ,
203
- ( "gc" , WasmFeatures :: GC ) ,
204
- ( "legacy-exceptions" , WasmFeatures :: LEGACY_EXCEPTIONS ) ,
205
- ] ;
175
+ fn flag_name ( flag : & bitflags:: Flag < WasmFeatures > ) -> String {
176
+ flag. name ( ) . to_lowercase ( ) . replace ( '_' , "-" )
177
+ }
206
178
207
179
for part in arg. split ( ',' ) . map ( |s| s. trim ( ) ) . filter ( |s| !s. is_empty ( ) ) {
208
180
let ( enable, part) = if let Some ( part) = part. strip_prefix ( "-" ) {
@@ -212,28 +184,27 @@ fn parse_features(arg: &str) -> Result<WasmFeatures> {
212
184
} ;
213
185
match part {
214
186
"all" => {
215
- for ( name, feature) in FEATURES {
216
- // don't count this under "all" for now.
217
- if * name == "deterministic" {
218
- continue ;
219
- }
220
- ret. set ( * feature, enable) ;
187
+ for flag in WasmFeatures :: FLAGS . iter ( ) {
188
+ ret. set ( * flag. value ( ) , enable) ;
221
189
}
222
190
}
223
191
224
192
name => {
225
- let ( _, feature) = FEATURES . iter ( ) . find ( |( n, _) | * n == name) . ok_or_else ( || {
226
- anyhow ! (
227
- "unknown feature `{}`\n Valid features: {}" ,
228
- name,
229
- FEATURES
230
- . iter( )
231
- . map( |( name, _) | * name)
232
- . collect:: <Vec <_>>( )
233
- . join( ", " ) ,
234
- )
235
- } ) ?;
236
- ret. set ( * feature, enable) ;
193
+ let flag = WasmFeatures :: FLAGS
194
+ . iter ( )
195
+ . find ( |f| flag_name ( f) == name)
196
+ . ok_or_else ( || {
197
+ anyhow ! (
198
+ "unknown feature `{}`\n Valid features: {}" ,
199
+ name,
200
+ WasmFeatures :: FLAGS
201
+ . iter( )
202
+ . map( flag_name)
203
+ . collect:: <Vec <_>>( )
204
+ . join( ", " ) ,
205
+ )
206
+ } ) ?;
207
+ ret. set ( * flag. value ( ) , enable) ;
237
208
}
238
209
}
239
210
}
0 commit comments