diff --git a/src/lib.rs b/src/lib.rs index 917a0dc..9915704 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,6 +8,4 @@ mod stack_limiter; pub use export_globals::export_mutable_globals; pub use parity_wasm; -pub use stack_limiter::inject as inject_stack_limiter; -pub use stack_limiter::compute_stack_cost; -pub use stack_limiter::compute_stack_costs; +pub use stack_limiter::{compute_stack_cost, compute_stack_costs, inject as inject_stack_limiter}; \ No newline at end of file diff --git a/src/stack_limiter/max_height.rs b/src/stack_limiter/max_height.rs index 5f145a4..a62c16e 100644 --- a/src/stack_limiter/max_height.rs +++ b/src/stack_limiter/max_height.rs @@ -145,8 +145,9 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result = if let Some(global_section) = module.global_section() { - global_section.entries() - .into_iter() + global_section + .entries() + .iter() .map(|g| g.global_type().content_type()) .collect() } else { @@ -155,13 +156,10 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result = func_signature .params() - .into_iter() + .iter() .cloned() - .chain( - body.locals() - .iter() - .flat_map(|l| vec![l.value_type(); l.count() as usize]) - ).collect(); + .chain(body.locals().iter().flat_map(|l| vec![l.value_type(); l.count() as usize])) + .collect(); let mut stack = Stack::new(); let mut max_weight: u32 = 0; @@ -170,12 +168,9 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result Result { // Pop values for the destination block result. - if let Some(_) = stack.frame(*target)?.branch_type { + if stack.frame(*target)?.branch_type.is_some() { stack.pop_value()?; } @@ -283,7 +278,7 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result 0 { + if !callee_results.is_empty() { stack.push_value(callee_results[0])?; } }, @@ -301,7 +296,7 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result 0 { + if !callee_results.is_empty() { stack.push_value(callee_results[0])?; } }, @@ -402,10 +397,18 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result { stack.push_value(ValueType::I32)?; }, - I64Const(_) => { stack.push_value(ValueType::I64)?; }, - F32Const(_) => { stack.push_value(ValueType::F32)?; }, - F64Const(_) => { stack.push_value(ValueType::F64)?; }, + I32Const(_) => { + stack.push_value(ValueType::I32)?; + }, + I64Const(_) => { + stack.push_value(ValueType::I64)?; + }, + F32Const(_) => { + stack.push_value(ValueType::F32)?; + }, + F64Const(_) => { + stack.push_value(ValueType::F64)?; + }, I32Eqz | I64Eqz => { // These instructions pop the value and compare it against zero, and pushes @@ -458,14 +461,14 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result { + F32ConvertSI32 | F32ConvertUI32 | F32ConvertSI64 | F32ConvertUI64 | F32DemoteF64 | + F32ReinterpretI32 => { stack.pop_value()?; stack.push_value(ValueType::F32)?; }, - F64ConvertSI32 | F64ConvertUI32 | F64ConvertSI64 | F64ConvertUI64 | - F64PromoteF32 | F64ReinterpretI64 => { + F64ConvertSI32 | F64ConvertUI32 | F64ConvertSI64 | F64ConvertUI64 | F64PromoteF32 | + F64ReinterpretI64 => { stack.pop_value()?; stack.push_value(ValueType::F64)?; }, @@ -475,11 +478,10 @@ pub fn compute(func_idx: u32, module: &elements::Module) -> Result { + SignExt(SignExtInstruction::I64Extend32S) => if let Some(vt) = stack.pop_value()? { stack.push_value(vt)?; - } - }, + }, } // If current value stack is heavier than maximal weight observed so far,