use alloc::{ boxed::Box, collections::{BTreeMap, BTreeSet}, string::String, vec::Vec, }; #[derive(Default, Debug)] pub struct DepTree { pub name: String, pub deps: Vec, } impl DepTree { pub fn new(name: String) -> DepTree { DepTree { name, deps: Vec::new(), } } } /// Use to represnt a library as well as all th symbols that is loaded withen it. #[derive(Default)] pub struct Library { /// Global symbols pub globals: BTreeMap, /// Weak symbols pub weak_syms: BTreeMap, /// Loaded library raw data pub objects: BTreeMap>, /// Loaded library in-memory data pub mmaps: BTreeMap, /// Each object will have its children called once with no repetition. pub dep_tree: DepTree, /// A set used to detect circular dependencies in the Linker::load function pub cir_dep: BTreeSet, } impl Library { pub fn new() -> Library { Default::default() } pub fn get_sym(&self, name: &str) -> Option { if let Some(value) = self.globals.get(name) { Some(*value) } else if let Some(value) = self.weak_syms.get(name) { Some(*value) } else { None } } }