diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/parser/src/conversion.rs | 6 | ||||
| -rw-r--r-- | crates/parser/src/lib.rs | 2 | ||||
| -rw-r--r-- | crates/parser/src/module.rs | 4 | ||||
| -rw-r--r-- | crates/tinywasm/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/tinywasm/src/func.rs | 6 | ||||
| -rw-r--r-- | crates/tinywasm/src/imports.rs | 2 | ||||
| -rw-r--r-- | crates/tinywasm/src/instance.rs | 5 | ||||
| -rw-r--r-- | crates/tinywasm/src/lib.rs | 6 | ||||
| -rw-r--r-- | crates/tinywasm/src/runtime/interpreter/mod.rs | 12 | ||||
| -rw-r--r-- | crates/tinywasm/src/runtime/interpreter/no_std_floats.rs | 77 | ||||
| -rw-r--r-- | crates/tinywasm/src/runtime/interpreter/traits.rs | 3 | ||||
| -rw-r--r-- | crates/tinywasm/src/runtime/stack/call_stack.rs | 1 | ||||
| -rw-r--r-- | crates/tinywasm/src/runtime/stack/value_stack.rs | 1 | ||||
| -rw-r--r-- | crates/tinywasm/src/store.rs | 8 | ||||
| -rw-r--r-- | crates/types/src/lib.rs | 17 |
15 files changed, 125 insertions, 26 deletions
diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs index 90dde8c..835842f 100644 --- a/crates/parser/src/conversion.rs +++ b/crates/parser/src/conversion.rs @@ -1,5 +1,5 @@ +use crate::log; use alloc::{boxed::Box, format, string::ToString, vec::Vec}; -use log::debug; use tinywasm_types::*; use wasmparser::{FuncValidator, OperatorsReader, ValidatorResources}; @@ -239,7 +239,7 @@ pub fn process_operators<'a>( let mut labels_ptrs = Vec::new(); // indexes into the instructions array for op in ops { - debug!("op: {:?}", op); + log::debug!("op: {:?}", op); let op = op?; validator.op(offset, &op)?; @@ -274,7 +274,7 @@ pub fn process_operators<'a>( } End => { if let Some(label_pointer) = labels_ptrs.pop() { - debug!("ending block: {:?}", instructions[label_pointer]); + log::debug!("ending block: {:?}", instructions[label_pointer]); let current_instr_ptr = instructions.len(); diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index aa76ea3..edcd280 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -14,7 +14,9 @@ use log; #[cfg(not(feature = "logging"))] mod log { macro_rules! debug ( ($($tt:tt)*) => {{}} ); + macro_rules! error ( ($($tt:tt)*) => {{}} ); pub(crate) use debug; + pub(crate) use error; } mod conversion; diff --git a/crates/parser/src/module.rs b/crates/parser/src/module.rs index 811c51f..e0fb0cc 100644 --- a/crates/parser/src/module.rs +++ b/crates/parser/src/module.rs @@ -181,9 +181,9 @@ impl ModuleReader { validator.end(offset)?; self.end_reached = true; } - CustomSection(reader) => { + CustomSection(_reader) => { debug!("Found custom section"); - debug!("Skipping custom section: {:?}", reader.name()); + debug!("Skipping custom section: {:?}", _reader.name()); } // TagSection(tag) => { // debug!("Found tag section"); diff --git a/crates/tinywasm/Cargo.toml b/crates/tinywasm/Cargo.toml index 9e336c8..f1a3242 100644 --- a/crates/tinywasm/Cargo.toml +++ b/crates/tinywasm/Cargo.toml @@ -16,6 +16,7 @@ path="src/lib.rs" log={version="0.4", optional=true} tinywasm-parser={version="0.3.0-alpha.0", path="../parser", default-features=false, optional=true} tinywasm-types={version="0.3.0-alpha.0", path="../types", default-features=false} +libm={version="0.2", default-features=false} [dev-dependencies] wasm-testsuite={path="../wasm-testsuite"} diff --git a/crates/tinywasm/src/func.rs b/crates/tinywasm/src/func.rs index 7a29e18..8433236 100644 --- a/crates/tinywasm/src/func.rs +++ b/crates/tinywasm/src/func.rs @@ -1,5 +1,5 @@ +use crate::log; use alloc::{boxed::Box, format, string::String, string::ToString, vec, vec::Vec}; -use log::{debug, info}; use tinywasm_types::{FuncAddr, FuncType, ValType, WasmValue}; use crate::{ @@ -34,7 +34,7 @@ impl FuncHandle { // 4. If the length of the provided argument values is different from the number of expected arguments, then fail if func_ty.params.len() != params.len() { - info!("func_ty.params: {:?}", func_ty.params); + log::info!("func_ty.params: {:?}", func_ty.params); return Err(Error::Other(format!( "param count mismatch: expected {}, got {}", func_ty.params.len(), @@ -62,7 +62,7 @@ impl FuncHandle { }; // 6. Let f be the dummy frame - debug!("locals: {:?}", locals); + log::debug!("locals: {:?}", locals); let call_frame = CallFrame::new(func_inst, params, locals); // 7. Push the frame f to the call stack diff --git a/crates/tinywasm/src/imports.rs b/crates/tinywasm/src/imports.rs index 0720d02..a640081 100644 --- a/crates/tinywasm/src/imports.rs +++ b/crates/tinywasm/src/imports.rs @@ -4,7 +4,7 @@ use core::fmt::Debug; use crate::{ func::{FromWasmValueTuple, IntoWasmValueTuple, ValTypesFromTuple}, - LinkingError, Result, + log, LinkingError, Result, }; use alloc::{ collections::BTreeMap, diff --git a/crates/tinywasm/src/instance.rs b/crates/tinywasm/src/instance.rs index 75d1f87..d750cd5 100644 --- a/crates/tinywasm/src/instance.rs +++ b/crates/tinywasm/src/instance.rs @@ -6,7 +6,7 @@ use tinywasm_types::{ use crate::{ func::{FromWasmValueTuple, IntoWasmValueTuple}, - Error, FuncHandle, FuncHandleTyped, Imports, Module, Result, Store, + log, Error, FuncHandle, FuncHandleTyped, Imports, Module, Result, Store, }; /// An instanciated WebAssembly module @@ -123,7 +123,8 @@ impl ModuleInstance { &self.0.func_addrs } - pub(crate) fn func_tys(&self) -> &[FuncType] { + /// Get the module's function types + pub fn func_tys(&self) -> &[FuncType] { &self.0.types } diff --git a/crates/tinywasm/src/lib.rs b/crates/tinywasm/src/lib.rs index 5388c05..36270a7 100644 --- a/crates/tinywasm/src/lib.rs +++ b/crates/tinywasm/src/lib.rs @@ -78,7 +78,13 @@ use log; #[cfg(not(feature = "logging"))] pub(crate) mod log { macro_rules! debug ( ($($tt:tt)*) => {{}} ); + macro_rules! info ( ($($tt:tt)*) => {{}} ); + macro_rules! trace ( ($($tt:tt)*) => {{}} ); + macro_rules! error ( ($($tt:tt)*) => {{}} ); pub(crate) use debug; + pub(crate) use error; + pub(crate) use info; + pub(crate) use trace; } mod error; diff --git a/crates/tinywasm/src/runtime/interpreter/mod.rs b/crates/tinywasm/src/runtime/interpreter/mod.rs index 48ce21d..db013a0 100644 --- a/crates/tinywasm/src/runtime/interpreter/mod.rs +++ b/crates/tinywasm/src/runtime/interpreter/mod.rs @@ -1,16 +1,24 @@ -use core::ops::{BitAnd, BitOr, BitXor, Neg}; - use super::{InterpreterRuntime, Stack}; +use crate::log; use crate::{ log::debug, runtime::{BlockType, CallFrame, LabelArgs, LabelFrame}, Error, FuncContext, ModuleInstance, Result, Store, Trap, }; use alloc::{string::ToString, vec::Vec}; +use core::ops::{BitAnd, BitOr, BitXor, Neg}; use tinywasm_types::{ElementKind, Instruction, ValType}; +#[cfg(not(feature = "std"))] +mod no_std_floats; + +#[cfg(not(feature = "std"))] +#[allow(unused_imports)] +use no_std_floats::FExt; + mod macros; mod traits; + use macros::*; use traits::*; diff --git a/crates/tinywasm/src/runtime/interpreter/no_std_floats.rs b/crates/tinywasm/src/runtime/interpreter/no_std_floats.rs new file mode 100644 index 0000000..095fe9f --- /dev/null +++ b/crates/tinywasm/src/runtime/interpreter/no_std_floats.rs @@ -0,0 +1,77 @@ +pub(super) trait FExt { + fn round(self) -> Self; + fn abs(self) -> Self; + fn signum(self) -> Self; + fn ceil(self) -> Self; + fn floor(self) -> Self; + fn trunc(self) -> Self; + fn sqrt(self) -> Self; + fn copysign(self, other: Self) -> Self; +} + +impl FExt for f64 { + fn round(self) -> Self { + libm::round(self) + } + + fn abs(self) -> Self { + libm::fabs(self) + } + + fn signum(self) -> Self { + libm::copysign(1.0, self) + } + + fn ceil(self) -> Self { + libm::ceil(self) + } + + fn floor(self) -> Self { + libm::floor(self) + } + + fn trunc(self) -> Self { + libm::trunc(self) + } + + fn sqrt(self) -> Self { + libm::sqrt(self) + } + + fn copysign(self, other: Self) -> Self { + libm::copysign(self, other) + } +} +impl FExt for f32 { + fn round(self) -> Self { + libm::roundf(self) + } + + fn abs(self) -> Self { + libm::fabsf(self) + } + + fn signum(self) -> Self { + libm::copysignf(1.0, self) + } + + fn ceil(self) -> Self { + libm::ceilf(self) + } + + fn floor(self) -> Self { + libm::floorf(self) + } + + fn trunc(self) -> Self { + libm::truncf(self) + } + + fn sqrt(self) -> Self { + libm::sqrtf(self) + } + + fn copysign(self, other: Self) -> Self { + libm::copysignf(self, other) + } +} diff --git a/crates/tinywasm/src/runtime/interpreter/traits.rs b/crates/tinywasm/src/runtime/interpreter/traits.rs index 06aab2a..06a97e3 100644 --- a/crates/tinywasm/src/runtime/interpreter/traits.rs +++ b/crates/tinywasm/src/runtime/interpreter/traits.rs @@ -11,6 +11,9 @@ pub(crate) trait WasmFloatOps { fn wasm_nearest(self) -> Self; } +#[cfg(not(feature = "std"))] +use super::no_std_floats::FExt; + macro_rules! impl_wasm_float_ops { ($($t:ty)*) => ($( impl WasmFloatOps for $t { diff --git a/crates/tinywasm/src/runtime/stack/call_stack.rs b/crates/tinywasm/src/runtime/stack/call_stack.rs index 098b918..20de728 100644 --- a/crates/tinywasm/src/runtime/stack/call_stack.rs +++ b/crates/tinywasm/src/runtime/stack/call_stack.rs @@ -1,3 +1,4 @@ +use crate::log; use crate::{ runtime::{BlockType, RawWasmValue}, Error, FunctionInstance, Result, Trap, diff --git a/crates/tinywasm/src/runtime/stack/value_stack.rs b/crates/tinywasm/src/runtime/stack/value_stack.rs index e4467da..bb4e398 100644 --- a/crates/tinywasm/src/runtime/stack/value_stack.rs +++ b/crates/tinywasm/src/runtime/stack/value_stack.rs @@ -1,5 +1,6 @@ use core::ops::Range; +use crate::log; use crate::{runtime::RawWasmValue, Error, Result}; use alloc::vec::Vec; use tinywasm_types::{ValType, WasmValue}; diff --git a/crates/tinywasm/src/store.rs b/crates/tinywasm/src/store.rs index 4d3e326..d281b5c 100644 --- a/crates/tinywasm/src/store.rs +++ b/crates/tinywasm/src/store.rs @@ -1,9 +1,9 @@ +use crate::log; +use alloc::{boxed::Box, format, rc::Rc, string::ToString, vec, vec::Vec}; use core::{ cell::RefCell, sync::atomic::{AtomicUsize, Ordering}, }; - -use alloc::{boxed::Box, format, rc::Rc, string::ToString, vec, vec::Vec}; use tinywasm_types::*; use crate::{ @@ -581,7 +581,7 @@ impl TableInstance { pub(crate) const PAGE_SIZE: usize = 65536; pub(crate) const MAX_PAGES: usize = 65536; -pub(crate) const MAX_SIZE: usize = PAGE_SIZE * MAX_PAGES; +pub(crate) const MAX_SIZE: u64 = PAGE_SIZE as u64 * MAX_PAGES as u64; /// A WebAssembly Memory Instance /// @@ -660,7 +660,7 @@ impl MemoryInstance { } let new_size = new_pages as usize * PAGE_SIZE; - if new_size > MAX_SIZE { + if new_size as u64 > MAX_SIZE { return None; } diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index a467d7a..d0d854c 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -11,16 +11,15 @@ extern crate alloc; // log for logging (optional). -// #[cfg(feature = "logging")] -// #[allow(unused_imports)] -// use log; +#[cfg(feature = "logging")] +use log; -// #[cfg(not(feature = "logging"))] -// #[macro_use] -// pub(crate) mod log { -// // macro_rules! debug ( ($($tt:tt)*) => {{}} ); -// // pub(crate) use debug; -// } +#[cfg(not(feature = "logging"))] +#[macro_use] +pub(crate) mod log { + macro_rules! error ( ($($tt:tt)*) => {{}} ); + pub(crate) use error; +} mod instructions; use core::{fmt::Debug, ops::Range}; |
