-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefines.rs
37 lines (29 loc) · 1.22 KB
/
defines.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//! Contains all possible defines which are generated on request to be added to an autogenerated `hive_defines.S` file
use comm_types::defines::{DefineRegistry, HiveUid};
use tokio::sync::Mutex;
use lazy_static::lazy_static;
const FILE_HEADER: &str =
"# File: Hive defines\n# Author: Hive (autogenerated)\n# This file contains all symbols which can be used by a Hive testprogram.\n# The symbols are set to the appropriate value by Hive, before the final binary is flashed\n\n";
lazy_static! {
/// This is where all Hive Defines are registered for use in the monitor
pub static ref DEFINE_REGISTRY: Mutex<DefineRegistry> = {
let mut registry = DefineRegistry::new();
registry.register(Box::new(HiveUid::new()));
Mutex::new(registry)
};
}
/// Generates the `hive_defines.S` file contents and returns its binary representation
pub(super) fn generate_defines() -> String {
let mut defines = String::new();
for define in DEFINE_REGISTRY
.blocking_lock()
.get_active_defines()
.values_mut()
{
define.generate();
defines.push_str(&format!("{}\n", define.to_file_line()))
}
let mut out = FILE_HEADER.to_owned();
out.push_str(&defines);
out
}