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

Function convert_module_element

crates/parser/src/conversion.rs:11–42  ·  view source on GitHub ↗
(element: wasmparser::Element<'_>)

Source from the content-addressed store, hash-verified

9};
10
11pub(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
44pub(crate) fn convert_module_data(data: wasmparser::Data<'_>) -> Result<tinywasm_types::Data> {
45 Ok(tinywasm_types::Data {

Callers 1

process_payloadMethod · 0.85

Calls 3

process_const_operatorsFunction · 0.85
convert_reftypeFunction · 0.85
mapMethod · 0.80

Tested by

no test coverage detected