@@ -36,7 +36,7 @@ mod optimize;
3636mod visit;
3737pub use error:: * ;
3838use module:: ModuleReader ;
39- use wasmparser:: { Validator , WasmFeaturesInflated } ;
39+ use wasmparser:: { Validator , WasmFeatures } ;
4040
4141pub use tinywasm_types:: TinyWasmModule ;
4242
@@ -79,56 +79,32 @@ impl Parser {
7979 }
8080
8181 fn create_validator ( _options : ParserOptions ) -> Validator {
82- let features = WasmFeaturesInflated {
83- bulk_memory : true ,
84- floats : true ,
85- multi_value : true ,
86- mutable_global : true ,
87- reference_types : true ,
88- sign_extension : true ,
89- saturating_float_to_int : true ,
90- function_references : true ,
91- tail_call : true ,
92- multi_memory : true ,
93- simd : true ,
94- memory64 : true ,
95- custom_page_sizes : true ,
96- bulk_memory_opt : true ,
97- call_indirect_overlong : true ,
98- wide_arithmetic : true ,
99- relaxed_simd : true ,
100-
101- compact_imports : false ,
102- cm_map : false ,
103- custom_descriptors : false ,
104- cm_threading : false ,
105- extended_const : false ,
106- gc_types : true ,
107- stack_switching : false ,
108- component_model : false ,
109- exceptions : false ,
110- gc : false ,
111- memory_control : false ,
112- threads : false ,
113- shared_everything_threads : false ,
114- legacy_exceptions : false ,
115- cm_async : false ,
116- cm_async_builtins : false ,
117- cm_async_stackful : false ,
118- cm_nested_names : false ,
119- cm_values : false ,
120- cm_error_context : false ,
121- cm_fixed_length_lists : false ,
122- cm_gc : false ,
123- } ;
124- Validator :: new_with_features ( features. into ( ) )
82+ let features = WasmFeatures :: CALL_INDIRECT_OVERLONG
83+ | WasmFeatures :: BULK_MEMORY_OPT
84+ | WasmFeatures :: RELAXED_SIMD
85+ | WasmFeatures :: GC_TYPES
86+ | WasmFeatures :: REFERENCE_TYPES
87+ | WasmFeatures :: MUTABLE_GLOBAL
88+ | WasmFeatures :: MULTI_VALUE
89+ | WasmFeatures :: FLOATS
90+ | WasmFeatures :: BULK_MEMORY
91+ | WasmFeatures :: SATURATING_FLOAT_TO_INT
92+ | WasmFeatures :: SIGN_EXTENSION
93+ | WasmFeatures :: FUNCTION_REFERENCES
94+ | WasmFeatures :: TAIL_CALL
95+ | WasmFeatures :: MULTI_MEMORY
96+ | WasmFeatures :: SIMD
97+ | WasmFeatures :: MEMORY64
98+ | WasmFeatures :: CUSTOM_PAGE_SIZES
99+ | WasmFeatures :: WIDE_ARITHMETIC ;
100+ Validator :: new_with_features ( features)
125101 }
126102
127103 /// Parse a [`TinyWasmModule`] from bytes
128104 pub fn parse_module_bytes ( & self , wasm : impl AsRef < [ u8 ] > ) -> Result < TinyWasmModule > {
129105 let wasm = wasm. as_ref ( ) ;
130106 let mut validator = Self :: create_validator ( self . options . clone ( ) ) ;
131- let mut reader = ModuleReader :: new ( ) ;
107+ let mut reader = ModuleReader :: default ( ) ;
132108
133109 for payload in wasmparser:: Parser :: new ( 0 ) . parse_all ( wasm) {
134110 reader. process_payload ( payload?, & mut validator) ?;
@@ -144,21 +120,16 @@ impl Parser {
144120 #[ cfg( feature = "std" ) ]
145121 /// Parse a [`TinyWasmModule`] from a file. Requires `std` feature.
146122 pub fn parse_module_file ( & self , path : impl AsRef < crate :: std:: path:: Path > + Clone ) -> Result < TinyWasmModule > {
147- use alloc:: format;
148- let f = crate :: std:: fs:: File :: open ( & path)
149- . map_err ( |e| ParseError :: Other ( format ! ( "Error opening file {:?}: {}" , path. as_ref( ) , e) ) ) ?;
150-
151- let mut reader = crate :: std:: io:: BufReader :: new ( f) ;
152- self . parse_module_stream ( & mut reader)
123+ let file = crate :: std:: fs:: File :: open ( & path)
124+ . map_err ( |e| ParseError :: Other ( alloc:: format!( "Error opening file {:?}: {}" , path. as_ref( ) , e) ) ) ?;
125+ self . parse_module_stream ( & mut crate :: std:: io:: BufReader :: new ( file) )
153126 }
154127
155128 #[ cfg( feature = "std" ) ]
156129 /// Parse a [`TinyWasmModule`] from a stream. Requires `std` feature.
157130 pub fn parse_module_stream ( & self , mut stream : impl std:: io:: Read ) -> Result < TinyWasmModule > {
158- use alloc:: format;
159-
160131 let mut validator = Self :: create_validator ( self . options . clone ( ) ) ;
161- let mut reader = ModuleReader :: new ( ) ;
132+ let mut reader = ModuleReader :: default ( ) ;
162133 let mut buffer = alloc:: vec:: Vec :: new ( ) ;
163134 let mut parser = wasmparser:: Parser :: new ( 0 ) ;
164135 let mut eof = false ;
@@ -170,7 +141,7 @@ impl Parser {
170141 buffer. extend ( ( 0 ..hint) . map ( |_| 0u8 ) ) ;
171142 let read_bytes = stream
172143 . read ( & mut buffer[ len..] )
173- . map_err ( |e| ParseError :: Other ( format ! ( "Error reading from stream: {e}" ) ) ) ?;
144+ . map_err ( |e| ParseError :: Other ( alloc :: format!( "Error reading from stream: {e}" ) ) ) ?;
174145 buffer. truncate ( len + read_bytes) ;
175146 eof = read_bytes == 0 ;
176147 }
0 commit comments