MCPcopy Index your code
hub / github.com/explodingcamera/tinywasm / convert_module_import

Function convert_module_import

crates/parser/src/conversion.rs:58–86  ·  view source on GitHub ↗
(import: wasmparser::Import<'_>)

Source from the content-addressed store, hash-verified

56}
57
58pub(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
88pub(crate) fn convert_module_memory(memory: wasmparser::MemoryType) -> MemoryType {
89 MemoryType::new(

Callers 1

process_payloadMethod · 0.85

Calls 7

FunctionClass · 0.85
TableClass · 0.85
convert_reftypeFunction · 0.85
MemoryClass · 0.85
convert_module_memoryFunction · 0.85
convert_valtypeFunction · 0.85
GlobalClass · 0.50

Tested by

no test coverage detected