Refactor local flattening

This commit is contained in:
Rerumu 2022-02-07 21:32:32 -05:00
parent 66818a8566
commit 9d2d8aa69b

View File

@ -1,5 +1,6 @@
use parity_wasm::elements::{ use parity_wasm::elements::{
BlockType, External, FuncBody, FunctionType, ImportEntry, Instruction, Module, Type, ValueType, BlockType, External, FuncBody, FunctionType, ImportEntry, Instruction, Local, Module, Type,
ValueType,
}; };
use super::{ use super::{
@ -120,10 +121,15 @@ fn is_dead_precursor(inst: &Instruction) -> bool {
) )
} }
fn flat_local_list(local: Local) -> impl Iterator<Item = ValueType> {
std::iter::repeat(local.value_type()).take(local.count().try_into().unwrap())
}
fn load_local_list(func: &FuncBody) -> Vec<ValueType> { fn load_local_list(func: &FuncBody) -> Vec<ValueType> {
func.locals() func.locals()
.iter() .iter()
.flat_map(|l| std::iter::repeat(l.value_type()).take(l.count().try_into().unwrap())) .copied()
.flat_map(flat_local_list)
.collect() .collect()
} }