From 13c6bdd9bab2e8aaacad420a2f90b87624b8e6f3 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Wed, 7 Oct 2020 20:06:58 -0700 Subject: [PATCH] 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. --- cranelift/module/src/module.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cranelift/module/src/module.rs b/cranelift/module/src/module.rs index 26704ae5e5..58ddb2aa76 100644 --- a/cranelift/module/src/module.rs +++ b/cranelift/module/src/module.rs @@ -210,6 +210,11 @@ impl ModuleDeclarations { self.names.get(name).copied() } + /// Get an iterator of all function declarations + pub fn get_functions(&self) -> impl Iterator { + self.functions.iter() + } + /// Get the `FuncId` for the function named by `name`. pub fn get_function_id(&self, name: &ir::ExternalName) -> FuncId { if let ir::ExternalName::User { namespace, index } = *name { @@ -235,6 +240,11 @@ impl ModuleDeclarations { &self.functions[func_id] } + /// Get an iterator of all data declarations + pub fn get_data_objects(&self) -> impl Iterator { + self.data_objects.iter() + } + /// Get the `DataDeclaration` for the data object named by `name`. pub fn get_data_decl(&self, data_id: DataId) -> &DataDeclaration { &self.data_objects[data_id]