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

Function parse_into

crates/wizer/src/component/parse.rs:29–199  ·  view source on GitHub ↗
(
    mut cx: Option<&mut ComponentContext<'a>>,
    full_wasm: &'a [u8],
    mut iter: impl Iterator<Item = wasmparser::Result<Payload<'a>>>,
)

Source from the content-addressed store, hash-verified

27}
28
29fn parse_into<'a>(
30 mut cx: Option<&mut ComponentContext<'a>>,
31 full_wasm: &'a [u8],
32 mut iter: impl Iterator<Item = wasmparser::Result<Payload<'a>>>,
33) -> wasmtime::Result<()> {
34 let mut stack = Vec::new();
35 while let Some(payload) = iter.next() {
36 let payload = payload?;
37
38 match &payload {
39 // Module sections get parsed with wizer's core wasm support.
40 Payload::ModuleSection { .. } => match &mut cx {
41 Some(component) => {
42 let info = crate::parse::parse_with(&full_wasm, &mut iter)?;
43 component.push_module_section(info);
44 }
45 None => {
46 bail!("nested components with modules not currently supported");
47 }
48 },
49
50 // All other sections get pushed raw as-is into the component.
51 _ => {
52 if let Some((id, range)) = payload.as_section()
53 && let Some(component) = &mut cx
54 {
55 component.push_raw_section(wasm_encoder::RawSection {
56 id,
57 data: &full_wasm[range],
58 });
59 }
60 }
61 }
62
63 // Further validation/handling of each section, mostly about maintaining
64 // index spaces so we know what indices are used when the instrumented
65 // component is produced.
66 match payload {
67 Payload::Version {
68 encoding: Encoding::Module,
69 ..
70 } => {
71 bail!("expected a component, found a core module");
72 }
73
74 Payload::ComponentSection { .. } => {
75 stack.push(cx.take());
76 }
77
78 Payload::End(_) => {
79 if stack.len() > 0 {
80 cx = stack.pop().unwrap();
81 }
82 }
83
84 Payload::InstanceSection(reader) => {
85 if let Some(component) = &mut cx {
86 for instance in reader {

Callers 1

parseFunction · 0.85

Calls 15

parse_withFunction · 0.85
validate_item_kindFunction · 0.85
OkFunction · 0.85
push_module_sectionMethod · 0.80
push_raw_sectionMethod · 0.80
inc_core_instancesMethod · 0.80
inc_instancesMethod · 0.80
inc_coreMethod · 0.80
inc_typesMethod · 0.80
inc_funcsMethod · 0.80
inc_core_funcsMethod · 0.80
newFunction · 0.50

Tested by

no test coverage detected