mirror of
https://github.com/pezkuwichain/wasm-instrument.git
synced 2026-06-12 17:01:05 +00:00
Fixes necessary for having no_std imports work with edition2018
This commit is contained in:
+3
-2
@@ -8,6 +8,7 @@ use super::{
|
|||||||
PackingError,
|
PackingError,
|
||||||
OptimizerError,
|
OptimizerError,
|
||||||
TargetRuntime,
|
TargetRuntime,
|
||||||
|
std::fmt,
|
||||||
};
|
};
|
||||||
use parity_wasm::elements;
|
use parity_wasm::elements;
|
||||||
|
|
||||||
@@ -36,8 +37,8 @@ pub enum SourceTarget {
|
|||||||
Unknown,
|
Unknown,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Display for Error {
|
impl fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
use self::Error::*;
|
use self::Error::*;
|
||||||
match self {
|
match self {
|
||||||
Encoding(err) => write!(f, "Encoding error ({})", err),
|
Encoding(err) => write!(f, "Encoding error ({})", err),
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
use std::string::String;
|
use crate::std::string::String;
|
||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
use std::borrow::ToOwned;
|
use crate::std::borrow::ToOwned;
|
||||||
|
|
||||||
use parity_wasm::{elements, builder};
|
use parity_wasm::{elements, builder};
|
||||||
use byteorder::{LittleEndian, ByteOrder};
|
use byteorder::{LittleEndian, ByteOrder};
|
||||||
|
|||||||
+3
-3
@@ -7,9 +7,9 @@
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod validation;
|
mod validation;
|
||||||
|
|
||||||
use std::cmp::min;
|
use crate::std::cmp::min;
|
||||||
use std::mem;
|
use crate::std::mem;
|
||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
|
|
||||||
use parity_wasm::{elements, builder};
|
use parity_wasm::{elements, builder};
|
||||||
use crate::rules::Rules;
|
use crate::rules::Rules;
|
||||||
|
|||||||
@@ -11,9 +11,13 @@
|
|||||||
use super::MeteredBlock;
|
use super::MeteredBlock;
|
||||||
use crate::rules::Set as RuleSet;
|
use crate::rules::Set as RuleSet;
|
||||||
use crate::rules::Rules;
|
use crate::rules::Rules;
|
||||||
|
use crate::std::vec::Vec;
|
||||||
use parity_wasm::elements::{FuncBody, Instruction};
|
use parity_wasm::elements::{FuncBody, Instruction};
|
||||||
|
|
||||||
use std::collections::HashMap;
|
#[cfg(features = "std")]
|
||||||
|
use crate::std::collections::HashMap as Map;
|
||||||
|
#[cfg(not(features = "std"))]
|
||||||
|
use crate::std::collections::BTreeMap as Map;
|
||||||
|
|
||||||
/// An ID for a node in a ControlFlowGraph.
|
/// An ID for a node in a ControlFlowGraph.
|
||||||
type NodeId = usize;
|
type NodeId = usize;
|
||||||
@@ -288,7 +292,7 @@ fn validate_graph_gas_costs(graph: &ControlFlowGraph) -> bool {
|
|||||||
node_id: NodeId,
|
node_id: NodeId,
|
||||||
mut total_actual: u32,
|
mut total_actual: u32,
|
||||||
mut total_charged: u32,
|
mut total_charged: u32,
|
||||||
loop_costs: &mut HashMap<NodeId, (u32, u32)>,
|
loop_costs: &mut Map<NodeId, (u32, u32)>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let node = graph.get_node(node_id);
|
let node = graph.get_node(node_id);
|
||||||
|
|
||||||
@@ -325,7 +329,7 @@ fn validate_graph_gas_costs(graph: &ControlFlowGraph) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Recursively explore all paths through the execution graph starting from the entry node.
|
// Recursively explore all paths through the execution graph starting from the entry node.
|
||||||
visit(graph, 0, 0, 0, &mut HashMap::new())
|
visit(graph, 0, 0, 0, &mut Map::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Validate that the metered blocks are correct with respect to the function body by exhaustively
|
/// Validate that the metered blocks are correct with respect to the function body by exhaustively
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use parity_wasm::elements;
|
use parity_wasm::elements;
|
||||||
use super::ref_list::{RefList, EntryRef};
|
use super::ref_list::{RefList, EntryRef};
|
||||||
use std::{
|
use crate::std::{
|
||||||
vec::Vec,
|
vec::Vec,
|
||||||
borrow::ToOwned,
|
borrow::ToOwned,
|
||||||
string::String,
|
string::String,
|
||||||
|
|||||||
+7
-1
@@ -83,7 +83,7 @@ impl TargetRuntime {
|
|||||||
|
|
||||||
#[cfg(not(feature = "std"))]
|
#[cfg(not(feature = "std"))]
|
||||||
mod std {
|
mod std {
|
||||||
pub use alloc::{borrow, boxed, string, vec};
|
pub use ::alloc::{borrow, boxed, string, vec};
|
||||||
pub use core::*;
|
pub use core::*;
|
||||||
|
|
||||||
pub mod rc {
|
pub mod rc {
|
||||||
@@ -94,3 +94,9 @@ mod std {
|
|||||||
pub use alloc::collections::{BTreeMap, BTreeSet};
|
pub use alloc::collections::{BTreeMap, BTreeSet};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(feature = "std")]
|
||||||
|
mod std {
|
||||||
|
pub use std::*;
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
use std::env;
|
use crate::std::env;
|
||||||
use log::LevelFilter;
|
use log::LevelFilter;
|
||||||
use env_logger::Builder;
|
use env_logger::Builder;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
|||||||
+4
-4
@@ -1,9 +1,9 @@
|
|||||||
#[cfg(features = "std")]
|
#[cfg(features = "std")]
|
||||||
use std::collections::{HashSet as Set};
|
use crate::std::collections::{HashSet as Set};
|
||||||
#[cfg(not(features = "std"))]
|
#[cfg(not(features = "std"))]
|
||||||
use std::collections::{BTreeSet as Set};
|
use crate::std::collections::{BTreeSet as Set};
|
||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
use std::mem;
|
use crate::std::mem;
|
||||||
|
|
||||||
use parity_wasm::elements;
|
use parity_wasm::elements;
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
use std::fmt;
|
use crate::std::fmt;
|
||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
use std::borrow::ToOwned;
|
use crate::std::borrow::ToOwned;
|
||||||
|
|
||||||
use parity_wasm::elements::{
|
use parity_wasm::elements::{
|
||||||
self, Section, DataSection, Instruction, DataSegment, InitExpr, Internal, External,
|
self, Section, DataSection, Instruction, DataSegment, InitExpr, Internal, External,
|
||||||
|
|||||||
+8
-8
@@ -1,9 +1,9 @@
|
|||||||
#![warn(missing_docs)]
|
#![warn(missing_docs)]
|
||||||
|
|
||||||
use std::rc::Rc;
|
use crate::std::rc::Rc;
|
||||||
use std::cell::RefCell;
|
use crate::std::cell::RefCell;
|
||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
use std::slice;
|
use crate::std::slice;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum EntryOrigin {
|
enum EntryOrigin {
|
||||||
@@ -50,7 +50,7 @@ impl<T> Entry<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ::std::ops::Deref for Entry<T> {
|
impl<T> crate::std::ops::Deref for Entry<T> {
|
||||||
type Target = T;
|
type Target = T;
|
||||||
|
|
||||||
fn deref(&self) -> &T {
|
fn deref(&self) -> &T {
|
||||||
@@ -58,7 +58,7 @@ impl<T> ::std::ops::Deref for Entry<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> ::std::ops::DerefMut for Entry<T> {
|
impl<T> crate::std::ops::DerefMut for Entry<T> {
|
||||||
fn deref_mut(&mut self) -> &mut T {
|
fn deref_mut(&mut self) -> &mut T {
|
||||||
&mut self.val
|
&mut self.val
|
||||||
}
|
}
|
||||||
@@ -82,14 +82,14 @@ impl<T> From<Entry<T>> for EntryRef<T> {
|
|||||||
|
|
||||||
impl<T> EntryRef<T> {
|
impl<T> EntryRef<T> {
|
||||||
/// Read the reference data.
|
/// Read the reference data.
|
||||||
pub fn read(&self) -> ::std::cell::Ref<Entry<T>> {
|
pub fn read(&self) -> crate::std::cell::Ref<Entry<T>> {
|
||||||
self.0.borrow()
|
self.0.borrow()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to modify internal content of the referenced object.
|
/// Try to modify internal content of the referenced object.
|
||||||
///
|
///
|
||||||
/// May panic if it is already borrowed.
|
/// May panic if it is already borrowed.
|
||||||
pub fn write(&self) -> ::std::cell::RefMut<Entry<T>> {
|
pub fn write(&self) -> crate::std::cell::RefMut<Entry<T>> {
|
||||||
self.0.borrow_mut()
|
self.0.borrow_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-4
@@ -1,9 +1,10 @@
|
|||||||
#[cfg(features = "std")]
|
#[cfg(features = "std")]
|
||||||
use std::collections::{HashMap as Map};
|
use crate::std::collections::HashMap as Map;
|
||||||
#[cfg(not(features = "std"))]
|
#[cfg(not(features = "std"))]
|
||||||
use std::collections::{BTreeMap as Map};
|
use crate::std::collections::BTreeMap as Map;
|
||||||
|
|
||||||
use std::num::NonZeroU32;
|
use crate::std::num::NonZeroU32;
|
||||||
|
use crate::std::str::FromStr;
|
||||||
|
|
||||||
use parity_wasm::elements;
|
use parity_wasm::elements;
|
||||||
|
|
||||||
@@ -68,7 +69,7 @@ pub enum InstructionType {
|
|||||||
GrowMemory,
|
GrowMemory,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ::std::str::FromStr for InstructionType {
|
impl FromStr for InstructionType {
|
||||||
type Err = UnknownInstruction;
|
type Err = UnknownInstruction;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
|
|
||||||
use parity_wasm::elements::{self, BlockType, Type};
|
use parity_wasm::elements::{self, BlockType, Type};
|
||||||
use super::{resolve_func_type, Error};
|
use super::{resolve_func_type, Error};
|
||||||
|
|||||||
@@ -49,8 +49,8 @@
|
|||||||
//! between the frames.
|
//! between the frames.
|
||||||
//! - upon entry into the function entire stack frame is allocated.
|
//! - upon entry into the function entire stack frame is allocated.
|
||||||
|
|
||||||
use std::string::String;
|
use crate::std::string::String;
|
||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
|
|
||||||
use parity_wasm::elements::{self, Type};
|
use parity_wasm::elements::{self, Type};
|
||||||
use parity_wasm::builder;
|
use parity_wasm::builder;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#[cfg(features = "std")]
|
#[cfg(features = "std")]
|
||||||
use std::collections::{HashMap as Map};
|
use crate::std::collections::{HashMap as Map};
|
||||||
#[cfg(not(features = "std"))]
|
#[cfg(not(features = "std"))]
|
||||||
use std::collections::{BTreeMap as Map};
|
use crate::std::collections::{BTreeMap as Map};
|
||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
|
|
||||||
use parity_wasm::elements::{self, FunctionType, Internal};
|
use parity_wasm::elements::{self, FunctionType, Internal};
|
||||||
use parity_wasm::builder;
|
use parity_wasm::builder;
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
#[cfg(features = "std")]
|
#[cfg(features = "std")]
|
||||||
use std::collections::{HashSet as Set};
|
use crate::std::collections::{HashSet as Set};
|
||||||
#[cfg(not(features = "std"))]
|
#[cfg(not(features = "std"))]
|
||||||
use std::collections::{BTreeSet as Set};
|
use crate::std::collections::{BTreeSet as Set};
|
||||||
use std::vec::Vec;
|
use crate::std::vec::Vec;
|
||||||
|
|
||||||
use parity_wasm::elements;
|
use parity_wasm::elements;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user