llvm_ir_analysis/
functions_by_type.rs1use llvm_ir::{Module, TypeRef};
2use std::collections::{HashMap, HashSet};
3
4pub struct FunctionsByType<'m> {
10 map: HashMap<TypeRef, HashSet<&'m str>>,
11}
12
13impl<'m> FunctionsByType<'m> {
14 pub(crate) fn new(modules: impl IntoIterator<Item = &'m Module>) -> Self {
15 let mut map: HashMap<TypeRef, HashSet<&'m str>> = HashMap::new();
16 for module in modules {
17 for func in &module.functions {
18 map.entry(module.type_of(func))
19 .or_default()
20 .insert(&func.name);
21 }
22 }
23 Self { map }
24 }
25
26 pub fn functions_with_type<'s>(&'s self, ty: &TypeRef) -> impl Iterator<Item = &'m str> + 's {
29 self.map
30 .get(ty)
31 .into_iter()
32 .map(|hs| hs.iter().copied())
33 .flatten()
34 }
35}