From 81dc6e7062ed86945a6253c6edaffe62ddabc631 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Wed, 1 May 2024 17:35:52 +0200 Subject: feat: switch back to upstream wasmparser Signed-off-by: Henry Gressmann --- crates/parser/src/lib.rs | 8 +++++--- crates/parser/src/visit.rs | 22 ++++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) (limited to 'crates/parser/src') diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 5fb3c48..dd10f4d 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -35,7 +35,7 @@ use alloc::{string::ToString, vec::Vec}; pub use error::*; use module::ModuleReader; use tinywasm_types::WasmFunction; -use wasmparser::{Validator, WasmFeatures}; +use wasmparser::{Validator, WasmFeaturesInflated}; pub use tinywasm_types::TinyWasmModule; @@ -50,7 +50,7 @@ impl Parser { } fn create_validator(&self) -> Validator { - let features = WasmFeatures { + let features = WasmFeaturesInflated { bulk_memory: true, floats: true, multi_value: true, @@ -73,8 +73,10 @@ impl Parser { tail_call: false, threads: false, multi_memory: false, // should be working mostly + custom_page_sizes: false, + shared_everything_threads: false, }; - Validator::new_with_features(features) + Validator::new_with_features(features.into()) } /// Parse a [`TinyWasmModule`] from bytes diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs index c5743b8..80dc789 100644 --- a/crates/parser/src/visit.rs +++ b/crates/parser/src/visit.rs @@ -117,12 +117,26 @@ impl FunctionBuilder { } } +macro_rules! impl_visit_operator { + ($(@$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident)*) => { + $(impl_visit_operator!(@@$proposal $op $({ $($arg: $argty),* })? => $visit);)* + }; + + (@@mvp $($rest:tt)* ) => {}; + (@@reference_types $($rest:tt)* ) => {}; + (@@sign_extension $($rest:tt)* ) => {}; + (@@saturating_float_to_int $($rest:tt)* ) => {}; + (@@bulk_memory $($rest:tt)* ) => {}; + (@@$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident) => { + fn $visit(&mut self $($(,$arg: $argty)*)?) -> Result<()>{ + self.unsupported(stringify!($visit)) + } + }; +} + impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder { type Output = Result<()>; - - fn visit_default(&mut self, op: &str) -> Self::Output { - self.unsupported(op) - } + wasmparser::for_each_operator!(impl_visit_operator); define_primitive_operands! { visit_br, Instruction::Br, u32, -- cgit v1.3.1