Make it compile.

This commit is contained in:
Sergey Pepyakin 2019-04-15 17:33:50 +02:00
parent e167cbcb96
commit 1dad287999
8 changed files with 20 additions and 9 deletions

View File

@ -13,12 +13,16 @@ exclude = [ "/res/*", "/tests/*", "/fuzz/*", "/benches/*" ]
[features] [features]
default = ["std"] default = ["std"]
# Disable for no_std support # Disable for no_std support
std = ["parity-wasm/std"] std = [
"parity-wasm/std",
"wasmi-validation/std",
]
# Enable for no_std support # Enable for no_std support
# hashbrown only works on no_std # hashbrown only works on no_std
core = ["hashbrown/nightly", "libm"] core = ["hashbrown/nightly", "libm"]
[dependencies] [dependencies]
wasmi-validation = { path = "validation", default-features = false }
parity-wasm = { version = "0.31", default-features = false } parity-wasm = { version = "0.31", default-features = false }
hashbrown = { version = "0.1.8", optional = true } hashbrown = { version = "0.1.8", optional = true }
memory_units = "0.3.0" memory_units = "0.3.0"

View File

@ -120,6 +120,8 @@ extern crate hashbrown;
extern crate memory_units as memory_units_crate; extern crate memory_units as memory_units_crate;
extern crate parity_wasm; extern crate parity_wasm;
extern crate wasmi_validation as validation;
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use alloc::prelude::*;
use core::fmt; use core::fmt;
@ -392,7 +394,6 @@ mod prepare;
mod runner; mod runner;
mod table; mod table;
mod types; mod types;
mod validation;
mod value; mod value;
#[cfg(test)] #[cfg(test)]

View File

@ -108,7 +108,7 @@ impl MemoryInstance {
/// ///
/// [`LINEAR_MEMORY_PAGE_SIZE`]: constant.LINEAR_MEMORY_PAGE_SIZE.html /// [`LINEAR_MEMORY_PAGE_SIZE`]: constant.LINEAR_MEMORY_PAGE_SIZE.html
pub fn alloc(initial: Pages, maximum: Option<Pages>) -> Result<MemoryRef, Error> { pub fn alloc(initial: Pages, maximum: Option<Pages>) -> Result<MemoryRef, Error> {
validate_memory(initial, maximum).map_err(Error::Memory)?; validation::validate_memory(initial, maximum).map_err(Error::Memory)?;
let memory = MemoryInstance::new(initial, maximum); let memory = MemoryInstance::new(initial, maximum);
Ok(MemoryRef(Rc::new(memory))) Ok(MemoryRef(Rc::new(memory)))
@ -268,7 +268,7 @@ impl MemoryInstance {
} }
let new_size: Pages = size_before_grow + additional; let new_size: Pages = size_before_grow + additional;
let maximum = self.maximum.unwrap_or(LINEAR_MEMORY_MAX_PAGES); let maximum = self.maximum.unwrap_or(validation::LINEAR_MEMORY_MAX_PAGES);
if new_size > maximum { if new_size > maximum {
return Err(Error::Memory(format!( return Err(Error::Memory(format!(
"Trying to grow memory by {} pages when already have {}", "Trying to grow memory by {} pages when already have {}",

View File

@ -10,7 +10,7 @@ use hashbrown::HashMap;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::collections::HashMap; use std::collections::HashMap;
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; use validation::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
use core::cell::Ref; use core::cell::Ref;
use func::{FuncBody, FuncInstance, FuncRef}; use func::{FuncBody, FuncInstance, FuncRef};
use global::{GlobalInstance, GlobalRef}; use global::{GlobalInstance, GlobalRef};

View File

@ -6,8 +6,8 @@ use validation::func::{
}; };
use validation::util::Locals; use validation::util::Locals;
use validation::{Error, FunctionValidator}; use validation::{Error, FunctionValidator};
use validation::stack::StackWithLimit;
use common::stack::StackWithLimit;
use isa; use isa;
/// Type of block frame. /// Type of block frame.

View File

@ -1,6 +1,6 @@
#[allow(unused_imports)] #[allow(unused_imports)]
use alloc::prelude::*; use alloc::prelude::*;
use common::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX}; use validation::{DEFAULT_MEMORY_INDEX, DEFAULT_TABLE_INDEX};
use core::fmt; use core::fmt;
use core::ops; use core::ops;
use core::{u32, usize}; use core::{u32, usize};

View File

@ -6,7 +6,7 @@ edition = "2018"
[dependencies] [dependencies]
parity-wasm = { version = "0.31", default-features = false } parity-wasm = { version = "0.31", default-features = false }
memory_units = "0.3.0" memory_units_crate = { package = "memory_units", version = "0.3.0" }
[features] [features]
default = ["std"] default = ["std"]

View File

@ -30,6 +30,12 @@ use hashbrown::HashSet;
#[cfg(feature = "std")] #[cfg(feature = "std")]
use std::collections::HashSet; use std::collections::HashSet;
/// WebAssembly-specific sizes and units.
pub mod memory_units {
pub use memory_units_crate::wasm32::*;
pub use memory_units_crate::{size_of, ByteSize, Bytes, RoundUpTo};
}
use memory_units::Pages; use memory_units::Pages;
use self::context::ModuleContextBuilder; use self::context::ModuleContextBuilder;
@ -437,7 +443,7 @@ fn validate_memory_type(memory_type: &MemoryType) -> Result<(), Error> {
} }
/// Maximal number of pages that a wasm instance supports. /// Maximal number of pages that a wasm instance supports.
const LINEAR_MEMORY_MAX_PAGES: Pages = Pages(65536); pub const LINEAR_MEMORY_MAX_PAGES: Pages = Pages(65536);
pub fn validate_memory(initial: Pages, maximum: Option<Pages>) -> Result<(), String> { pub fn validate_memory(initial: Pages, maximum: Option<Pages>) -> Result<(), String> {
if initial > LINEAR_MEMORY_MAX_PAGES { if initial > LINEAR_MEMORY_MAX_PAGES {