cranelift-module: add iterator methods to ModuleDeclarations

The predecessor interface made it possible to iterate across all
function and data declarations. This is still useful and easy enough to
provide.
This commit is contained in:
Pat Hickey
2020-10-07 20:06:58 -07:00
parent b061694491
commit 13c6bdd9ba

View File

@@ -210,6 +210,11 @@ impl ModuleDeclarations {
self.names.get(name).copied() self.names.get(name).copied()
} }
/// Get an iterator of all function declarations
pub fn get_functions(&self) -> impl Iterator<Item = (FuncId, &FunctionDeclaration)> {
self.functions.iter()
}
/// Get the `FuncId` for the function named by `name`. /// Get the `FuncId` for the function named by `name`.
pub fn get_function_id(&self, name: &ir::ExternalName) -> FuncId { pub fn get_function_id(&self, name: &ir::ExternalName) -> FuncId {
if let ir::ExternalName::User { namespace, index } = *name { if let ir::ExternalName::User { namespace, index } = *name {
@@ -235,6 +240,11 @@ impl ModuleDeclarations {
&self.functions[func_id] &self.functions[func_id]
} }
/// Get an iterator of all data declarations
pub fn get_data_objects(&self) -> impl Iterator<Item = (DataId, &DataDeclaration)> {
self.data_objects.iter()
}
/// Get the `DataDeclaration` for the data object named by `name`. /// Get the `DataDeclaration` for the data object named by `name`.
pub fn get_data_decl(&self, data_id: DataId) -> &DataDeclaration { pub fn get_data_decl(&self, data_id: DataId) -> &DataDeclaration {
&self.data_objects[data_id] &self.data_objects[data_id]