diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2024-05-01 17:35:52 +0200 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2024-05-01 17:35:52 +0200 |
| commit | 81dc6e7062ed86945a6253c6edaffe62ddabc631 (patch) | |
| tree | 190673702389585a9b90ffe1764761a42c15fd76 | |
| parent | 704a8da24bb9e85e712fbb745ff4d4e1b54b6914 (diff) | |
feat: switch back to upstream wasmparser
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
| -rw-r--r-- | Cargo.lock | 60 | ||||
| -rw-r--r-- | crates/parser/Cargo.toml | 5 | ||||
| -rw-r--r-- | crates/parser/src/lib.rs | 8 | ||||
| -rw-r--r-- | crates/parser/src/visit.rs | 22 | ||||
| -rwxr-xr-x | examples/rust/build.sh | 2 |
5 files changed, 41 insertions, 56 deletions
@@ -35,7 +35,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", - "const-random", "once_cell", "version_check", "zerocopy", @@ -409,26 +408,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed3d0b5ff30645a68f35ece8cea4556ca14ef8a1651455f789a099a0513532a6" [[package]] -name = "const-random" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" -dependencies = [ - "const-random-macro", -] - -[[package]] -name = "const-random-macro" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" -dependencies = [ - "getrandom", - "once_cell", - "tiny-keccak", -] - -[[package]] name = "core-foundation" version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2043,15 +2022,6 @@ dependencies = [ ] [[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - -[[package]] name = "tinytemplate" version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2111,7 +2081,7 @@ version = "0.6.0" dependencies = [ "log", "tinywasm-types", - "tinywasm-wasmparser", + "wasmparser 0.206.0", ] [[package]] @@ -2134,19 +2104,6 @@ dependencies = [ ] [[package]] -name = "tinywasm-wasmparser" -version = "0.202.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b02b9566a3c8b98f29dd9821d0584de1ad0290cdc9132296f66fbf4015001bb1" -dependencies = [ - "ahash 0.8.11", - "bitflags 2.5.0", - "hashbrown 0.14.5", - "indexmap 2.2.6", - "semver", -] - -[[package]] name = "tracing" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2429,7 +2386,7 @@ dependencies = [ "thiserror", "wasmer-types", "wasmer-vm", - "wasmparser", + "wasmparser 0.95.0", "winapi", ] @@ -2569,6 +2526,19 @@ dependencies = [ ] [[package]] +name = "wasmparser" +version = "0.206.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39192edb55d55b41963db40fd49b0b542156f04447b5b512744a91d38567bdbc" +dependencies = [ + "ahash 0.8.11", + "bitflags 2.5.0", + "hashbrown 0.14.5", + "indexmap 2.2.6", + "semver", +] + +[[package]] name = "wasmparser-nostd" version = "0.100.2" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml index 6057c30..7d726d4 100644 --- a/crates/parser/Cargo.toml +++ b/crates/parser/Cargo.toml @@ -8,12 +8,11 @@ authors.workspace=true repository.workspace=true [dependencies] -# fork of wasmparser with no_std support, see https://github.com/bytecodealliance/wasmtime/issues/3495 -wasmparser={version="0.202.0", package="tinywasm-wasmparser", default-features=false} +wasmparser={version="0.206", default-features=false} log={version="0.4", optional=true} tinywasm-types={version="0.6.0", path="../types", default-features=false} [features] default=["std", "logging"] logging=["log"] -std=["tinywasm-types/std"] +std=["tinywasm-types/std", "wasmparser/std"] 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, diff --git a/examples/rust/build.sh b/examples/rust/build.sh index e6d3b0d..744f9d0 100755 --- a/examples/rust/build.sh +++ b/examples/rust/build.sh @@ -6,7 +6,7 @@ exclude_wat=("tinywasm") out_dir="./target/wasm32-unknown-unknown/wasm" dest_dir="out" -features="+reference-types,+bulk-memory,+mutable-globals" +features="+reference-types,+bulk-memory,+mutable-globals,+multivalue" # ensure out dir exists mkdir -p "$dest_dir" |
