litex/module_manager/
module_manager.rs1use crate::prelude::*;
2use std::collections::HashMap;
3use std::rc::Rc;
4
5pub const BUILTIN_CODE_PATH: &str = "builtin_code";
7
8pub struct ImportedModuleEnvironment {
9 pub environment: Environment,
10 pub name_scope: HashMap<String, LineFile>,
11}
12
13pub struct ModuleManager {
14 pub run_file_paths: Vec<Rc<str>>,
15 pub module_name_and_path_map: HashMap<String, String>,
16 pub module_path_and_names_map: HashMap<String, Vec<String>>,
17 pub current_module_path: String,
18 pub current_module_name: String,
19 pub current_file_index: usize,
20 pub entry_path: String,
21 pub display_entry_rc: Option<Rc<str>>,
23 pub hide_file_paths_in_output: bool,
24 pub imported_module_environments: HashMap<String, Box<ImportedModuleEnvironment>>,
25}
26
27impl ModuleManager {
28 pub fn new_empty_module_manager(initial_path: &str) -> Self {
29 ModuleManager {
30 run_file_paths: vec![Rc::from(initial_path)],
31 module_name_and_path_map: HashMap::new(),
32 module_path_and_names_map: HashMap::new(),
33 current_module_path: String::new(),
34 current_module_name: String::new(),
35 current_file_index: FILE_INDEX_FOR_BUILTIN,
36 entry_path: initial_path.to_string(),
37 display_entry_rc: None,
38 hide_file_paths_in_output: false,
39 imported_module_environments: HashMap::new(),
40 }
41 }
42
43 pub fn current_file_path_rc(&self) -> Rc<str> {
44 self.run_file_paths[self.current_file_index].clone()
45 }
46}