mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-23 13:41:32 +00:00
merge and respond to feedback
This commit is contained in:
@ -14,6 +14,8 @@ use crate::{
|
||||
};
|
||||
use std::{any::Any, ptr::NonNull};
|
||||
|
||||
use hashbrown::HashMap;
|
||||
|
||||
pub mod sys {
|
||||
pub use crate::sys::*;
|
||||
}
|
||||
@ -38,11 +40,28 @@ impl Token {
|
||||
}
|
||||
}
|
||||
|
||||
/// Configuration data for the compiler
|
||||
pub struct CompilerConfig {
|
||||
/// Symbol information generated from emscripten; used for more detailed debug messages
|
||||
pub symbol_map: Option<HashMap<u32, String>>,
|
||||
}
|
||||
|
||||
impl Default for CompilerConfig {
|
||||
fn default() -> CompilerConfig {
|
||||
CompilerConfig { symbol_map: None }
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Compiler {
|
||||
/// Compiles a `Module` from WebAssembly binary format.
|
||||
/// The `CompileToken` parameter ensures that this can only
|
||||
/// be called from inside the runtime.
|
||||
fn compile(&self, wasm: &[u8], _: Token) -> CompileResult<ModuleInner>;
|
||||
fn compile(
|
||||
&self,
|
||||
wasm: &[u8],
|
||||
comp_conf: CompilerConfig,
|
||||
_: Token,
|
||||
) -> CompileResult<ModuleInner>;
|
||||
|
||||
unsafe fn from_cache(&self, cache: Artifact, _: Token) -> Result<ModuleInner, CacheError>;
|
||||
}
|
||||
|
@ -67,13 +67,26 @@ pub fn compile_with(
|
||||
compiler: &dyn backend::Compiler,
|
||||
) -> CompileResult<module::Module> {
|
||||
let token = backend::Token::generate();
|
||||
compiler.compile(wasm, token).map(|mut inner| {
|
||||
compiler.compile(wasm, Default::default(), token).map(|mut inner| {
|
||||
let inner_info: &mut crate::module::ModuleInfo = &mut inner.info;
|
||||
inner_info.import_custom_sections(wasm).unwrap();
|
||||
module::Module::new(Arc::new(inner))
|
||||
})
|
||||
}
|
||||
|
||||
/// The same as `compile_with` but changes the compiler behavior
|
||||
/// with the values in the `CompilerConfig`
|
||||
pub fn compile_with_config(
|
||||
wasm: &[u8],
|
||||
compiler: &dyn backend::Compiler,
|
||||
compiler_config: backend::CompilerConfig,
|
||||
) -> CompileResult<module::Module> {
|
||||
let token = backend::Token::generate();
|
||||
compiler
|
||||
.compile(wasm, compiler_config, token)
|
||||
.map(|inner| module::Module::new(Arc::new(inner)))
|
||||
}
|
||||
|
||||
/// Perform validation as defined by the
|
||||
/// WebAssembly specification. Returns `true` if validation
|
||||
/// succeeded, `false` if validation failed.
|
||||
|
@ -57,6 +57,9 @@ pub struct ModuleInfo {
|
||||
pub namespace_table: StringTable<NamespaceIndex>,
|
||||
pub name_table: StringTable<NameIndex>,
|
||||
|
||||
/// Symbol information from emscripten
|
||||
pub em_symbol_map: Option<HashMap<u32, String>>,
|
||||
|
||||
pub custom_sections: HashMap<String, Vec<u8>>,
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,8 @@ use crate::{
|
||||
};
|
||||
use std::{ffi::c_void, mem, ptr};
|
||||
|
||||
use hashbrown::HashMap;
|
||||
|
||||
/// The context of the currently running WebAssembly instance.
|
||||
///
|
||||
///
|
||||
@ -156,6 +158,11 @@ impl Ctx {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Gives access to the emscripten symbol map, used for debugging
|
||||
pub unsafe fn borrow_symbol_map(&self) -> &Option<HashMap<u32, String>> {
|
||||
&(*self.module).info.em_symbol_map
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
@ -609,6 +616,8 @@ mod vm_ctx_tests {
|
||||
namespace_table: StringTable::new(),
|
||||
name_table: StringTable::new(),
|
||||
|
||||
em_symbol_map: None,
|
||||
|
||||
custom_sections: HashMap::new(),
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user