diff options
Diffstat (limited to 'crates/parser/src')
| -rw-r--r-- | crates/parser/src/conversion.rs | 26 | ||||
| -rw-r--r-- | crates/parser/src/module.rs | 14 | ||||
| -rw-r--r-- | crates/parser/src/visit.rs | 15 |
3 files changed, 23 insertions, 32 deletions
diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs index 34dcdfd..cfc0e84 100644 --- a/crates/parser/src/conversion.rs +++ b/crates/parser/src/conversion.rs @@ -60,8 +60,11 @@ pub(crate) fn convert_module_import(import: wasmparser::Import<'_>) -> Result<Im wasmparser::TypeRef::Func(ty) => ImportKind::Function(ty), 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 }) + ImportKind::Table(if ty.table64 { + TableType::new64(element_type, ty.initial, ty.maximum) + } else { + TableType::new(element_type, ty.initial, ty.maximum) + }) } wasmparser::TypeRef::Memory(ty) => ImportKind::Memory(convert_module_memory(ty)), wasmparser::TypeRef::Global(ty) => { @@ -87,25 +90,6 @@ pub(crate) fn convert_module_memory(memory: wasmparser::MemoryType) -> MemoryTyp ) } -pub(crate) fn convert_module_table(table: wasmparser::Table<'_>) -> Result<TableType> { - 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]>> { diff --git a/crates/parser/src/module.rs b/crates/parser/src/module.rs index 9273d44..05811ec 100644 --- a/crates/parser/src/module.rs +++ b/crates/parser/src/module.rs @@ -128,8 +128,18 @@ impl<'a> ModuleReader<'a> { if let Some(validator) = validator.as_mut() { validator.table_section(&reader)?; } - self.table_types = - reader.into_iter().map(|table| convert_module_table(table?)).collect::<Result<_>>()?; + self.table_types = reader + .into_iter() + .map(|table| { + let table = table?; + let element_type = convert_reftype(table.ty.element_type)?; + Ok(if table.ty.table64 { + TableType::new64(element_type, table.ty.initial, table.ty.maximum) + } else { + TableType::new(element_type, table.ty.initial, table.ty.maximum) + }) + }) + .collect::<Result<_>>()?; } Payload::MemorySection(reader) => { check_section("memory", !self.memory_types.is_empty())?; diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs index 0ca9494..cb13387 100644 --- a/crates/parser/src/visit.rs +++ b/crates/parser/src/visit.rs @@ -168,14 +168,14 @@ impl ModuleMetadata { ImportKind::Function(ty) => functions.push(*ty), ImportKind::Global(ty) => global_sizes.push(OperandSize::from(&ty.ty)), ImportKind::Memory(ty) => memory_sizes.push(OperandSize::from(ty.arch())), - ImportKind::Table(_) => table_sizes.push(OperandSize::S32), + ImportKind::Table(ty) => table_sizes.push(OperandSize::from(ty.arch())), } } functions.extend_from_slice(code_type_addrs); global_sizes.extend(globals.iter().map(|global| OperandSize::from(&global.ty.ty))); memory_sizes.extend(memories.iter().map(|ty| OperandSize::from(ty.arch()))); - table_sizes.extend(tables.iter().map(|_| OperandSize::S32)); + table_sizes.extend(tables.iter().map(|ty| OperandSize::from(ty.arch()))); let signatures = types .iter() @@ -653,13 +653,10 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder<'_> { } fn visit_table_copy(&mut self, dst_table: u32, src_table: u32) -> Self::Output { - self.metadata.table_size(dst_table)?; - self.metadata.table_size(src_table)?; - self.emit( - &[OperandSize::S32, OperandSize::S32, OperandSize::S32], - &[], - Instruction::TableCopy { dst_table, src_table }, - ) + let dst = self.metadata.table_size(dst_table)?; + let src = self.metadata.table_size(src_table)?; + let len = if dst == OperandSize::S32 || src == OperandSize::S32 { OperandSize::S32 } else { OperandSize::S64 }; + self.emit(&[dst, src, len], &[], Instruction::TableCopy { dst_table, src_table }) } fn visit_memory_copy(&mut self, dst_mem: u32, src_mem: u32) -> Self::Output { |
