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

Method new

winch/codegen/src/frame/mod.rs:47–75  ·  view source on GitHub ↗

Compute the local slots for a Wasm function.

(
        types: &impl TypeConvert,
        reader: &mut BinaryReader<'_>,
        validator: &mut FuncValidator<ValidatorResources>,
    )

Source from the content-addressed store, hash-verified

45impl DefinedLocals {
46 /// Compute the local slots for a Wasm function.
47 pub fn new<A: ABI>(
48 types: &impl TypeConvert,
49 reader: &mut BinaryReader<'_>,
50 validator: &mut FuncValidator<ValidatorResources>,
51 ) -> Result<Self> {
52 let mut next_stack: u32 = 0;
53 // The first 32 bits of a Wasm binary function describe the number of locals.
54 let local_count = reader.read_var_u32()?;
55 let mut slots: WasmLocals = Default::default();
56
57 for _ in 0..local_count {
58 let position = reader.original_position();
59 let count = reader.read_var_u32()?;
60 let ty = reader.read()?;
61 validator.define_locals(position, count, ty)?;
62
63 let ty = types.convert_valtype(ty)?;
64 for _ in 0..count {
65 let ty_size = <A as ABI>::sizeof(&ty);
66 next_stack = align_to(next_stack, ty_size as u32) + (ty_size as u32);
67 slots.push(LocalSlot::new(ty, next_stack));
68 }
69 }
70
71 Ok(Self {
72 defined_locals: slots,
73 stack_size: next_stack,
74 })
75 }
76}
77
78/// Frame handler abstraction.

Callers

nothing calls this directly

Calls 12

OkFunction · 0.85
DefinedLocalsRangeClass · 0.85
convert_valtypeMethod · 0.80
has_retptrMethod · 0.80
align_toFunction · 0.50
newFunction · 0.50
readMethod · 0.45
pushMethod · 0.45
extendMethod · 0.45
mapMethod · 0.45
iterMethod · 0.45

Tested by

no test coverage detected