(import: wasmparser::Import<'_>)
| 56 | } |
| 57 | |
| 58 | pub(crate) fn convert_module_import(import: wasmparser::Import<'_>) -> Result<Import> { |
| 59 | let kind = match import.ty { |
| 60 | wasmparser::TypeRef::Func(ty) => ImportKind::Function(ty), |
| 61 | wasmparser::TypeRef::Table(ty) => ImportKind::Table(TableType { |
| 62 | element_type: convert_reftype(ty.element_type)?, |
| 63 | size_initial: ty.initial.try_into().map_err(|_| { |
| 64 | crate::ParseError::UnsupportedOperator(format!("Table size initial is too large: {}", ty.initial)) |
| 65 | })?, |
| 66 | size_max: match ty.maximum { |
| 67 | Some(max) => Some(max.try_into().map_err(|_| { |
| 68 | crate::ParseError::UnsupportedOperator(format!("Table size max is too large: {max}")) |
| 69 | })?), |
| 70 | None => None, |
| 71 | }, |
| 72 | }), |
| 73 | wasmparser::TypeRef::Memory(ty) => ImportKind::Memory(convert_module_memory(ty)), |
| 74 | wasmparser::TypeRef::Global(ty) => { |
| 75 | ImportKind::Global(GlobalType::new(convert_valtype(&ty.content_type)?, ty.mutable)) |
| 76 | } |
| 77 | wasmparser::TypeRef::Tag(ty) => { |
| 78 | return Err(crate::ParseError::UnsupportedOperator(format!("Unsupported import kind: {ty:?}"))); |
| 79 | } |
| 80 | _ => { |
| 81 | return Err(crate::ParseError::UnsupportedOperator(format!("Unsupported import kind: {:?}", import.ty))); |
| 82 | } |
| 83 | }; |
| 84 | |
| 85 | Ok(Import { module: import.module.into(), name: import.name.into(), kind }) |
| 86 | } |
| 87 | |
| 88 | pub(crate) fn convert_module_memory(memory: wasmparser::MemoryType) -> MemoryType { |
| 89 | MemoryType::new( |
no test coverage detected