(element: wasmparser::Element<'_>)
| 9 | }; |
| 10 | |
| 11 | pub(crate) fn convert_module_element(element: wasmparser::Element<'_>) -> Result<tinywasm_types::Element> { |
| 12 | let kind = match element.kind { |
| 13 | wasmparser::ElementKind::Active { table_index, offset_expr } => tinywasm_types::ElementKind::Active { |
| 14 | table: table_index.unwrap_or(0), |
| 15 | offset: process_const_operators(offset_expr.get_operators_reader())?, |
| 16 | }, |
| 17 | wasmparser::ElementKind::Passive => tinywasm_types::ElementKind::Passive, |
| 18 | wasmparser::ElementKind::Declared => tinywasm_types::ElementKind::Declared, |
| 19 | }; |
| 20 | |
| 21 | match element.items { |
| 22 | wasmparser::ElementItems::Functions(funcs) => { |
| 23 | let items = funcs |
| 24 | .into_iter() |
| 25 | .map(|func| Ok(ElementItem::Func(func?))) |
| 26 | .collect::<Result<Vec<_>>>()? |
| 27 | .into_boxed_slice(); |
| 28 | |
| 29 | Ok(tinywasm_types::Element { kind, items, ty: WasmType::RefFunc, range: element.range }) |
| 30 | } |
| 31 | |
| 32 | wasmparser::ElementItems::Expressions(ty, exprs) => { |
| 33 | let items = exprs |
| 34 | .into_iter() |
| 35 | .map(|expr| Ok(ElementItem::Expr(process_const_operators(expr?.get_operators_reader())?))) |
| 36 | .collect::<Result<Vec<_>>>()? |
| 37 | .into_boxed_slice(); |
| 38 | |
| 39 | Ok(tinywasm_types::Element { kind, items, ty: convert_reftype(ty)?, range: element.range }) |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | pub(crate) fn convert_module_data(data: wasmparser::Data<'_>) -> Result<tinywasm_types::Data> { |
| 45 | Ok(tinywasm_types::Data { |
no test coverage detected