From 4c1f44a79d0e04fb33042c2eabc27040d260dfa5 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Fri, 11 Oct 2024 22:44:29 +0200 Subject: feat: add simd support to the parser --- crates/parser/src/module.rs | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) (limited to 'crates/parser/src/module.rs') diff --git a/crates/parser/src/module.rs b/crates/parser/src/module.rs index ff7d109..9b31f9e 100644 --- a/crates/parser/src/module.rs +++ b/crates/parser/src/module.rs @@ -3,12 +3,12 @@ use crate::{conversion, ParseError, Result}; use alloc::string::ToString; use alloc::{boxed::Box, format, vec::Vec}; use tinywasm_types::{ - Data, Element, Export, FuncType, Global, Import, Instruction, MemoryType, TableType, TinyWasmModule, ValType, - ValueCounts, ValueCountsSmall, WasmFunction, + Data, Element, Export, FuncType, Global, Import, Instruction, MemoryType, TableType, TinyWasmModule, ValueCounts, + ValueCountsSmall, WasmFunction, WasmFunctionData, }; use wasmparser::{FuncValidatorAllocations, Payload, Validator}; -pub(crate) type Code = (Box<[Instruction]>, ValueCounts); +pub(crate) type Code = (Box<[Instruction]>, WasmFunctionData, ValueCounts); #[derive(Default)] pub(crate) struct ModuleReader { @@ -179,7 +179,6 @@ impl ModuleReader { Ok(()) } - #[inline] pub(crate) fn into_module(self) -> Result { if !self.end_reached { return Err(ParseError::EndNotReached); @@ -193,18 +192,10 @@ impl ModuleReader { .code .into_iter() .zip(self.code_type_addrs) - .map(|((instructions, locals), ty_idx)| { - let mut params = ValueCountsSmall::default(); + .map(|((instructions, data, locals), ty_idx)| { let ty = self.func_types.get(ty_idx as usize).expect("No func type for func, this is a bug").clone(); - for param in &ty.params { - match param { - ValType::I32 | ValType::F32 => params.c32 += 1, - ValType::I64 | ValType::F64 => params.c64 += 1, - ValType::V128 => params.c128 += 1, - ValType::RefExtern | ValType::RefFunc => params.cref += 1, - } - } - WasmFunction { instructions, locals, params, ty } + let params = ValueCountsSmall::from(&ty.params); + WasmFunction { instructions, data, locals, params, ty } }) .collect::>() .into_boxed_slice(); -- cgit v1.3.1