diff --git a/Cargo.toml b/Cargo.toml index ff52d7b..744b795 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -75,3 +75,4 @@ cli = [ "env_logger", "lazy_static", ] +sign_ext = ["parity-wasm/sign_ext"] diff --git a/src/gas/validation.rs b/src/gas/validation.rs index 5bd2b2f..812c37d 100644 --- a/src/gas/validation.rs +++ b/src/gas/validation.rs @@ -25,7 +25,7 @@ type NodeId = usize; /// A node in a control flow graph is commonly known as a basic block. This is a sequence of /// operations that are always executed sequentially. -#[derive(Debug)] +#[derive(Debug, Default)] struct ControlFlowNode { /// The index of the first instruction in the basic block. This is only used for debugging. first_instr_pos: Option, @@ -48,19 +48,6 @@ struct ControlFlowNode { loopback_edges: Vec, } -impl Default for ControlFlowNode { - fn default() -> Self { - ControlFlowNode { - first_instr_pos: None, - actual_cost: 0, - charged_cost: 0, - is_loop_target: false, - forward_edges: Vec::new(), - loopback_edges: Vec::new(), - } - } -} - /// A control flow graph where nodes are basic blocks and edges represent possible transitions /// between them in execution flow. The graph has two types of edges, forward and loop-back edges. /// The subgraph with only the forward edges forms a directed acyclic graph (DAG); including the diff --git a/src/rules.rs b/src/rules.rs index 6e33f95..4a1cbc3 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -65,6 +65,9 @@ pub enum InstructionType { Nop, CurrentMemory, GrowMemory, + + #[cfg(feature = "sign_ext")] + SignExt, } impl FromStr for InstructionType { @@ -92,6 +95,10 @@ impl FromStr for InstructionType { "nop" => Ok(InstructionType::Nop), "current_mem" => Ok(InstructionType::CurrentMemory), "grow_mem" => Ok(InstructionType::GrowMemory), + + #[cfg(feature = "sign_ext")] + "sign_ext" => Ok(InstructionType::SignExt), + _ => Err(UnknownInstruction), } } @@ -290,6 +297,9 @@ impl InstructionType { I64ReinterpretF64 => InstructionType::Reinterpretation, F32ReinterpretI32 => InstructionType::Reinterpretation, F64ReinterpretI64 => InstructionType::Reinterpretation, + + #[cfg(feature = "sign_ext")] + SignExt(_) => InstructionType::SignExt, } } } diff --git a/src/stack_height/max_height.rs b/src/stack_height/max_height.rs index 4e928d3..6b3d566 100644 --- a/src/stack_height/max_height.rs +++ b/src/stack_height/max_height.rs @@ -4,6 +4,9 @@ use super::{resolve_func_type, Error}; use log::trace; use parity_wasm::elements::{self, BlockType, Type}; +#[cfg(feature = "sign_ext")] +use parity_wasm::elements::SignExtInstruction; + /// Control stack frame. #[derive(Debug)] struct Frame { @@ -410,6 +413,16 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result { + stack.pop_values(1)?; + stack.push_values(1)?; + }, } pc += 1; }