Expose some more internals publicly (#340)

This commit is contained in:
Jim Posen
2019-10-28 18:12:11 +01:00
committed by Sergei Pepyakin
parent f27e0ad53c
commit 71dd73d672
10 changed files with 30 additions and 173 deletions

View File

@@ -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,

View File

@@ -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;
@@ -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 {

View File

@@ -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

View File

@@ -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};