use llvm_ir::{Module, TypeRef};
use std::collections::{HashMap, HashSet};
pub struct FunctionsByType<'m> {
map: HashMap<TypeRef, HashSet<&'m str>>,
}
impl<'m> FunctionsByType<'m> {
pub(crate) fn new(modules: impl IntoIterator<Item = &'m Module>) -> Self {
let mut map: HashMap<TypeRef, HashSet<&'m str>> = HashMap::new();
for module in modules {
for func in &module.functions {
map.entry(module.type_of(func))
.or_default()
.insert(&func.name);
}
}
Self { map }
}
pub fn functions_with_type<'s>(&'s self, ty: &TypeRef) -> impl Iterator<Item = &'m str> + 's {
self.map
.get(ty)
.into_iter()
.map(|hs| hs.iter().copied())
.flatten()
}
}