Skip to content

Commit

Permalink
crates/sel4/config: Add sel4_cfg_word
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Feb 10, 2024
1 parent 5bcebfa commit 8a25c12
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
13 changes: 10 additions & 3 deletions crates/sel4-kernel-loader/add-payload/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,18 @@ fn main() -> Result<()> {

let sel4_config: Configuration =
serde_json::from_reader(File::open(&args.sel4_config_path).unwrap()).unwrap();
let word_size = sel4_config.get("WORD_SIZE").unwrap().as_string().unwrap();

let word_size = sel4_config
.get("WORD_SIZE")
.unwrap()
.as_str()
.unwrap()
.parse::<usize>()
.unwrap();

match word_size {
"32" => continue_with_word_size::<FileHeader32<Endianness>>(&args),
"64" => continue_with_word_size::<FileHeader64<Endianness>>(&args),
32 => continue_with_word_size::<FileHeader32<Endianness>>(&args),
64 => continue_with_word_size::<FileHeader64<Endianness>>(&args),
_ => {
panic!()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4/config/generic/macro-impls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<'a> Impls<'a> {
}
}

fn config(&self) -> &'a Configuration {
pub const fn config(&self) -> &'a Configuration {
self.config
}

Expand Down
2 changes: 1 addition & 1 deletion crates/sel4/config/generic/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl Value {
}
}

pub fn as_string(&self) -> Option<&str> {
pub fn as_str(&self) -> Option<&str> {
match self {
Self::String(v) => Some(v),
_ => None,
Expand Down
19 changes: 19 additions & 0 deletions crates/sel4/config/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,22 @@ pub fn sel4_cfg_usize(key_toks: TokenStream) -> TokenStream {
.cfg_from_str_impl::<usize>(PhantomData, key_toks.into())
.into()
}

#[proc_macro]
pub fn sel4_cfg_word(key_toks: TokenStream) -> TokenStream {
let impls = get_impls();
let word_size = impls
.config()
.get("WORD_SIZE")
.unwrap()
.as_str()
.unwrap()
.parse::<usize>()
.unwrap();
let toks = match word_size {
32 => impls.cfg_from_str_impl::<u32>(PhantomData, key_toks.into()),
64 => impls.cfg_from_str_impl::<u64>(PhantomData, key_toks.into()),
_ => panic!(),
};
toks.into()
}
2 changes: 1 addition & 1 deletion crates/sel4/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

pub use sel4_config::{
self as config, sel4_cfg, sel4_cfg_bool, sel4_cfg_enum, sel4_cfg_if, sel4_cfg_match,
sel4_cfg_str, sel4_cfg_usize, sel4_cfg_wrap_match,
sel4_cfg_str, sel4_cfg_usize, sel4_cfg_word, sel4_cfg_wrap_match,
};

pub use sel4_sys as sys;
Expand Down

0 comments on commit 8a25c12

Please sign in to comment.