MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_with

Function parse_with

crates/wizer/src/parse.rs:10–46  ·  view source on GitHub ↗
(
    full_wasm: &'a [u8],
    payloads: &mut impl Iterator<Item = wasmparser::Result<wasmparser::Payload<'a>>>,
)

Source from the content-addressed store, hash-verified

8}
9
10pub(crate) fn parse_with<'a>(
11 full_wasm: &'a [u8],
12 payloads: &mut impl Iterator<Item = wasmparser::Result<wasmparser::Payload<'a>>>,
13) -> wasmtime::Result<ModuleContext<'a>> {
14 log::debug!("Parsing the input Wasm");
15
16 let mut module = ModuleContext::default();
17
18 while let Some(payload) = payloads.next() {
19 use wasmparser::Payload::*;
20
21 let payload = payload.context("failed to parse Wasm")?;
22
23 if let Some((id, range)) = payload.as_section() {
24 module.add_raw_section(id, range, full_wasm);
25 }
26
27 match payload {
28 Version {
29 encoding: Encoding::Component,
30 ..
31 } => {
32 bail!("expected a core module, found a component");
33 }
34 ImportSection(imports) => import_section(&mut module, imports)?,
35 FunctionSection(funcs) => function_section(&mut module, funcs)?,
36 TableSection(tables) => table_section(&mut module, tables)?,
37 MemorySection(mems) => memory_section(&mut module, mems)?,
38 GlobalSection(globals) => global_section(&mut module, globals)?,
39 ExportSection(exports) => export_section(&mut module, exports)?,
40 End { .. } => break,
41 _ => {}
42 }
43 }
44
45 Ok(module)
46}
47
48fn import_section<'a>(
49 module: &mut ModuleContext<'a>,

Callers 2

parseFunction · 0.85
parse_intoFunction · 0.85

Calls 10

import_sectionFunction · 0.85
function_sectionFunction · 0.85
table_sectionFunction · 0.85
memory_sectionFunction · 0.85
global_sectionFunction · 0.85
export_sectionFunction · 0.85
OkFunction · 0.85
add_raw_sectionMethod · 0.80
nextMethod · 0.45
contextMethod · 0.45

Tested by

no test coverage detected