diff --git a/crates/sel4-kernel-loader/add-payload/src/main.rs b/crates/sel4-kernel-loader/add-payload/src/main.rs index 5b709f3ab..a2f44f48a 100644 --- a/crates/sel4-kernel-loader/add-payload/src/main.rs +++ b/crates/sel4-kernel-loader/add-payload/src/main.rs @@ -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::() + .unwrap(); match word_size { - "32" => continue_with_word_size::>(&args), - "64" => continue_with_word_size::>(&args), + 32 => continue_with_word_size::>(&args), + 64 => continue_with_word_size::>(&args), _ => { panic!() } diff --git a/crates/sel4/config/generic/macro-impls/src/lib.rs b/crates/sel4/config/generic/macro-impls/src/lib.rs index fcd500793..7db27d894 100644 --- a/crates/sel4/config/generic/macro-impls/src/lib.rs +++ b/crates/sel4/config/generic/macro-impls/src/lib.rs @@ -27,7 +27,7 @@ impl<'a> Impls<'a> { } } - fn config(&self) -> &'a Configuration { + pub const fn config(&self) -> &'a Configuration { self.config } diff --git a/crates/sel4/config/generic/types/src/lib.rs b/crates/sel4/config/generic/types/src/lib.rs index 9f4334358..32bff5337 100644 --- a/crates/sel4/config/generic/types/src/lib.rs +++ b/crates/sel4/config/generic/types/src/lib.rs @@ -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, diff --git a/crates/sel4/config/macros/src/lib.rs b/crates/sel4/config/macros/src/lib.rs index 9bcd4e6d5..3ade46bfb 100644 --- a/crates/sel4/config/macros/src/lib.rs +++ b/crates/sel4/config/macros/src/lib.rs @@ -70,3 +70,22 @@ pub fn sel4_cfg_usize(key_toks: TokenStream) -> TokenStream { .cfg_from_str_impl::(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::() + .unwrap(); + let toks = match word_size { + 32 => impls.cfg_from_str_impl::(PhantomData, key_toks.into()), + 64 => impls.cfg_from_str_impl::(PhantomData, key_toks.into()), + _ => panic!(), + }; + toks.into() +} diff --git a/crates/sel4/src/lib.rs b/crates/sel4/src/lib.rs index 3615f6ef8..df1aab5f9 100644 --- a/crates/sel4/src/lib.rs +++ b/crates/sel4/src/lib.rs @@ -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;