mirror of
https://github.com/fluencelabs/wasmer
synced 2025-07-02 10:01:33 +00:00
Deny missing docs in runtime core and add missing docs
This commit is contained in:
@ -1,3 +1,5 @@
|
||||
//! The module module contains the implementation data structures and helper functions used to
|
||||
//! manipulate and access wasm modules.
|
||||
use crate::{
|
||||
backend::{Backend, RunnableModule},
|
||||
cache::{Artifact, Error as CacheError},
|
||||
@ -27,40 +29,59 @@ pub struct ModuleInner {
|
||||
pub info: ModuleInfo,
|
||||
}
|
||||
|
||||
/// Container for module data including memories, globals, tables, imports, and exports.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct ModuleInfo {
|
||||
/// Map of memory index to memory descriptors.
|
||||
// This are strictly local and the typesystem ensures that.
|
||||
pub memories: Map<LocalMemoryIndex, MemoryDescriptor>,
|
||||
/// Map of global index to global descriptors.
|
||||
pub globals: Map<LocalGlobalIndex, GlobalInit>,
|
||||
/// Map of table index to table descriptors.
|
||||
pub tables: Map<LocalTableIndex, TableDescriptor>,
|
||||
|
||||
/// Map of imported function index to import name.
|
||||
// These are strictly imported and the typesystem ensures that.
|
||||
pub imported_functions: Map<ImportedFuncIndex, ImportName>,
|
||||
/// Map of imported memory index to import name and memory descriptor.
|
||||
pub imported_memories: Map<ImportedMemoryIndex, (ImportName, MemoryDescriptor)>,
|
||||
/// Map of imported table index to import name and table descriptor.
|
||||
pub imported_tables: Map<ImportedTableIndex, (ImportName, TableDescriptor)>,
|
||||
/// Map of imported global index to import name and global descriptor.
|
||||
pub imported_globals: Map<ImportedGlobalIndex, (ImportName, GlobalDescriptor)>,
|
||||
|
||||
/// Map of string to export index.
|
||||
pub exports: IndexMap<String, ExportIndex>,
|
||||
|
||||
/// Vector of data initializers.
|
||||
pub data_initializers: Vec<DataInitializer>,
|
||||
/// Vector of table initializers.
|
||||
pub elem_initializers: Vec<TableInitializer>,
|
||||
|
||||
/// Index of optional start function.
|
||||
pub start_func: Option<FuncIndex>,
|
||||
|
||||
/// Map function index to signature index.
|
||||
pub func_assoc: Map<FuncIndex, SigIndex>,
|
||||
/// Map signature index to function signature.
|
||||
pub signatures: Map<SigIndex, FuncSig>,
|
||||
/// Backend.
|
||||
pub backend: Backend,
|
||||
|
||||
/// Table of namespace indexes.
|
||||
pub namespace_table: StringTable<NamespaceIndex>,
|
||||
/// Table of name indexes.
|
||||
pub name_table: StringTable<NameIndex>,
|
||||
|
||||
/// Symbol information from emscripten
|
||||
/// Symbol information from emscripten.
|
||||
pub em_symbol_map: Option<HashMap<u32, String>>,
|
||||
|
||||
/// Custom sections.
|
||||
pub custom_sections: HashMap<String, Vec<u8>>,
|
||||
}
|
||||
|
||||
impl ModuleInfo {
|
||||
/// Creates custom section info from the given wasm file.
|
||||
pub fn import_custom_sections(&mut self, wasm: &[u8]) -> crate::error::ParseResult<()> {
|
||||
let mut parser = wasmparser::ModuleReader::new(wasm)?;
|
||||
while !parser.eof() {
|
||||
@ -120,6 +141,7 @@ impl Module {
|
||||
Instance::new(Arc::clone(&self.inner), import_object)
|
||||
}
|
||||
|
||||
/// Create a cache artifact from this module.
|
||||
pub fn cache(&self) -> Result<Artifact, CacheError> {
|
||||
let (backend_metadata, code) = self.inner.cache_gen.generate_cache()?;
|
||||
Ok(Artifact::from_parts(
|
||||
@ -129,6 +151,7 @@ impl Module {
|
||||
))
|
||||
}
|
||||
|
||||
/// Get the module data for this module.
|
||||
pub fn info(&self) -> &ModuleInfo {
|
||||
&self.inner.info
|
||||
}
|
||||
@ -151,11 +174,16 @@ pub struct ImportName {
|
||||
pub name_index: NameIndex,
|
||||
}
|
||||
|
||||
/// Kinds of export indexes.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum ExportIndex {
|
||||
/// Function export index.
|
||||
Func(FuncIndex),
|
||||
/// Memory export index.
|
||||
Memory(MemoryIndex),
|
||||
/// Global export index.
|
||||
Global(GlobalIndex),
|
||||
/// Table export index.
|
||||
Table(TableIndex),
|
||||
}
|
||||
|
||||
@ -182,6 +210,7 @@ pub struct TableInitializer {
|
||||
pub elements: Vec<FuncIndex>,
|
||||
}
|
||||
|
||||
/// String table builder.
|
||||
pub struct StringTableBuilder<K: TypedIndex> {
|
||||
map: IndexMap<String, (K, u32, u32)>,
|
||||
buffer: String,
|
||||
@ -189,6 +218,7 @@ pub struct StringTableBuilder<K: TypedIndex> {
|
||||
}
|
||||
|
||||
impl<K: TypedIndex> StringTableBuilder<K> {
|
||||
/// Creates a new `StringTableBuilder`.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
map: IndexMap::new(),
|
||||
@ -197,6 +227,7 @@ impl<K: TypedIndex> StringTableBuilder<K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Register a new string into table.
|
||||
pub fn register<S>(&mut self, s: S) -> K
|
||||
where
|
||||
S: Into<String> + AsRef<str>,
|
||||
@ -219,6 +250,7 @@ impl<K: TypedIndex> StringTableBuilder<K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Finish building the `StringTable`.
|
||||
pub fn finish(self) -> StringTable<K> {
|
||||
let table = self
|
||||
.map
|
||||
@ -233,6 +265,7 @@ impl<K: TypedIndex> StringTableBuilder<K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// A map of index to string.
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct StringTable<K: TypedIndex> {
|
||||
table: Map<K, (u32, u32)>,
|
||||
@ -240,6 +273,7 @@ pub struct StringTable<K: TypedIndex> {
|
||||
}
|
||||
|
||||
impl<K: TypedIndex> StringTable<K> {
|
||||
/// Creates a `StringTable`.
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
table: Map::new(),
|
||||
@ -247,6 +281,7 @@ impl<K: TypedIndex> StringTable<K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets a reference to a string at the given index.
|
||||
pub fn get(&self, index: K) -> &str {
|
||||
let (offset, length) = self.table[index];
|
||||
let offset = offset as usize;
|
||||
@ -256,6 +291,7 @@ impl<K: TypedIndex> StringTable<K> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Namespace index.
|
||||
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NamespaceIndex(u32);
|
||||
|
||||
@ -271,6 +307,7 @@ impl TypedIndex for NamespaceIndex {
|
||||
}
|
||||
}
|
||||
|
||||
/// Name index.
|
||||
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct NameIndex(u32);
|
||||
|
||||
|
Reference in New Issue
Block a user