rtic_core/codegen/utils.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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
use quote::format_ident;
use syn::Ident;
pub fn core_type(core: u32) -> Ident {
format_ident!("__rtic__internal__Core{core}")
}
pub fn core_type_inner(core: u32) -> Ident {
format_ident!("__rtic__internal__Core{core}Inner")
}
pub fn core_type_mod(core: u32) -> Ident {
format_ident!("core{core}_type_mod")
}
#[allow(unused)]
pub mod multibin {
use proc_macro2::TokenStream;
use syn::{parse_quote, Attribute};
/// If `multibin` feature is enabled, this returns a tokenstream for the attribute `#[cfg(core = "x")]` to partition an application
/// to multiple binaries. Otherwise `None` is returned
pub fn multibin_cfg_core(core: u32) -> Option<Attribute> {
#[cfg(feature = "multibin")]
{
let val = core.to_string();
Some(parse_quote! {
#[cfg(core = #val)]
})
}
#[cfg(not(feature = "multibin"))]
None
}
/// If `multibin` feature is enabled, this returns a tokenstream for the attribute `#[cfg(not(core = "x"))]`
/// Otherwise `None` is returned
pub fn multibin_cfg_not_core(core: u32) -> Option<Attribute> {
#[cfg(feature = "multibin")]
{
let val = core.to_string();
Some(parse_quote! {
#[cfg(not(core = #val))]
})
}
#[cfg(not(feature = "multibin"))]
None
}
/// If `multibin` feature is enabled, this returns a tokenstream for the attribute `#[cfg_attr(not(core = "x"), your_attr)]`
/// Otherwise `None` is returned
pub fn multibin_cfg_attr_not_core(core: u32, attr: TokenStream) -> Option<Attribute> {
#[cfg(feature = "multibin")]
{
let val = core.to_string();
Some(parse_quote! {
#[cfg_attr(not(core = #val), #attr)]
})
}
#[cfg(not(feature = "multibin"))]
None
}
/// If `multibin` feature is enabled, this returns a tokenstream for the attribute `#[multibin_shared]` to make sure the annotated variable
/// is present at the same address on all cores. Otherwise `None` is returned
pub fn multibin_shared() -> Option<Attribute> {
#[cfg(feature = "multibin")]
{
Some(parse_quote! {
#[multibin_shared]
})
}
#[cfg(not(feature = "multibin"))]
None
}
}