Skip to content

Commit

Permalink
Expose some Module APIs that measure various lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Mar 1, 2024
1 parent 0ed3f3d commit 1c05edd
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions crates/wasmi/src/module/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,22 +179,46 @@ impl Module {
}
}

/// Returns the number of func types of the [`Module`].
pub fn len_types(&self) -> usize {
self.func_types.len()
}
/// Returns the number of non-imported functions of the [`Module`].
pub(crate) fn len_funcs(&self) -> usize {
pub fn len_funcs(&self) -> usize {
self.funcs.len()
}
/// Returns the number of non-imported tables of the [`Module`].
pub(crate) fn len_tables(&self) -> usize {
pub fn len_tables(&self) -> usize {
self.tables.len()
}
/// Returns the sum of the minimum sizes of non-imported tables of the [`Module`].
pub fn len_table_entries(&self) -> usize {
self.tables.iter().map(|t| t.minimum() as usize).sum()
}
/// Returns the number of non-imported linear memories of the [`Module`].
pub(crate) fn len_memories(&self) -> usize {
pub fn len_memories(&self) -> usize {
self.memories.len()
}
/// Returns the number of non-imported global variables of the [`Module`].
pub(crate) fn len_globals(&self) -> usize {
pub fn len_globals(&self) -> usize {
self.globals.len()
}
/// Returns the number of data segments in the [`Module`].
pub fn len_data_segments(&self) -> usize {
self.globals.len()
}
/// Returns the number of element segments in the [`Module`].
pub fn len_element_segments(&self) -> usize {
self.globals.len()
}
/// Returns the number of imports in the [`Module`].
pub fn len_imports(&self) -> usize {
self.imports.items.len()
}
/// Returns the number of exports in the [`Module`].
pub fn len_exports(&self) -> usize {
self.exports.len()
}

/// Returns a slice to the function types of the [`Module`].
///
Expand Down

0 comments on commit 1c05edd

Please sign in to comment.