Skip to content

Commit

Permalink
Expose some more internals publicly (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimpo authored and pepyakin committed Oct 28, 2019
1 parent f27e0ad commit 71dd73d
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 173 deletions.
83 changes: 0 additions & 83 deletions misc/wasmtime-py/src/code_memory.rs

This file was deleted.

2 changes: 1 addition & 1 deletion misc/wasmtime-py/src/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ extern crate alloc;
use pyo3::prelude::*;
use pyo3::types::{PyAny, PyDict, PyTuple};

use crate::code_memory::CodeMemory;
use crate::function::Function;
use crate::memory::Memory;
use crate::value::{read_value_from, write_value_to};
Expand All @@ -18,6 +17,7 @@ use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext};
use cranelift_wasm::{DefinedFuncIndex, FuncIndex};
use target_lexicon::HOST;
use wasmtime_environ::{Export, Module};
use wasmtime_jit::CodeMemory;
use wasmtime_runtime::{Imports, InstanceHandle, VMContext, VMFunctionBody};

use alloc::rc::Rc;
Expand Down
1 change: 0 additions & 1 deletion misc/wasmtime-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use core::cell::RefCell;
use std::rc::Rc;
use wasmtime_interface_types::ModuleData;

mod code_memory;
mod function;
mod import;
mod instance;
Expand Down
83 changes: 0 additions & 83 deletions wasmtime-api/src/trampoline/code_memory.rs

This file was deleted.

2 changes: 1 addition & 1 deletion wasmtime-api/src/trampoline/func.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Support for a calling of an imported function.

use crate::r#ref::HostRef;
use crate::trampoline::code_memory::CodeMemory;
use cranelift_codegen::ir::types;
use cranelift_codegen::ir::{InstBuilder, StackSlotData, StackSlotKind, TrapCode};
use cranelift_codegen::Context;
Expand All @@ -12,6 +11,7 @@ use cranelift_wasm::{DefinedFuncIndex, FuncIndex};
//use target_lexicon::HOST;
use failure::Error;
use wasmtime_environ::{Export, Module};
use wasmtime_jit::CodeMemory;
use wasmtime_runtime::{InstanceHandle, VMContext, VMFunctionBody};

use alloc::boxed::Box;
Expand Down
1 change: 0 additions & 1 deletion wasmtime-api/src/trampoline/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! Utility module to create trampolines in/out WebAssembly module.

mod code_memory;
mod create_handle;
mod func;
mod global;
Expand Down
2 changes: 1 addition & 1 deletion wasmtime-jit/src/code_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use region;
use wasmtime_runtime::{Mmap, VMFunctionBody};

/// Memory manager for executable code.
pub(crate) struct CodeMemory {
pub struct CodeMemory {
current: Mmap,
mmaps: Vec<Mmap>,
position: usize,
Expand Down
18 changes: 16 additions & 2 deletions wasmtime-jit/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::action::{get, inspect_memory, invoke};
use crate::HashMap;
use crate::{
instantiate, ActionError, ActionOutcome, CompilationStrategy, Compiler, InstanceHandle,
Namespace, RuntimeValue, SetupError,
instantiate, ActionError, ActionOutcome, CompilationStrategy, CompiledModule, Compiler,
InstanceHandle, Namespace, RuntimeValue, SetupError,
};
use alloc::boxed::Box;
use alloc::rc::Rc;
Expand Down Expand Up @@ -160,6 +160,20 @@ impl Context {
Ok(instance)
}

/// Compile a module.
pub fn compile_module(&mut self, data: &[u8]) -> Result<CompiledModule, SetupError> {
self.validate(&data).map_err(SetupError::Validate)?;
let debug_info = self.debug_info();

CompiledModule::new(
&mut *self.compiler,
data,
&mut self.namespace,
Rc::clone(&self.global_exports),
debug_info,
)
}

/// If `name` isn't None, register it for the given instance.
pub fn optionally_name_instance(&mut self, name: Option<String>, instance: InstanceHandle) {
if let Some(name) = name {
Expand Down
10 changes: 10 additions & 0 deletions wasmtime-jit/src/instantiate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ impl CompiledModule {
Box::new(()),
)
}

/// Return a reference-counting pointer to a module.
pub fn module(&self) -> Rc<Module> {
self.module.clone()
}

/// Return a reference to a module.
pub fn module_ref(&self) -> &Module {
&self.module
}
}

/// Similar to `DataInitializer`, but owns its own copy of the data rather
Expand Down
1 change: 1 addition & 0 deletions wasmtime-jit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ mod resolver;
mod target_tunables;

pub use crate::action::{ActionError, ActionOutcome, RuntimeValue};
pub use crate::code_memory::CodeMemory;
pub use crate::compiler::{CompilationStrategy, Compiler};
pub use crate::context::{Context, ContextError, Features, UnknownInstance};
pub use crate::instantiate::{instantiate, CompiledModule, SetupError};
Expand Down

0 comments on commit 71dd73d

Please sign in to comment.