diff options
author | 2020-04-22 14:18:32 +0000 | |
---|---|---|
committer | 2020-04-22 14:18:32 +0000 | |
commit | 7406f77a4ec163165fa2f89e8e9351b792e305e3 (patch) | |
tree | 4d2563b527be8f59b8c013e84df47da46ec27b22 /macros/src/codegen/post_init.rs | |
parent | bb59606b7cf14105492c034c9875edc4c1725da0 (diff) | |
parent | f58f37b2b9a292a0e0d0be7d8afbe4df651c3432 (diff) | |
download | rtic-7406f77a4ec163165fa2f89e8e9351b792e305e3.tar.gz rtic-7406f77a4ec163165fa2f89e8e9351b792e305e3.tar.zst rtic-7406f77a4ec163165fa2f89e8e9351b792e305e3.zip |
Merge #306
306: Retain cfg-attributes on resources r=korken89 a=AfoHT
When rust 1.43 lands as stable this will resolve #301 and allow for the kind of conditional compilation exemplified in the issue.
Tested on beta and nightly.
Co-authored-by: Henrik Tjäder <henrik@tjaders.com>
Diffstat (limited to 'macros/src/codegen/post_init.rs')
-rw-r--r-- | macros/src/codegen/post_init.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 19773e45..8578d5ac 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -1,11 +1,13 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; +use rtfm_syntax::ast::App; use crate::{analyze::Analysis, check::Extra, codegen::util}; /// Generates code that runs after `#[init]` returns pub fn codegen( core: u8, + app: &App, analysis: &Analysis, extra: &Extra, ) -> (Vec<TokenStream2>, Vec<TokenStream2>) { @@ -14,10 +16,16 @@ pub fn codegen( // initialize late resources if let Some(late_resources) = analysis.late_resources.get(&core) { + for name in late_resources { // if it's live + let cfgs = app.late_resources[name].cfgs.clone(); if analysis.locations.get(name).is_some() { - stmts.push(quote!(#name.as_mut_ptr().write(late.#name);)); + // Need to also include the cfgs + stmts.push(quote!( + #(#cfgs)* + #name.as_mut_ptr().write(late.#name); + )); } } } |