diff options
| -rw-r--r-- | Cargo.lock | 4 | ||||
| -rw-r--r-- | crates/parser/Cargo.toml | 2 | ||||
| -rw-r--r-- | crates/parser/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/parser/src/visit.rs | 96 |
4 files changed, 29 insertions, 74 deletions
@@ -2120,9 +2120,9 @@ dependencies = [ [[package]] name = "tinywasm-wasmparser" -version = "0.200.2" +version = "0.200.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fce1b3563499af272f7e88c8b0357e740e62c2bcf59f134992698d35af96da" +checksum = "365709f885b90cad71c71120414f99255e74d9d03f232618d9d1c6eb5db0ea99" dependencies = [ "ahash 0.8.9", "bitflags 2.4.2", diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 73eec99..3be0bb1 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -9,7 +9,7 @@ repository.workspace=true [dependencies] # fork of wasmparser with no_std support, see https://github.com/bytecodealliance/wasmtime/issues/3495 -wasmparser={version="0.200.2", package="tinywasm-wasmparser", default-features=false} +wasmparser={version="0.200.3", package="tinywasm-wasmparser", default-features=false} log={version="0.4", optional=true} tinywasm-types={version="0.4.0", path="../types", default-features=false} diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 5de4b03..7beb5f8 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -7,7 +7,6 @@ #![forbid(unsafe_code)] #![cfg_attr(not(feature = "std"), feature(error_in_core))] //! See [`tinywasm`](https://docs.rs/tinywasm) for documentation. -#![recursion_limit = "1028"] mod std; extern crate alloc; diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs index 88b6ba5..cc9f0e2 100644 --- a/crates/parser/src/visit.rs +++ b/crates/parser/src/visit.rs @@ -71,6 +71,14 @@ macro_rules! define_primitive_operands { } )* }; + ($($name:ident, $instr:expr, $ty:ty, $ty2:ty),*) => { + $( + fn $name(&mut self, arg: $ty, arg2: $ty) -> Self::Output { + self.instructions.push($instr(arg, arg2)); + Ok(()) + } + )* + }; } macro_rules! define_mem_operands { @@ -88,34 +96,6 @@ macro_rules! define_mem_operands { }; } -macro_rules! impl_visit_operator { - ( @mvp $($rest:tt)* ) => { - impl_visit_operator!(@@skipped $($rest)*); - }; - ( @sign_extension $($rest:tt)* ) => { - impl_visit_operator!(@@skipped $($rest)*); - }; - ( @saturating_float_to_int $($rest:tt)* ) => { - impl_visit_operator!(@@skipped $($rest)*); - }; - ( @bulk_memory $($rest:tt)* ) => { - impl_visit_operator!(@@skipped $($rest)*); - }; - ( @reference_types $($rest:tt)* ) => { - impl_visit_operator!(@@skipped $($rest)*); - }; - ( @@skipped $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident $($rest:tt)* ) => { - impl_visit_operator!($($rest)*); - }; - ( @$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident $($rest:tt)* ) => { - fn $visit(&mut self $($(, $arg: $argty)*)?) -> Self::Output { - self.unsupported(stringify!($op)) - } - impl_visit_operator!($($rest)*); - }; - () => {}; -} - pub(crate) struct FunctionBuilder { instructions: Vec<Instruction>, label_ptrs: Vec<usize>, @@ -141,6 +121,10 @@ impl FunctionBuilder { impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder { type Output = Result<()>; + fn visit_default(&mut self, op: &str) -> Self::Output { + self.unsupported(op) + } + define_primitive_operands! { visit_br, Instruction::Br, u32, visit_br_if, Instruction::BrIf, u32, @@ -329,7 +313,6 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder { match instruction { Instruction::LocalGet(a) => *instruction = Instruction::LocalGet2(*a, idx), Instruction::LocalGet2(a, b) => *instruction = Instruction::LocalGet3(*a, *b, idx), - // Instruction::LocalGet3(a, b, c) => *instruction = Instruction::LocalGet4(*a, *b, *c, idx), Instruction::LocalTee(a) => *instruction = Instruction::LocalTeeGet(*a, idx), _ => return self.visit(Instruction::LocalGet(idx)), }; @@ -502,24 +485,14 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder { // Bulk Memory Operations - fn visit_memory_init(&mut self, data_index: u32, mem: u32) -> Self::Output { - self.visit(Instruction::MemoryInit(data_index, mem)) - } - - fn visit_data_drop(&mut self, data_index: u32) -> Self::Output { - self.visit(Instruction::DataDrop(data_index)) - } - - fn visit_memory_copy(&mut self, dst_mem: u32, src_mem: u32) -> Self::Output { - self.visit(Instruction::MemoryCopy(dst_mem, src_mem)) - } - - fn visit_memory_fill(&mut self, mem: u32) -> Self::Output { - self.visit(Instruction::MemoryFill(mem)) + define_primitive_operands! { + visit_memory_init, Instruction::MemoryInit, u32, u32, + visit_memory_copy, Instruction::MemoryCopy, u32, u32, + visit_table_init, Instruction::TableInit, u32, u32 } - - fn visit_table_init(&mut self, elem_index: u32, table: u32) -> Self::Output { - self.visit(Instruction::TableInit(elem_index, table)) + define_primitive_operands! { + visit_memory_fill, Instruction::MemoryFill, u32, + visit_data_drop, Instruction::DataDrop, u32 } fn visit_elem_drop(&mut self, _elem_index: u32) -> Self::Output { @@ -540,33 +513,16 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder { self.visit(Instruction::RefIsNull) } - fn visit_ref_func(&mut self, idx: u32) -> Self::Output { - self.visit(Instruction::RefFunc(idx)) - } - fn visit_typed_select(&mut self, ty: wasmparser::ValType) -> Self::Output { self.visit(Instruction::Select(Some(convert_valtype(&ty)))) } - fn visit_table_fill(&mut self, table: u32) -> Self::Output { - self.visit(Instruction::TableFill(table)) - } - - fn visit_table_get(&mut self, table: u32) -> Self::Output { - self.visit(Instruction::TableGet(table)) - } - - fn visit_table_set(&mut self, table: u32) -> Self::Output { - self.visit(Instruction::TableSet(table)) - } - - fn visit_table_grow(&mut self, table: u32) -> Self::Output { - self.visit(Instruction::TableGrow(table)) - } - - fn visit_table_size(&mut self, table: u32) -> Self::Output { - self.visit(Instruction::TableSize(table)) + define_primitive_operands! { + visit_ref_func, Instruction::RefFunc, u32, + visit_table_fill, Instruction::TableFill, u32, + visit_table_get, Instruction::TableGet, u32, + visit_table_set, Instruction::TableSet, u32, + visit_table_grow, Instruction::TableGrow, u32, + visit_table_size, Instruction::TableSize, u32 } - - wasmparser::for_each_operator!(impl_visit_operator); } |
