Skip to content

Commit

Permalink
Merge pull request #11 from wasmerio/engine
Browse files Browse the repository at this point in the history
Engine
  • Loading branch information
syrusakbary authored May 5, 2020
2 parents a945b43 + 60e8350 commit f54735e
Show file tree
Hide file tree
Showing 38 changed files with 406 additions and 191 deletions.
36 changes: 33 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ wasmer-compiler = { version = "0.16.2", path = "lib/compiler" }
wasmer-compiler-cranelift = { version = "0.16.2", path = "lib/compiler-cranelift", optional = true }
wasmer-compiler-singlepass = { version = "0.16.2", path = "lib/compiler-singlepass", optional = true }
wasmer-compiler-llvm = { version = "0.16.2", path = "lib/compiler-llvm", optional = true }
wasmer-jit = { version = "0.16.2", path = "lib/jit" }
wasmer-engine = { version = "0.16.2", path = "lib/engine" }
wasmer-engine-jit = { version = "0.16.2", path = "lib/engine-jit", optional = true }
wasmer-wasi = { version = "0.16.2", path = "lib/wasi", optional = true }
wasmer-wasi-experimental-io-devices = { version = "0.16.2", path = "lib/wasi-experimental-io-devices", optional = true }
wasmer-wast = { version = "0.16.2", path = "tests/lib/wast", optional = true }
Expand Down Expand Up @@ -55,12 +56,17 @@ test-utils = { path = "tests/lib/test-utils" }
[features]
# Don't add the compiler features in default, please add them on the Makefile
# since we might want to autoconfigure them depending on the availability on the host.
default = ["wat", "wast", "wasi", "cranelift", "cache"]
default = ["wat", "wast", "wasi", "cranelift", "cache", "jit"]
engine = []
jit = [
"wasmer-engine-jit",
"engine",
]
cache = ["wasmer-cache"]
wast = ["wasmer-wast"]
wasi = ["wasmer-wasi"]
wat = ["wasmer/wat"]
compiler = ["wasmer-jit/compiler"]
compiler = ["wasmer-engine-jit/compiler",]
experimental-io-devices = [
"wasmer-wasi-experimental-io-devices",
"wasi"
Expand Down
9 changes: 6 additions & 3 deletions lib/api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ wasmer-compiler-singlepass = { path = "../compiler-singlepass", version = "0.16.
wasmer-compiler-cranelift = { path = "../compiler-cranelift", version = "0.16.2", optional = true }
wasmer-compiler-llvm = { path = "../compiler-llvm", version = "0.16.2", optional = true }
wasmer-compiler = { path = "../compiler", version = "0.16.2" }
wasmer-jit = { path = "../jit", version = "0.16.2" }
wasmer-engine = { path = "../engine", version = "0.16.2" }
wasmer-engine-jit = { path = "../engine-jit", version = "0.16.2", optional = true }
wasm-common = { path = "../wasm-common", version = "0.16.2" }
indexmap = { version = "1.3.2", features = ["serde-1"] }
cfg-if = "0.1.10"
Expand All @@ -37,8 +38,10 @@ anyhow = "1.0.28"
maintenance = { status = "actively-developed" }

[features]
default = ["wat", "cranelift"]
compiler = ["wasmer-jit/compiler"]
default = ["wat", "cranelift", "jit"]
compiler = ["wasmer-engine-jit/compiler"]
engine = []
jit = ["wasmer-engine-jit"]
singlepass = [
"wasmer-compiler-singlepass",
"compiler",
Expand Down
1 change: 1 addition & 0 deletions lib/api/src/externals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{ExternType, FunctionType, GlobalType, MemoryType, TableType, ValType
use std::cmp::max;
use std::slice;
use wasm_common::{Bytes, HostFunction, Pages, ValueType, WasmTypeList, WithEnv, WithoutEnv};
use wasmer_engine::Engine as _;
use wasmer_runtime::{
wasmer_call_trampoline, Export, ExportFunction, ExportGlobal, ExportMemory, ExportTable,
LinearMemory, Table as RuntimeTable, VMCallerCheckedAnyfunc, VMContext, VMFunctionBody,
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/import_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
ffi::c_void,
sync::{Arc, Mutex},
};
use wasmer_jit::Resolver;
use wasmer_engine::Resolver;
use wasmer_runtime::Export;

/// The `LikeNamespace` trait represents objects that act as a namespace for imports.
Expand Down
2 changes: 1 addition & 1 deletion lib/api/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::externals::Extern;
use crate::module::Module;
use crate::store::Store;
use crate::InstantiationError;
use wasmer_jit::Resolver;
use wasmer_engine::Resolver;
use wasmer_runtime::InstanceHandle;

/// A WebAssembly Instance is a stateful, executable
Expand Down
10 changes: 6 additions & 4 deletions lib/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use crate::instance::Instance;
pub use crate::memory_view::MemoryView;
pub use crate::module::Module;
pub use crate::ptr::{Array, Item, WasmPtr};
pub use crate::store::{Engine, Store, StoreObject};
pub use crate::store::{Store, StoreObject};
pub use crate::tunables::Tunables;
pub use crate::types::{
AnyRef, ExportType, ExternType, FunctionType, GlobalType, HostInfo, HostRef, ImportType,
Expand All @@ -30,9 +30,8 @@ pub use wasm_common::{ValueType, WasmExternType, WasmTypeList};
#[cfg(feature = "compiler")]
pub use wasmer_compiler::CompilerConfig;
pub use wasmer_compiler::{Features, Target};

pub use wasmer_jit::{
DeserializeError, InstantiationError, LinkError, RuntimeError, SerializeError,
pub use wasmer_engine::{
DeserializeError, Engine, InstantiationError, LinkError, RuntimeError, SerializeError,
};

// The compilers are mutually exclusive
Expand Down Expand Up @@ -62,5 +61,8 @@ pub use wasmer_compiler_cranelift::CraneliftConfig;
#[cfg(feature = "llvm")]
pub use wasmer_compiler_llvm::LLVMConfig;

#[cfg(feature = "jit")]
pub use wasmer_engine_jit::JITEngine;

/// Version number of this crate.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
18 changes: 11 additions & 7 deletions lib/api/src/module.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use crate::store::Store;
use crate::types::{ExportType, ImportType};
use crate::InstantiationError;
use std::borrow::Borrow;
use std::io;
use std::path::Path;
use std::sync::Arc;
use thiserror::Error;
use wasmer_compiler::{CompileError, WasmError};
use wasmer_jit::{CompiledModule, DeserializeError, Resolver, SerializeError};
use wasmer_engine::{CompiledModule, DeserializeError, Engine, Resolver, SerializeError};
use wasmer_runtime::{ExportsIterator, ImportsIterator, InstanceHandle, Module as ModuleInfo};

#[derive(Error, Debug)]
Expand All @@ -30,7 +31,7 @@ pub enum IoCompileError {
#[derive(Clone)]
pub struct Module {
store: Store,
compiled: Arc<CompiledModule>,
compiled: Arc<dyn CompiledModule>,

#[cfg(feature = "wat")]
#[doc(hidden)]
Expand Down Expand Up @@ -155,7 +156,7 @@ impl Module {
/// let serialized = module.serialize()?;
/// ```
pub fn serialize(&self) -> Result<Vec<u8>, SerializeError> {
self.store.engine().serialize(&self.compiled)
self.store.engine().serialize(self.compiled.borrow())
}

/// Deserializes a a serialized Module binary into a `Module`.
Expand Down Expand Up @@ -183,10 +184,10 @@ impl Module {
Ok(Self::from_compiled_module(store, compiled))
}

fn from_compiled_module(store: &Store, compiled: CompiledModule) -> Self {
fn from_compiled_module(store: &Store, compiled: Arc<CompiledModule>) -> Self {
Module {
store: store.clone(),
compiled: Arc::new(compiled),
compiled,
#[cfg(feature = "wat")]
from_wat: false,
}
Expand All @@ -197,7 +198,10 @@ impl Module {
resolver: &dyn Resolver,
) -> Result<InstanceHandle, InstantiationError> {
unsafe {
let instance_handle = self.store.engine().instantiate(&self.compiled, resolver)?;
let instance_handle = self
.store
.engine()
.instantiate(self.compiled.borrow(), resolver)?;

// After the instance handle is created, we need to initialize
// the data, call the start function and so. However, if any
Expand Down Expand Up @@ -240,7 +244,7 @@ impl Module {
/// ```
pub fn set_name(&mut self, name: &str) {
let compiled = Arc::get_mut(&mut self.compiled).unwrap();
Arc::get_mut(compiled.module_mut()).unwrap().name = Some(name.to_string());
compiled.module_mut().name = Some(name.to_string());
}

/// Returns an iterator over the imported types in the Module.
Expand Down
37 changes: 19 additions & 18 deletions lib/api/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,25 @@ use crate::tunables::Tunables;
use std::sync::Arc;
#[cfg(feature = "compiler")]
use wasmer_compiler::CompilerConfig;
use wasmer_jit::JITEngine;

pub type Engine = JITEngine;
use wasmer_engine::Engine;

#[derive(Clone)]
pub struct Store {
engine: Arc<Engine>,
engine: Arc<dyn Engine>,
}

impl Store {
pub fn new(engine: &Engine) -> Store {
Store {
engine: Arc::new(engine.clone()),
}
pub fn new(engine: Arc<dyn Engine>) -> Store {
Store { engine }
}

pub fn engine(&self) -> &Engine {
pub fn engine(&self) -> &Arc<dyn Engine> {
&self.engine
}

pub fn same(a: &Store, b: &Store) -> bool {
Arc::ptr_eq(&a.engine, &b.engine)
}

#[cfg(feature = "compiler")]
fn new_config(config: Box<dyn CompilerConfig>) -> Self {
let tunables = Tunables::for_target(config.target().triple());
Self::new(&Engine::new(&*config, tunables))
}
}

impl PartialEq for Store {
Expand All @@ -39,8 +29,8 @@ impl PartialEq for Store {
}
}

// We only implement default if we have assigned a default compiler
#[cfg(feature = "compiler")]
// We only implement default if we have assigned a default compiler and engine
#[cfg(all(feature = "compiler", feature = "engine"))]
impl Default for Store {
fn default() -> Store {
// We store them on a function that returns to make
Expand All @@ -57,7 +47,18 @@ impl Default for Store {
#[cfg(feature = "singlepass")]
return Box::new(wasmer_compiler_singlepass::SinglepassConfig::default());
}
Store::new_config(get_config())

#[allow(unreachable_code)]
fn get_engine(config: Box<dyn CompilerConfig>) -> Arc<dyn Engine> {
let tunables = Tunables::for_target(config.target().triple());

#[cfg(feature = "jit")]
return Arc::new(wasmer_engine_jit::JITEngine::new(&config, tunables));
}

let config = get_config();
let engine = get_engine(config);
Store::new(config)
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/api/src/tunables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use more_asserts::assert_ge;
use std::cmp::min;
use target_lexicon::{OperatingSystem, PointerWidth, Triple, HOST};
use wasm_common::{MemoryType, Pages, TableType};
use wasmer_engine::Tunables as BaseTunables;
use wasmer_runtime::{LinearMemory, Table};
use wasmer_runtime::{MemoryPlan, MemoryStyle, TablePlan, TableStyle};

Expand Down Expand Up @@ -57,7 +58,7 @@ impl Tunables {
}
}

impl wasmer_jit::Tunables for Tunables {
impl BaseTunables for Tunables {
/// Get a `MemoryPlan` for the provided `MemoryType`
fn memory_plan(&self, memory: MemoryType) -> MemoryPlan {
// A heap with a maximum that doesn't exceed the static memory bound specified by the
Expand Down
2 changes: 1 addition & 1 deletion lib/cache/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ keywords = ["webassembly", "wasm", "cache"]
edition = "2018"

[dependencies]
wasmer = { path = "../api", version = "0.16.2" }
wasmer = { path = "../api", version = "0.16.2", default-features = false }
memmap = "0.7"
hex = "0.4"
thiserror = "1"
Expand Down
5 changes: 3 additions & 2 deletions lib/jit/Cargo.toml → lib/engine-jit/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[package]
name = "wasmer-jit"
name = "wasmer-engine-jit"
version = "0.16.2"
authors = ["Wasmer Engineering Team <[email protected]>"]
description = "Wasmer JIT frontend"
description = "Wasmer JIT Engine"
license = "(Apache-2.0 WITH LLVM-exception) or MIT"
categories = ["wasm"]
keywords = ["webassembly", "wasm"]
Expand All @@ -14,6 +14,7 @@ edition = "2018"
wasm-common = { path = "../wasm-common", version = "0.16.2" }
wasmer-compiler = { path = "../compiler", version = "0.16.2", default-features = false }
wasmer-runtime = { path = "../runtime", version = "0.16.2" }
wasmer-engine = { path = "../engine", version = "0.16.2" }
target-lexicon = { version = "0.10.0", default-features = false }
# flexbuffers = { path = "../../../flatbuffers/rust/flexbuffers", version = "0.1.0" }
backtrace = "0.3.46"
Expand Down
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit f54735e

Please sign in to comment.