summaryrefslogtreecommitdiff
path: root/crates/parser/src/conversion.rs
diff options
context:
space:
mode:
authorHenry <mail@henrygressmann.de>2026-07-14 20:48:18 +0200
committerHenry <mail@henrygressmann.de>2026-07-14 20:48:18 +0200
commitdc366165b8cd0f8c43cfe7017cb37f0a16887d6d (patch)
treea0e9eeba6211fe9fddde96547a6338aca79d7c3f /crates/parser/src/conversion.rs
parentfe43e4816efbf622e8cdc106a552dfb9aadfb80e (diff)
chore: simplify runtime, parser, types, and SIMD internals
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/parser/src/conversion.rs')
-rw-r--r--crates/parser/src/conversion.rs45
1 files changed, 21 insertions, 24 deletions
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<tinywasm
pub(crate) fn convert_module_import(import: wasmparser::Import<'_>) -> Result<Import> {
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<TableType> {
- 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<u32>)> {
+ 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<Box<[Global]>> {
@@ -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())),
}
}