From 9d2d8aa69b9127eb96c22a65f3b1e825e34ad9ae Mon Sep 17 00:00:00 2001 From: Rerumu Date: Mon, 7 Feb 2022 21:32:32 -0500 Subject: [PATCH] Refactor local flattening --- wasm/src/ast/builder.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/wasm/src/ast/builder.rs b/wasm/src/ast/builder.rs index 5819824..5f14897 100644 --- a/wasm/src/ast/builder.rs +++ b/wasm/src/ast/builder.rs @@ -1,5 +1,6 @@ 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::{ @@ -120,10 +121,15 @@ fn is_dead_precursor(inst: &Instruction) -> bool { ) } +fn flat_local_list(local: Local) -> impl Iterator { + std::iter::repeat(local.value_type()).take(local.count().try_into().unwrap()) +} + fn load_local_list(func: &FuncBody) -> Vec { func.locals() .iter() - .flat_map(|l| std::iter::repeat(l.value_type()).take(l.count().try_into().unwrap())) + .copied() + .flat_map(flat_local_list) .collect() }