mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-15 11:10:49 +00:00
Update parity-wasm dependency to 0.31
This commit is contained in:
parent
f4b75bd840
commit
d6f82000ee
@ -8,7 +8,7 @@ description = "Collection of command-line utilities and corresponding Rust api f
|
||||
keywords = ["wasm", "webassembly", "pwasm"]
|
||||
|
||||
[dependencies]
|
||||
parity-wasm = { version = "0.30", default-features = false }
|
||||
parity-wasm = { version = "0.31", default-features = false }
|
||||
log = { version = "0.4", default-features = false }
|
||||
byteorder = { version = "1", default-features = false }
|
||||
|
||||
|
10
src/ext.rs
10
src/ext.rs
@ -8,10 +8,10 @@ use byteorder::{LittleEndian, ByteOrder};
|
||||
|
||||
type Insertion = (usize, u32, u32, String);
|
||||
|
||||
pub fn update_call_index(opcodes: &mut elements::Opcodes, original_imports: usize, inserts: &[Insertion]) {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
for opcode in opcodes.elements_mut().iter_mut() {
|
||||
if let &mut Call(ref mut call_index) = opcode {
|
||||
pub fn update_call_index(instructions: &mut elements::Instructions, original_imports: usize, inserts: &[Insertion]) {
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
for instruction in instructions.elements_mut().iter_mut() {
|
||||
if let &mut Call(ref mut call_index) = instruction {
|
||||
if let Some(pos) = inserts.iter().position(|x| x.1 == *call_index) {
|
||||
*call_index = (original_imports + pos) as u32;
|
||||
} else if *call_index as usize > original_imports {
|
||||
@ -98,7 +98,7 @@ pub fn shrink_unknown_stack(
|
||||
match section {
|
||||
&mut elements::Section::Data(ref mut data_section) => {
|
||||
for ref mut data_segment in data_section.entries_mut() {
|
||||
if data_segment.offset().code() == &[elements::Opcode::I32Const(4), elements::Opcode::End] {
|
||||
if data_segment.offset().code() == &[elements::Instruction::I32Const(4), elements::Instruction::End] {
|
||||
assert_eq!(data_segment.value().len(), 4);
|
||||
let current_val = LittleEndian::read_u32(data_segment.value());
|
||||
let new_val = current_val - shrink_amount;
|
||||
|
44
src/gas.rs
44
src/gas.rs
@ -3,10 +3,10 @@ use std::vec::Vec;
|
||||
use parity_wasm::{elements, builder};
|
||||
use rules;
|
||||
|
||||
pub fn update_call_index(opcodes: &mut elements::Opcodes, inserted_index: u32) {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
for opcode in opcodes.elements_mut().iter_mut() {
|
||||
if let &mut Call(ref mut call_index) = opcode {
|
||||
pub fn update_call_index(instructions: &mut elements::Instructions, inserted_index: u32) {
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
for instruction in instructions.elements_mut().iter_mut() {
|
||||
if let &mut Call(ref mut call_index) = instruction {
|
||||
if *call_index >= inserted_index { *call_index += 1}
|
||||
}
|
||||
}
|
||||
@ -83,12 +83,12 @@ impl Counter {
|
||||
}
|
||||
}
|
||||
|
||||
fn inject_grow_counter(opcodes: &mut elements::Opcodes, grow_counter_func: u32) -> usize {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
fn inject_grow_counter(instructions: &mut elements::Instructions, grow_counter_func: u32) -> usize {
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
let mut counter = 0;
|
||||
for opcode in opcodes.elements_mut() {
|
||||
if let GrowMemory(_) = *opcode {
|
||||
*opcode = Call(grow_counter_func);
|
||||
for instruction in instructions.elements_mut() {
|
||||
if let GrowMemory(_) = *instruction {
|
||||
*instruction = Call(grow_counter_func);
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
@ -96,14 +96,14 @@ fn inject_grow_counter(opcodes: &mut elements::Opcodes, grow_counter_func: u32)
|
||||
}
|
||||
|
||||
fn add_grow_counter(module: elements::Module, rules: &rules::Set, gas_func: u32) -> elements::Module {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
|
||||
let mut b = builder::from_module(module);
|
||||
b.push_function(
|
||||
builder::function()
|
||||
.signature().params().i32().build().with_return_type(Some(elements::ValueType::I32)).build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(vec![
|
||||
.with_instructions(elements::Instructions::new(vec![
|
||||
GetLocal(0),
|
||||
GetLocal(0),
|
||||
I32Const(rules.grow_cost() as i32),
|
||||
@ -121,24 +121,24 @@ fn add_grow_counter(module: elements::Module, rules: &rules::Set, gas_func: u32)
|
||||
}
|
||||
|
||||
pub fn inject_counter(
|
||||
opcodes: &mut elements::Opcodes,
|
||||
instructions: &mut elements::Instructions,
|
||||
rules: &rules::Set,
|
||||
gas_func: u32,
|
||||
) -> Result<(), ()> {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
|
||||
let mut counter = Counter::new();
|
||||
|
||||
// Begin an implicit function (i.e. `func...end`) block.
|
||||
counter.begin(0);
|
||||
|
||||
for cursor in 0..opcodes.elements().len() {
|
||||
let opcode = &opcodes.elements()[cursor];
|
||||
match *opcode {
|
||||
for cursor in 0..instructions.elements().len() {
|
||||
let instruction = &instructions.elements()[cursor];
|
||||
match *instruction {
|
||||
Block(_) | If(_) | Loop(_) => {
|
||||
// Increment previous block with the cost of the current opcode.
|
||||
let opcode_cost = rules.process(opcode)?;
|
||||
counter.increment(opcode_cost)?;
|
||||
let instruction_cost = rules.process(instruction)?;
|
||||
counter.increment(instruction_cost)?;
|
||||
|
||||
// Begin new block. The cost of the following opcodes until `End` or `Else` will
|
||||
// be included into this block.
|
||||
@ -164,8 +164,8 @@ pub fn inject_counter(
|
||||
}
|
||||
_ => {
|
||||
// An ordinal non control flow instruction. Just increment the cost of the current block.
|
||||
let opcode_cost = rules.process(opcode)?;
|
||||
counter.increment(opcode_cost)?;
|
||||
let instruction_cost = rules.process(instruction)?;
|
||||
counter.increment(instruction_cost)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,8 +175,8 @@ pub fn inject_counter(
|
||||
for block in counter.blocks {
|
||||
let effective_pos = block.start_pos + cumulative_offset;
|
||||
|
||||
opcodes.elements_mut().insert(effective_pos, I32Const(block.cost as i32));
|
||||
opcodes.elements_mut().insert(effective_pos+1, Call(gas_func));
|
||||
instructions.elements_mut().insert(effective_pos, I32Const(block.cost as i32));
|
||||
instructions.elements_mut().insert(effective_pos+1, Call(gas_func));
|
||||
|
||||
// Take into account these two inserted instructions.
|
||||
cumulative_offset += 2;
|
||||
|
@ -270,10 +270,10 @@ pub fn optimize(
|
||||
}
|
||||
|
||||
|
||||
pub fn update_call_index(opcodes: &mut elements::Opcodes, eliminated_indices: &[usize]) {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
for opcode in opcodes.elements_mut().iter_mut() {
|
||||
if let &mut Call(ref mut call_index) = opcode {
|
||||
pub fn update_call_index(instructions: &mut elements::Instructions, eliminated_indices: &[usize]) {
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
for instruction in instructions.elements_mut().iter_mut() {
|
||||
if let &mut Call(ref mut call_index) = instruction {
|
||||
let totalle = eliminated_indices.iter().take_while(|i| (**i as u32) < *call_index).count();
|
||||
trace!("rewired call {} -> call {}", *call_index, *call_index - totalle as u32);
|
||||
*call_index -= totalle as u32;
|
||||
@ -282,10 +282,10 @@ pub fn update_call_index(opcodes: &mut elements::Opcodes, eliminated_indices: &[
|
||||
}
|
||||
|
||||
/// Updates global references considering the _ordered_ list of eliminated indices
|
||||
pub fn update_global_index(opcodes: &mut Vec<elements::Opcode>, eliminated_indices: &[usize]) {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
for opcode in opcodes.iter_mut() {
|
||||
match opcode {
|
||||
pub fn update_global_index(instructions: &mut Vec<elements::Instruction>, eliminated_indices: &[usize]) {
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
for instruction in instructions.iter_mut() {
|
||||
match instruction {
|
||||
&mut GetGlobal(ref mut index) | &mut SetGlobal(ref mut index) => {
|
||||
let totalle = eliminated_indices.iter().take_while(|i| (**i as u32) < *index).count();
|
||||
trace!("rewired global {} -> global {}", *index, *index - totalle as u32);
|
||||
@ -297,10 +297,10 @@ pub fn update_global_index(opcodes: &mut Vec<elements::Opcode>, eliminated_indic
|
||||
}
|
||||
|
||||
/// Updates global references considering the _ordered_ list of eliminated indices
|
||||
pub fn update_type_index(opcodes: &mut elements::Opcodes, eliminated_indices: &[usize]) {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
for opcode in opcodes.elements_mut().iter_mut() {
|
||||
if let &mut CallIndirect(ref mut call_index, _) = opcode {
|
||||
pub fn update_type_index(instructions: &mut elements::Instructions, eliminated_indices: &[usize]) {
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
for instruction in instructions.elements_mut().iter_mut() {
|
||||
if let &mut CallIndirect(ref mut call_index, _) = instruction {
|
||||
let totalle = eliminated_indices.iter().take_while(|i| (**i as u32) < *call_index).count();
|
||||
trace!("rewired call_indrect {} -> call_indirect {}", *call_index, *call_index - totalle as u32);
|
||||
*call_index -= totalle as u32;
|
||||
@ -435,10 +435,10 @@ mod tests {
|
||||
.function()
|
||||
.signature().param().i32().build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_opcodes(elements::Instructions::new(
|
||||
vec![
|
||||
elements::Opcode::GetGlobal(0),
|
||||
elements::Opcode::End
|
||||
elements::Instruction::GetGlobal(0),
|
||||
elements::Instruction::End
|
||||
]
|
||||
))
|
||||
.build()
|
||||
@ -477,10 +477,10 @@ mod tests {
|
||||
.function()
|
||||
.signature().param().i32().build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_opcodes(elements::Instructions::new(
|
||||
vec![
|
||||
elements::Opcode::GetGlobal(1),
|
||||
elements::Opcode::End
|
||||
elements::Instruction::GetGlobal(1),
|
||||
elements::Instruction::End
|
||||
]
|
||||
))
|
||||
.build()
|
||||
@ -510,10 +510,10 @@ mod tests {
|
||||
.function()
|
||||
.signature().param().i32().build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_opcodes(elements::Instructions::new(
|
||||
vec![
|
||||
elements::Opcode::Call(1),
|
||||
elements::Opcode::End
|
||||
elements::Instruction::Call(1),
|
||||
elements::Instruction::End
|
||||
]
|
||||
))
|
||||
.build()
|
||||
@ -563,10 +563,10 @@ mod tests {
|
||||
.function()
|
||||
.signature().param().i32().build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_opcodes(elements::Instructions::new(
|
||||
vec![
|
||||
elements::Opcode::CallIndirect(1, 0),
|
||||
elements::Opcode::End
|
||||
elements::Instruction::CallIndirect(1, 0),
|
||||
elements::Instruction::End
|
||||
]
|
||||
))
|
||||
.build()
|
||||
@ -586,7 +586,7 @@ mod tests {
|
||||
|
||||
let indirect_opcode = &module.code_section().expect("code section to be generated").bodies()[0].code().elements()[0];
|
||||
match *indirect_opcode {
|
||||
elements::Opcode::CallIndirect(0, 0) => {},
|
||||
elements::Instruction::CallIndirect(0, 0) => {},
|
||||
_ => {
|
||||
panic!(
|
||||
"Expected call_indirect to use index 0 after optimization, since previois 0th was eliminated, but got {:?}",
|
||||
|
36
src/pack.rs
36
src/pack.rs
@ -3,7 +3,7 @@ use std::vec::Vec;
|
||||
use std::borrow::ToOwned;
|
||||
|
||||
use parity_wasm::elements::{
|
||||
self, Section, DataSection, Opcode, DataSegment, InitExpr, Internal, External,
|
||||
self, Section, DataSection, Instruction, DataSegment, InitExpr, Internal, External,
|
||||
ImportCountType,
|
||||
};
|
||||
use parity_wasm::builder;
|
||||
@ -162,7 +162,7 @@ pub fn pack_instance(raw_module: Vec<u8>, mut ctor_module: elements::Module) ->
|
||||
for section in ctor_module.sections_mut() {
|
||||
if let &mut Section::Data(ref mut data_section) = section {
|
||||
let (index, offset) = if let Some(ref entry) = data_section.entries().iter().last() {
|
||||
if let Opcode::I32Const(offst) = entry.offset().code()[0] {
|
||||
if let Instruction::I32Const(offst) = entry.offset().code()[0] {
|
||||
let len = entry.value().len() as i32;
|
||||
let offst = offst as i32;
|
||||
(entry.index(), offst + (len + 4) - len % 4)
|
||||
@ -174,7 +174,7 @@ pub fn pack_instance(raw_module: Vec<u8>, mut ctor_module: elements::Module) ->
|
||||
};
|
||||
let code_data = DataSegment::new(
|
||||
index,
|
||||
InitExpr::new(vec![Opcode::I32Const(offset), Opcode::End]),
|
||||
InitExpr::new(vec![Instruction::I32Const(offset), Instruction::End]),
|
||||
raw_module.clone()
|
||||
);
|
||||
data_section.entries_mut().push(code_data);
|
||||
@ -185,13 +185,13 @@ pub fn pack_instance(raw_module: Vec<u8>, mut ctor_module: elements::Module) ->
|
||||
let mut new_module = builder::from_module(ctor_module)
|
||||
.function()
|
||||
.signature().build()
|
||||
.body().with_opcodes(elements::Opcodes::new(
|
||||
.body().with_instructions(elements::Instructions::new(
|
||||
vec![
|
||||
Opcode::Call((create_func_id + ctor_import_functions) as u32),
|
||||
Opcode::I32Const(code_data_address),
|
||||
Opcode::I32Const(raw_module.len() as i32),
|
||||
Opcode::Call(ret_function_id as u32),
|
||||
Opcode::End,
|
||||
Instruction::Call((create_func_id + ctor_import_functions) as u32),
|
||||
Instruction::I32Const(code_data_address),
|
||||
Instruction::I32Const(raw_module.len() as i32),
|
||||
Instruction::Call(ret_function_id as u32),
|
||||
Instruction::End,
|
||||
])).build()
|
||||
.build()
|
||||
.build();
|
||||
@ -249,9 +249,9 @@ mod test {
|
||||
.function()
|
||||
.signature().build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_opcodes(elements::Instructions::new(
|
||||
vec![
|
||||
elements::Opcode::End
|
||||
elements::Instruction::End
|
||||
]
|
||||
))
|
||||
.build()
|
||||
@ -259,9 +259,9 @@ mod test {
|
||||
.function()
|
||||
.signature().build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_opcodes(elements::Instructions::new(
|
||||
vec![
|
||||
elements::Opcode::End
|
||||
elements::Instruction::End
|
||||
]
|
||||
))
|
||||
.build()
|
||||
@ -287,7 +287,7 @@ mod test {
|
||||
.external().memory(1 as u32, Some(1 as u32))
|
||||
.build()
|
||||
.data()
|
||||
.offset(elements::Opcode::I32Const(16)).value(vec![0u8])
|
||||
.offset(elements::Instruction::I32Const(16)).value(vec![0u8])
|
||||
.build()
|
||||
.function()
|
||||
.signature()
|
||||
@ -298,9 +298,9 @@ mod test {
|
||||
.function()
|
||||
.signature().build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_opcodes(elements::Instructions::new(
|
||||
vec![
|
||||
elements::Opcode::End
|
||||
elements::Instruction::End
|
||||
]
|
||||
))
|
||||
.build()
|
||||
@ -308,9 +308,9 @@ mod test {
|
||||
.function()
|
||||
.signature().build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_opcodes(elements::Instructions::new(
|
||||
vec![
|
||||
elements::Opcode::End
|
||||
elements::Instruction::End
|
||||
]
|
||||
))
|
||||
.build()
|
||||
|
10
src/rules.rs
10
src/rules.rs
@ -70,10 +70,10 @@ impl ::std::str::FromStr for InstructionType {
|
||||
}
|
||||
|
||||
impl InstructionType {
|
||||
pub fn op(opcode: &elements::Opcode) -> Self {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
pub fn op(instruction: &elements::Instruction) -> Self {
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
|
||||
match *opcode {
|
||||
match *instruction {
|
||||
Unreachable => InstructionType::Unreachable,
|
||||
Nop => InstructionType::Nop,
|
||||
Block(_) => InstructionType::ControlFlow,
|
||||
@ -288,8 +288,8 @@ impl Set {
|
||||
Set { regular: regular, entries: entries, grow: 0 }
|
||||
}
|
||||
|
||||
pub fn process(&self, opcode: &elements::Opcode) -> Result<u32, ()> {
|
||||
match self.entries.get(&InstructionType::op(opcode)).map(|x| *x) {
|
||||
pub fn process(&self, instruction: &elements::Instruction) -> Result<u32, ()> {
|
||||
match self.entries.get(&InstructionType::op(instruction)).map(|x| *x) {
|
||||
None | Some(Metering::Regular) => Ok(self.regular),
|
||||
Some(Metering::Forbidden) => Err(()),
|
||||
Some(Metering::Fixed(val)) => Ok(val),
|
||||
|
@ -1,5 +1,5 @@
|
||||
use parity_wasm::{elements, builder};
|
||||
use self::elements::{ Module, GlobalEntry, External, ExportEntry, GlobalType, ValueType, InitExpr, Opcode, Internal };
|
||||
use self::elements::{ Module, GlobalEntry, External, ExportEntry, GlobalType, ValueType, InitExpr, Instruction, Internal };
|
||||
use byteorder::{ LittleEndian, ByteOrder };
|
||||
|
||||
pub fn inject_runtime_type(module: Module, runtime_type: &[u8], runtime_version: u32) -> Module {
|
||||
@ -18,9 +18,9 @@ pub fn inject_runtime_type(module: Module, runtime_type: &[u8], runtime_version:
|
||||
let total_globals_count: u32 = globals_count + imported_globals_count;
|
||||
|
||||
builder::from_module(module)
|
||||
.with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Opcode::I32Const(runtime_type as i32), Opcode::End])))
|
||||
.with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Instruction::I32Const(runtime_type as i32), Instruction::End])))
|
||||
.with_export(ExportEntry::new("RUNTIME_TYPE".into(), Internal::Global(total_globals_count)))
|
||||
.with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Opcode::I32Const(runtime_version as i32), Opcode::End])))
|
||||
.with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Instruction::I32Const(runtime_version as i32), Instruction::End])))
|
||||
.with_export(ExportEntry::new("RUNTIME_VERSION".into(), Internal::Global(total_globals_count + 1)))
|
||||
.build()
|
||||
}
|
||||
@ -31,7 +31,7 @@ mod tests {
|
||||
#[test]
|
||||
fn it_injects() {
|
||||
let mut module = builder::module()
|
||||
.with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Opcode::I32Const(42 as i32)])))
|
||||
.with_global(GlobalEntry::new(GlobalType::new(ValueType::I32, false), InitExpr::new(vec![Instruction::I32Const(42 as i32)])))
|
||||
.build();
|
||||
module = inject_runtime_type(module, b"emcc", 1);
|
||||
let global_section = module.global_section().expect("Global section expected");
|
||||
|
@ -136,7 +136,7 @@ impl Stack {
|
||||
|
||||
/// This function expects the function to be validated.
|
||||
pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, Error> {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
|
||||
let func_section = module
|
||||
.function_section()
|
||||
@ -165,7 +165,7 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
|
||||
.bodies()
|
||||
.get(func_idx as usize)
|
||||
.ok_or_else(|| Error("Function body for the index isn't found".into()))?;
|
||||
let opcodes = body.code();
|
||||
let instructions = body.code();
|
||||
|
||||
let mut stack = Stack::new();
|
||||
let mut max_height: u32 = 0;
|
||||
@ -186,7 +186,7 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
|
||||
});
|
||||
|
||||
loop {
|
||||
if pc >= opcodes.elements().len() {
|
||||
if pc >= instructions.elements().len() {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ pub(crate) fn compute(func_idx: u32, module: &elements::Module) -> Result<u32, E
|
||||
max_height = stack.height();
|
||||
}
|
||||
|
||||
let opcode = &opcodes.elements()[pc];
|
||||
let opcode = &instructions.elements()[pc];
|
||||
trace!(target: "max_height", "{:?}", opcode);
|
||||
|
||||
match *opcode {
|
||||
|
@ -57,7 +57,7 @@ use parity_wasm::builder;
|
||||
/// Macro to generate preamble and postamble.
|
||||
macro_rules! instrument_call {
|
||||
($callee_idx: expr, $callee_stack_cost: expr, $stack_height_global_idx: expr, $stack_limit: expr) => {{
|
||||
use $crate::parity_wasm::elements::Opcode::*;
|
||||
use $crate::parity_wasm::elements::Instruction::*;
|
||||
[
|
||||
// stack_height += stack_cost(F)
|
||||
GetGlobal($stack_height_global_idx),
|
||||
@ -160,7 +160,7 @@ fn generate_stack_height_global(ctx: &mut Context, module: &mut elements::Module
|
||||
.value_type()
|
||||
.i32()
|
||||
.mutable()
|
||||
.init_expr(elements::Opcode::I32Const(0))
|
||||
.init_expr(elements::Instruction::I32Const(0))
|
||||
.build();
|
||||
|
||||
// Try to find an existing global section.
|
||||
@ -268,13 +268,13 @@ fn instrument_functions(ctx: &mut Context, module: &mut elements::Module) -> Res
|
||||
/// ```
|
||||
fn instrument_function(
|
||||
ctx: &mut Context,
|
||||
opcodes: &mut elements::Opcodes,
|
||||
instructions: &mut elements::Instructions,
|
||||
) -> Result<(), Error> {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
|
||||
let mut cursor = 0;
|
||||
loop {
|
||||
if cursor >= opcodes.elements().len() {
|
||||
if cursor >= instructions.elements().len() {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -287,8 +287,8 @@ fn instrument_function(
|
||||
}
|
||||
|
||||
let action: Action = {
|
||||
let opcode = &opcodes.elements()[cursor];
|
||||
match *opcode {
|
||||
let instruction = &instructions.elements()[cursor];
|
||||
match *instruction {
|
||||
Call(ref callee_idx) => {
|
||||
let callee_stack_cost = ctx
|
||||
.stack_cost(*callee_idx)
|
||||
@ -330,7 +330,7 @@ fn instrument_function(
|
||||
//
|
||||
// To splice actually take a place, we need to consume iterator
|
||||
// splice returns. So we just `count()` it.
|
||||
let _ = opcodes
|
||||
let _ = instructions
|
||||
.elements_mut()
|
||||
.splice(cursor..(cursor + 1), new_seq.iter().cloned())
|
||||
.count();
|
||||
|
@ -93,17 +93,17 @@ pub(crate) fn generate_thunks(
|
||||
// - argument pushing
|
||||
// - instrumented call
|
||||
// - end
|
||||
let mut thunk_body: Vec<elements::Opcode> = Vec::with_capacity(
|
||||
let mut thunk_body: Vec<elements::Instruction> = Vec::with_capacity(
|
||||
thunk.signature.params().len() +
|
||||
instrumented_call.len() +
|
||||
1
|
||||
);
|
||||
|
||||
for (arg_idx, _) in thunk.signature.params().iter().enumerate() {
|
||||
thunk_body.push(elements::Opcode::GetLocal(arg_idx as u32));
|
||||
thunk_body.push(elements::Instruction::GetLocal(arg_idx as u32));
|
||||
}
|
||||
thunk_body.extend(instrumented_call.iter().cloned());
|
||||
thunk_body.push(elements::Opcode::End);
|
||||
thunk_body.push(elements::Instruction::End);
|
||||
|
||||
// TODO: Don't generate a signature, but find an existing one.
|
||||
|
||||
@ -114,7 +114,7 @@ pub(crate) fn generate_thunks(
|
||||
.with_return_type(thunk.signature.return_type().clone())
|
||||
.build()
|
||||
.body()
|
||||
.with_opcodes(elements::Opcodes::new(
|
||||
.with_instructions(elements::Instructions::new(
|
||||
thunk_body
|
||||
))
|
||||
.build()
|
||||
|
@ -47,11 +47,11 @@ pub fn resolve_global(module: &elements::Module, index: u32) -> Symbol {
|
||||
Symbol::Global(index as usize - globals as usize)
|
||||
}
|
||||
|
||||
pub fn push_code_symbols(module: &elements::Module, opcodes: &[elements::Opcode], dest: &mut Vec<Symbol>) {
|
||||
use parity_wasm::elements::Opcode::*;
|
||||
pub fn push_code_symbols(module: &elements::Module, instructions: &[elements::Instruction], dest: &mut Vec<Symbol>) {
|
||||
use parity_wasm::elements::Instruction::*;
|
||||
|
||||
for opcode in opcodes {
|
||||
match opcode {
|
||||
for instruction in instructions {
|
||||
match instruction {
|
||||
&Call(idx) => {
|
||||
dest.push(resolve_function(module, idx));
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user