(
func: wasmparser::FunctionBody<'_>,
mut validator: FuncValidator<ValidatorResources>,
reader_allocs: OperatorsReaderAllocations,
)
| 134 | } |
| 135 | |
| 136 | pub(crate) fn convert_module_code( |
| 137 | func: wasmparser::FunctionBody<'_>, |
| 138 | mut validator: FuncValidator<ValidatorResources>, |
| 139 | reader_allocs: OperatorsReaderAllocations, |
| 140 | ) -> Result<(FunctionCode, FuncValidatorAllocations, OperatorsReaderAllocations)> { |
| 141 | let locals_reader = func.get_locals_reader()?; |
| 142 | let count = locals_reader.get_count(); |
| 143 | let pos = locals_reader.original_position(); |
| 144 | |
| 145 | // maps a local's address to the index in the type's locals array |
| 146 | let mut local_addr_map = Vec::with_capacity(count as usize); |
| 147 | let mut local_counts = ValueCounts::default(); |
| 148 | |
| 149 | for (i, local) in locals_reader.into_iter().enumerate() { |
| 150 | let local = local?; |
| 151 | validator.define_locals(pos + i, local.0, local.1)?; |
| 152 | } |
| 153 | |
| 154 | for i in 0..validator.len_locals() { |
| 155 | match validator.get_local_type(i) { |
| 156 | Some(wasmparser::ValType::I32 | wasmparser::ValType::F32) => { |
| 157 | local_addr_map.push(local_counts.c32); |
| 158 | local_counts.c32 += 1; |
| 159 | } |
| 160 | Some(wasmparser::ValType::I64 | wasmparser::ValType::F64) => { |
| 161 | local_addr_map.push(local_counts.c64); |
| 162 | local_counts.c64 += 1; |
| 163 | } |
| 164 | Some(wasmparser::ValType::V128) => { |
| 165 | local_addr_map.push(local_counts.c128); |
| 166 | local_counts.c128 += 1; |
| 167 | } |
| 168 | Some(wasmparser::ValType::Ref(_)) => { |
| 169 | local_addr_map.push(local_counts.c32); |
| 170 | local_counts.c32 += 1; |
| 171 | } |
| 172 | None => return Err(crate::ParseError::UnsupportedOperator("Unknown local type".to_string())), |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | let (body, data, validator_allocs, reader_allocs) = |
| 177 | process_operators_and_validate(validator, func, local_addr_map, reader_allocs)?; |
| 178 | Ok(( |
| 179 | FunctionCode { instructions: body, data, locals: local_counts, uses_local_memory: false }, |
| 180 | validator_allocs, |
| 181 | reader_allocs, |
| 182 | )) |
| 183 | } |
| 184 | |
| 185 | pub(crate) fn convert_module_type(ty: wasmparser::RecGroup) -> Result<Arc<FuncType>> { |
| 186 | let mut types = ty.types(); |
no test coverage detected