diff options
Diffstat (limited to 'macros/src/codegen/resources.rs')
-rw-r--r-- | macros/src/codegen/resources.rs | 67 |
1 files changed, 25 insertions, 42 deletions
diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs index 0bec3e5a..38ea5245 100644 --- a/macros/src/codegen/resources.rs +++ b/macros/src/codegen/resources.rs @@ -1,9 +1,6 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use rtic_syntax::{ - analyze::{Location, Ownership}, - ast::App, -}; +use rtic_syntax::{analyze::Ownership, ast::App}; use crate::{analyze::Analysis, check::Extra, codegen::util}; @@ -13,45 +10,26 @@ pub fn codegen( analysis: &Analysis, extra: &Extra, ) -> ( - // const_app -- the `static [mut]` variables behind the proxies + // mod_app -- the `static [mut]` variables behind the proxies Vec<TokenStream2>, // mod_resources -- the `resources` module TokenStream2, + // mod_resources_imports -- the `resources` module imports + Vec<TokenStream2>, ) { - let mut const_app = vec![]; + let mut mod_app = vec![]; let mut mod_resources = vec![]; + let mut mod_resources_imports = vec![]; - for (name, res, expr, loc) in app.resources(analysis) { + for (name, res, expr, _) in app.resources(analysis) { let cfgs = &res.cfgs; let ty = &res.ty; { - let (loc_attr, section) = match loc { - Location::Owned { - core, - cross_initialized: false, - } => ( - util::cfg_core(*core, app.args.cores), - if expr.is_none() { - util::link_section_uninit(Some(*core)) - } else { - util::link_section("data", *core) - }, - ), - - // shared `static`s and cross-initialized resources need to be in `.shared` memory - _ => ( - if cfg!(feature = "heterogeneous") { - Some(quote!(#[rtic::export::shared])) - } else { - None - }, - if expr.is_none() { - util::link_section_uninit(None) - } else { - None - }, - ), + let section = if expr.is_none() { + util::link_section_uninit(true) + } else { + None }; let (ty, expr) = if let Some(expr) = expr { @@ -64,29 +42,24 @@ pub fn codegen( }; let attrs = &res.attrs; - const_app.push(quote!( + mod_app.push(quote!( #[allow(non_upper_case_globals)] #(#attrs)* #(#cfgs)* - #loc_attr #section static mut #name: #ty = #expr; )); } if let Some(Ownership::Contended { ceiling }) = analysis.ownerships.get(name) { - let cfg_core = util::cfg_core(loc.core().expect("UNREACHABLE"), app.args.cores); - mod_resources.push(quote!( #[allow(non_camel_case_types)] #(#cfgs)* - #cfg_core pub struct #name<'a> { priority: &'a Priority, } #(#cfgs)* - #cfg_core impl<'a> #name<'a> { #[inline(always)] pub unsafe fn new(priority: &'a Priority) -> Self { @@ -112,10 +85,15 @@ pub fn codegen( ) }; - const_app.push(util::impl_mutex( + mod_resources_imports.push(quote!( + #[allow(non_camel_case_types)] + #(#cfgs)* + use super::resources::#name; + )); + + mod_app.push(util::impl_mutex( extra, cfgs, - cfg_core.as_ref(), true, name, quote!(#ty), @@ -128,6 +106,11 @@ pub fn codegen( let mod_resources = if mod_resources.is_empty() { quote!() } else { + // Also import the resource module + mod_resources_imports.push(quote!( + use super::resources; + )); + quote!(mod resources { use rtic::export::Priority; @@ -135,5 +118,5 @@ pub fn codegen( }) }; - (const_app, mod_resources) + (mod_app, mod_resources, mod_resources_imports) } |