From d1c1e5c6adb85effbd29a82ebde76681468e2504 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sun, 3 Dec 2023 22:54:28 +0100 Subject: feat: new tinywasm api Signed-off-by: Henry Gressmann --- crates/parser/src/lib.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'crates/parser/src/lib.rs') diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 5b17fb8..6c49af0 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -18,7 +18,11 @@ use wasmparser::Validator; pub struct Parser {} impl Parser { - pub fn parse_module_bytes(wasm: &[u8]) -> Result { + pub fn new() -> Self { + Self {} + } + + pub fn parse_module_bytes(&self, wasm: &[u8]) -> Result { let mut validator = Validator::new(); let mut reader = ModuleReader::new(); @@ -34,18 +38,21 @@ impl Parser { } #[cfg(feature = "std")] - pub fn parse_module_file(path: impl AsRef) -> Result { + pub fn parse_module_file( + &self, + path: impl AsRef, + ) -> Result { use alloc::format; let f = crate::std::fs::File::open("log.txt").map_err(|e| { ParseError::Other(format!("Error opening file {:?}: {}", path.as_ref(), e)) })?; let mut reader = crate::std::io::BufReader::new(f); - Self::parse_module_stream(&mut reader) + self.parse_module_stream(&mut reader) } #[cfg(feature = "std")] - pub fn parse_module_stream(mut stream: impl std::io::Read) -> Result { + pub fn parse_module_stream(&self, mut stream: impl std::io::Read) -> Result { use alloc::format; let mut validator = Validator::new(); -- cgit v1.3.1