Compute the local slots for a Wasm function.
(
types: &impl TypeConvert,
reader: &mut BinaryReader<'_>,
validator: &mut FuncValidator<ValidatorResources>,
)
| 45 | impl 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. |
nothing calls this directly
no test coverage detected