2019-01-11 03:59:57 +00:00
|
|
|
use crate::types::{FuncSig, Map, SigIndex};
|
2019-01-10 16:26:52 +00:00
|
|
|
use hashbrown::HashMap;
|
2019-01-08 17:09:47 +00:00
|
|
|
|
2019-01-10 16:26:52 +00:00
|
|
|
#[derive(Debug)]
|
2019-01-08 17:09:47 +00:00
|
|
|
pub struct SigRegistry {
|
2019-01-10 16:26:52 +00:00
|
|
|
func_table: HashMap<FuncSig, SigIndex>,
|
2019-01-08 17:09:47 +00:00
|
|
|
sig_assoc: Map<SigIndex, FuncSig>,
|
2019-01-10 16:26:52 +00:00
|
|
|
duplicated_sig_assoc: Map<SigIndex, SigIndex>,
|
2019-01-08 17:09:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl SigRegistry {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
2019-01-10 16:26:52 +00:00
|
|
|
func_table: HashMap::new(),
|
2019-01-08 17:09:47 +00:00
|
|
|
sig_assoc: Map::new(),
|
2019-01-10 16:26:52 +00:00
|
|
|
duplicated_sig_assoc: Map::new(),
|
2019-01-08 17:09:47 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-09 02:57:28 +00:00
|
|
|
|
2019-01-08 17:09:47 +00:00
|
|
|
pub fn register(&mut self, func_sig: FuncSig) -> SigIndex {
|
2019-01-10 16:26:52 +00:00
|
|
|
// self.sig_assoc.push(func_sig)
|
|
|
|
let func_table = &mut self.func_table;
|
|
|
|
let sig_assoc = &mut self.sig_assoc;
|
|
|
|
let sig_index = *func_table
|
|
|
|
.entry(func_sig.clone())
|
|
|
|
.or_insert_with(|| sig_assoc.push(func_sig));
|
|
|
|
self.duplicated_sig_assoc.push(sig_index);
|
|
|
|
sig_index
|
2019-01-08 17:09:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 16:26:52 +00:00
|
|
|
pub fn lookup_deduplicated_sigindex(&self, sig_index: SigIndex) -> SigIndex {
|
|
|
|
self.duplicated_sig_assoc[sig_index]
|
2019-01-08 17:09:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 16:26:52 +00:00
|
|
|
pub fn lookup_func_sig(&self, sig_index: SigIndex) -> &FuncSig {
|
|
|
|
&self.sig_assoc[sig_index]
|
2019-01-08 17:09:47 +00:00
|
|
|
}
|
|
|
|
}
|