Make it work under no_std

This commit is contained in:
Sergey Pepyakin 2019-04-15 17:45:54 +02:00
parent 379e960c94
commit 321f0b765c
17 changed files with 40 additions and 28 deletions

View File

@ -10,17 +10,6 @@ description = "WebAssembly interpreter"
keywords = ["wasm", "webassembly", "bytecode", "interpreter"]
exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
[features]
default = ["std"]
# Disable for no_std support
std = [
"parity-wasm/std",
"wasmi-validation/std",
]
# Enable for no_std support
# hashbrown only works on no_std
core = ["hashbrown/nightly", "libm"]
[dependencies]
wasmi-validation = { path = "validation", default-features = false }
parity-wasm = { version = "0.31", default-features = false }
@ -33,5 +22,20 @@ assert_matches = "1.1"
rand = "0.4.2"
wabt = "0.6"
[features]
default = ["std"]
# Disable for no_std support
std = [
"parity-wasm/std",
"wasmi-validation/std",
]
# Enable for no_std support
# hashbrown only works on no_std
core = [
"wasmi-validation/core",
"hashbrown/nightly",
"libm"
]
[workspace]
members = ["validation"]

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use alloc::rc::{Rc, Weak};
use core::fmt;
use host::Externals;

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
#[cfg(not(feature = "std"))]
use hashbrown::HashMap;

View File

@ -68,7 +68,7 @@
//!
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
/// Should we keep a value before "discarding" a stack frame?
///

View File

@ -97,7 +97,7 @@
#![warn(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]
//// alloc is required in no_std
#![cfg_attr(not(feature = "std"), feature(alloc))]
#![cfg_attr(not(feature = "std"), feature(alloc, alloc_prelude))]
#[cfg(not(feature = "std"))]
#[macro_use]
@ -123,7 +123,7 @@ extern crate parity_wasm;
extern crate wasmi_validation as validation;
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use core::fmt;
#[cfg(feature = "std")]
use std::error;

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use alloc::rc::Rc;
use core::cell::{Cell, RefCell};
use core::cmp;

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use alloc::rc::Rc;
use core::cell::RefCell;
use core::fmt;

View File

@ -1,3 +1,6 @@
#[allow(unused_imports)]
use alloc::prelude::v1::*;
use parity_wasm::elements::{BlockType, Instruction};
use validation::func::{

View File

@ -1,3 +1,6 @@
#[allow(unused_imports)]
use alloc::prelude::v1::*;
use crate::{
isa,
validation::{validate_module2, Error, Validation},

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use core::fmt;
use core::ops;
use core::{u32, usize};

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use alloc::rc::Rc;
use core::cell::RefCell;
use core::fmt;

View File

@ -7,7 +7,11 @@ edition = "2018"
[dependencies]
parity-wasm = { version = "0.31", default-features = false }
memory_units_crate = { package = "memory_units", version = "0.3.0" }
hashbrown = { version = "0.1.8", optional = true }
[features]
default = ["std"]
std = ["parity-wasm/std"]
core = [
"hashbrown/nightly"
]

View File

@ -1,6 +1,6 @@
use crate::Error;
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use parity_wasm::elements::{
BlockType, FunctionType, GlobalType, MemoryType, TableType, ValueType,
};

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use crate::{
context::ModuleContext, stack::StackWithLimit, util::Locals, Error, FunctionValidator,

View File

@ -3,7 +3,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
//// alloc is required in no_std
#![cfg_attr(not(feature = "std"), feature(alloc))]
#![cfg_attr(not(feature = "std"), feature(alloc, alloc_prelude))]
#[cfg(not(feature = "std"))]
#[macro_use]
@ -22,7 +22,7 @@ pub const DEFAULT_TABLE_INDEX: u32 = 0;
pub const LINEAR_MEMORY_MAX_PAGES: Pages = Pages(65536);
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use core::fmt;
#[cfg(feature = "std")]
use std::error;
@ -167,8 +167,6 @@ pub fn deny_floating_point(module: &Module) -> Result<(), Error> {
}
if let (Some(sec), Some(types)) = (module.function_section(), module.type_section()) {
use parity_wasm::elements::{Type, ValueType};
let types = types.types();
for sig in sec.entries() {

View File

@ -1,5 +1,5 @@
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use core::fmt;
#[cfg(feature = "std")]

View File

@ -1,6 +1,6 @@
use crate::Error;
#[allow(unused_imports)]
use alloc::prelude::*;
use alloc::prelude::v1::*;
use parity_wasm::elements::{Local, ValueType};
/// Locals are the concatenation of a slice of function parameters