Use embedded API in the wasmtime-rust (#540)

This commit is contained in:
Yury Delendik
2019-11-13 09:15:37 -06:00
committed by Alex Crichton
parent 2737c5e8e5
commit 98266498af
13 changed files with 316 additions and 112 deletions

View File

@@ -170,10 +170,16 @@ fn read_imports_and_exports(binary: &[u8]) -> Result<(Box<[ImportType]>, Box<[Ex
Ok((imports.into_boxed_slice(), exports.into_boxed_slice()))
}
#[derive(Clone)]
pub(crate) enum ModuleCodeSource {
Binary(Box<[u8]>),
Unknown,
}
#[derive(Clone)]
pub struct Module {
store: HostRef<Store>,
binary: Box<[u8]>,
source: ModuleCodeSource,
imports: Box<[ImportType]>,
exports: Box<[ExportType]>,
}
@@ -183,13 +189,16 @@ impl Module {
let (imports, exports) = read_imports_and_exports(binary)?;
Ok(Module {
store: store.clone(),
binary: binary.into(),
source: ModuleCodeSource::Binary(binary.into()),
imports,
exports,
})
}
pub(crate) fn binary(&self) -> &[u8] {
&self.binary
pub(crate) fn binary(&self) -> Option<&[u8]> {
match &self.source {
ModuleCodeSource::Binary(b) => Some(b),
_ => None,
}
}
pub fn validate(_store: &Store, binary: &[u8]) -> bool {
validate(binary, None).is_ok()
@@ -200,4 +209,12 @@ impl Module {
pub fn exports(&self) -> &[ExportType] {
&self.exports
}
pub fn from_exports(store: &HostRef<Store>, exports: Box<[ExportType]>) -> Self {
Module {
store: store.clone(),
source: ModuleCodeSource::Unknown,
imports: Box::new([]),
exports,
}
}
}