sign_ext feature flag (#174)

* sign_ext feature flag

* Derive default to fix clippy warning
This commit is contained in:
Leonardo Yvens
2021-12-21 14:23:16 +00:00
committed by GitHub
parent 5259f1c922
commit b22696aaa5
4 changed files with 25 additions and 14 deletions
+1
View File
@@ -75,3 +75,4 @@ cli = [
"env_logger",
"lazy_static",
]
sign_ext = ["parity-wasm/sign_ext"]
+1 -14
View File
@@ -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<usize>,
@@ -48,19 +48,6 @@ struct ControlFlowNode {
loopback_edges: Vec<NodeId>,
}
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
+10
View File
@@ -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,
}
}
}
+13
View File
@@ -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<u32, E
stack.pop_values(1)?;
stack.push_values(1)?;
},
#[cfg(feature = "sign_ext")]
SignExt(SignExtInstruction::I32Extend8S) |
SignExt(SignExtInstruction::I32Extend16S) |
SignExt(SignExtInstruction::I64Extend8S) |
SignExt(SignExtInstruction::I64Extend16S) |
SignExt(SignExtInstruction::I64Extend32S) => {
stack.pop_values(1)?;
stack.push_values(1)?;
},
}
pc += 1;
}