From dc366165b8cd0f8c43cfe7017cb37f0a16887d6d Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 14 Jul 2026 20:48:18 +0200 Subject: chore: simplify runtime, parser, types, and SIMD internals Signed-off-by: Henry --- crates/parser/src/conversion.rs | 45 +++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 24 deletions(-) (limited to 'crates/parser/src/conversion.rs') diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs index 4561974..99cf1ba 100644 --- a/crates/parser/src/conversion.rs +++ b/crates/parser/src/conversion.rs @@ -58,18 +58,11 @@ pub(crate) fn convert_module_data(data: wasmparser::Data<'_>) -> Result) -> Result { let kind = match import.ty { wasmparser::TypeRef::Func(ty) => ImportKind::Function(ty), - wasmparser::TypeRef::Table(ty) => ImportKind::Table(TableType { - element_type: convert_reftype(ty.element_type)?, - size_initial: ty.initial.try_into().map_err(|_| { - crate::ParseError::UnsupportedOperator(format!("Table size initial is too large: {}", ty.initial)) - })?, - size_max: match ty.maximum { - Some(max) => Some(max.try_into().map_err(|_| { - crate::ParseError::UnsupportedOperator(format!("Table size max is too large: {max}")) - })?), - None => None, - }, - }), + wasmparser::TypeRef::Table(ty) => { + let element_type = convert_reftype(ty.element_type)?; + let (size_initial, size_max) = convert_table_limits(ty)?; + ImportKind::Table(TableType { element_type, size_initial, size_max }) + } wasmparser::TypeRef::Memory(ty) => ImportKind::Memory(convert_module_memory(ty)), wasmparser::TypeRef::Global(ty) => { ImportKind::Global(GlobalType::new(convert_valtype(&ty.content_type)?, ty.mutable)) @@ -95,16 +88,24 @@ pub(crate) fn convert_module_memory(memory: wasmparser::MemoryType) -> MemoryTyp } pub(crate) fn convert_module_table(table: wasmparser::Table<'_>) -> Result { - let size_initial = table.ty.initial.try_into().map_err(|_| { - crate::ParseError::UnsupportedOperator(format!("Table size initial is too large: {}", table.ty.initial)) - })?; - - let size_max = table.ty.maximum.map(|max| max.try_into()).transpose(); - let size_max = - size_max.map_err(|e| crate::ParseError::UnsupportedOperator(format!("Table size max is too large: {e}")))?; + let (size_initial, size_max) = convert_table_limits(table.ty)?; Ok(TableType { element_type: convert_reftype(table.ty.element_type)?, size_initial, size_max }) } +fn convert_table_limits(table: wasmparser::TableType) -> Result<(u32, Option)> { + let size_initial = table.initial.try_into().map_err(|_| { + crate::ParseError::UnsupportedOperator(format!("Table size initial is too large: {}", table.initial)) + })?; + let size_max = table + .maximum + .map(|max| { + u32::try_from(max) + .map_err(|_| crate::ParseError::UnsupportedOperator(format!("Table size max is too large: {max}"))) + }) + .transpose()?; + Ok((size_initial, size_max)) +} + pub(crate) fn convert_module_globals( globals: wasmparser::SectionLimited<'_, wasmparser::Global<'_>>, ) -> Result> { @@ -153,7 +154,7 @@ pub(crate) fn convert_module_code( for i in 0..validator.len_locals() { match validator.get_local_type(i) { - Some(wasmparser::ValType::I32 | wasmparser::ValType::F32) => { + Some(wasmparser::ValType::I32 | wasmparser::ValType::F32 | wasmparser::ValType::Ref(_)) => { local_addr_map.push(local_counts.c32); local_counts.c32 += 1; } @@ -165,10 +166,6 @@ pub(crate) fn convert_module_code( local_addr_map.push(local_counts.c128); local_counts.c128 += 1; } - Some(wasmparser::ValType::Ref(_)) => { - local_addr_map.push(local_counts.c32); - local_counts.c32 += 1; - } None => return Err(crate::ParseError::UnsupportedOperator("Unknown local type".to_string())), } } -- cgit v1.3.1