diff options
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/analyze.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen.rs | 7 | ||||
-rw-r--r-- | macros/src/codegen/local_resources_struct.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen/module.rs | 13 | ||||
-rw-r--r-- | macros/src/codegen/post_init.rs | 1 | ||||
-rw-r--r-- | macros/src/codegen/pre_init.rs | 8 | ||||
-rw-r--r-- | macros/src/codegen/shared_resources.rs | 7 | ||||
-rw-r--r-- | macros/src/codegen/shared_resources_struct.rs | 55 | ||||
-rw-r--r-- | macros/src/codegen/software_tasks.rs | 2 | ||||
-rw-r--r-- | macros/src/codegen/timer_queue.rs | 1 | ||||
-rw-r--r-- | macros/src/codegen/util.rs | 10 | ||||
-rw-r--r-- | macros/src/lib.rs | 21 |
12 files changed, 64 insertions, 65 deletions
diff --git a/macros/src/analyze.rs b/macros/src/analyze.rs index 6b261388..d255b7f5 100644 --- a/macros/src/analyze.rs +++ b/macros/src/analyze.rs @@ -34,7 +34,7 @@ pub fn app(analysis: P<analyze::Analysis>, app: &App) -> P<Analysis> { // map from priorities to interrupts (holding name and attributes) let interrupts: BTreeMap<Priority, _> = priorities .iter() - .cloned() + .copied() .rev() .zip(&app.args.extern_interrupts) .map(|(p, (id, ext))| (p, (id.clone(), ext.clone()))) diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 10050843..f5cae34a 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -20,6 +20,7 @@ mod software_tasks; mod timer_queue; mod util; +#[allow(clippy::too_many_lines)] pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { let mut mod_app = vec![]; let mut mains = vec![]; @@ -142,7 +143,9 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { }) .collect(); - let monotonics = if !monotonic_parts.is_empty() { + let monotonics = if monotonic_parts.is_empty() { + quote!() + } else { quote!( pub use rtic::Monotonic as _; @@ -151,8 +154,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 { #(#monotonic_parts)* } ) - } else { - quote!() }; let rt_err = util::rt_err_ident(); diff --git a/macros/src/codegen/local_resources_struct.rs b/macros/src/codegen/local_resources_struct.rs index 10bde5fe..b7eae3f9 100644 --- a/macros/src/codegen/local_resources_struct.rs +++ b/macros/src/codegen/local_resources_struct.rs @@ -78,7 +78,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, pub __marker__: core::marker::PhantomData<&'a ()> )); - values.push(quote!(__marker__: core::marker::PhantomData)) + values.push(quote!(__marker__: core::marker::PhantomData)); } } diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 8410b7d7..fd8137fa 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -3,6 +3,7 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; use rtic_syntax::{ast::App, Context}; +#[allow(clippy::too_many_lines)] pub fn codegen( ctxt: Context, shared_resources_tick: bool, @@ -50,11 +51,7 @@ pub fn codegen( values.push(quote!(core)); } - Context::Idle => {} - - Context::HardwareTask(_) => {} - - Context::SoftwareTask(_) => {} + Context::Idle | Context::HardwareTask(_) | Context::SoftwareTask(_) => {} } // if ctxt.has_locals(app) { @@ -438,7 +435,9 @@ pub fn codegen( } } - if !items.is_empty() { + if items.is_empty() { + quote!() + } else { quote!( #(#items)* @@ -449,7 +448,5 @@ pub fn codegen( #(#module_items)* } ) - } else { - quote!() } } diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 8bd3a7dd..9531254c 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -48,6 +48,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); // stmts.push(quote!(#[doc = #doc])); + #[allow(clippy::cast_possible_truncation)] let idx = Index { index: i as u32, span: Span::call_site(), diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs index 7aaf20fc..91c99912 100644 --- a/macros/src/codegen/pre_init.rs +++ b/macros/src/codegen/pre_init.rs @@ -41,12 +41,12 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id)); // Unmask interrupts and set their priorities - for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().flat_map(|task| { - if !util::is_exception(&task.args.binds) { - Some((&task.args.priority, &task.args.binds)) - } else { + for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().filter_map(|task| { + if util::is_exception(&task.args.binds) { // We do exceptions in another pass None + } else { + Some((&task.args.priority, &task.args.binds)) } })) { // Compile time assert that this priority is supported by the device diff --git a/macros/src/codegen/shared_resources.rs b/macros/src/codegen/shared_resources.rs index a115b7c2..9e45cff9 100644 --- a/macros/src/codegen/shared_resources.rs +++ b/macros/src/codegen/shared_resources.rs @@ -75,8 +75,7 @@ pub fn codegen( ); let ceiling = match analysis.ownerships.get(name) { - Some(Ownership::Owned { priority }) => *priority, - Some(Ownership::CoOwned { priority }) => *priority, + Some(Ownership::Owned { priority } | Ownership::CoOwned { priority }) => *priority, Some(Ownership::Contended { ceiling }) => *ceiling, None => 0, }; @@ -89,9 +88,9 @@ pub fn codegen( cfgs, true, &shared_name, - quote!(#ty), + "e!(#ty), ceiling, - ptr, + &ptr, )); } } diff --git a/macros/src/codegen/shared_resources_struct.rs b/macros/src/codegen/shared_resources_struct.rs index 7ae8d808..90cbc1be 100644 --- a/macros/src/codegen/shared_resources_struct.rs +++ b/macros/src/codegen/shared_resources_struct.rs @@ -35,33 +35,8 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, let mangled_name = util::static_shared_resource_ident(name); let shared_name = util::need_to_lock_ident(name); - if !res.properties.lock_free { - if access.is_shared() { - lt = Some(quote!('a)); - - fields.push(quote!( - #(#cfgs)* - pub #name: &'a #ty - )); - } else { - // Resource proxy - lt = Some(quote!('a)); - - fields.push(quote!( - #(#cfgs)* - pub #name: shared_resources::#shared_name<'a> - )); - - values.push(quote!( - #(#cfgs)* - #name: shared_resources::#shared_name::new(priority) - - )); - - // continue as the value has been filled, - continue; - } - } else { + if res.properties.lock_free { + // Lock free resources of `idle` and `init` get 'static lifetime let lt = if ctxt.runs_once() { quote!('static) } else { @@ -73,6 +48,30 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, #(#cfgs)* pub #name: &#lt #mut_ #ty )); + } else if access.is_shared() { + lt = Some(quote!('a)); + + fields.push(quote!( + #(#cfgs)* + pub #name: &'a #ty + )); + } else { + // Resource proxy + lt = Some(quote!('a)); + + fields.push(quote!( + #(#cfgs)* + pub #name: shared_resources::#shared_name<'a> + )); + + values.push(quote!( + #(#cfgs)* + #name: shared_resources::#shared_name::new(priority) + + )); + + // continue as the value has been filled, + continue; } let expr = if access.is_exclusive() { @@ -97,7 +96,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, pub __marker__: core::marker::PhantomData<&'a ()> )); - values.push(quote!(__marker__: core::marker::PhantomData)) + values.push(quote!(__marker__: core::marker::PhantomData)); } } diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 0357003f..77559493 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -43,7 +43,7 @@ pub fn codegen( ( quote!(rtic::export::SCFQ<#cap_lit_p1>), quote!(rtic::export::Queue::new()), - Box::new(|| util::link_section_uninit()), + Box::new(|| Some(util::link_section_uninit())), ) }; mod_app.push(quote!( diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs index 2a344d25..32e288c5 100644 --- a/macros/src/codegen/timer_queue.rs +++ b/macros/src/codegen/timer_queue.rs @@ -5,6 +5,7 @@ use rtic_syntax::ast::App; use crate::{analyze::Analysis, check::Extra, codegen::util}; /// Generates timer queues and timer queue handlers +#[allow(clippy::too_many_lines)] pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStream2> { let mut items = vec![]; diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 46eace4c..6a07732c 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -25,9 +25,9 @@ pub fn impl_mutex( cfgs: &[Attribute], resources_prefix: bool, name: &Ident, - ty: TokenStream2, + ty: &TokenStream2, ceiling: u8, - ptr: TokenStream2, + ptr: &TokenStream2, ) -> TokenStream2 { let (path, priority) = if resources_prefix { (quote!(shared_resources::#name), quote!(self.priority())) @@ -117,11 +117,11 @@ fn link_section_index() -> usize { INDEX.fetch_add(1, Ordering::Relaxed) } -// NOTE `None` means in shared memory -pub fn link_section_uninit() -> Option<TokenStream2> { +/// Add `link_section` attribute +pub fn link_section_uninit() -> TokenStream2 { let section = format!(".uninit.rtic{}", link_section_index()); - Some(quote!(#[link_section = #section])) + quote!(#[link_section = #section]) } // Regroups the inputs of a task diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 13b6a7c2..2b526017 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -20,7 +20,10 @@ mod tests; /// Attribute used to declare a RTIC application /// /// For user documentation see the [RTIC book](https://rtic.rs) - +/// +/// # Panics +/// +/// Should never panic, cargo feeds a path which is later converted to a string #[proc_macro_attribute] pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { let mut settings = Settings::default(); @@ -61,7 +64,10 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { #[cfg(feature = "debugprint")] println!("OUT_DIR\n{:#?}", out_str); - if !out_dir.exists() { + if out_dir.exists() { + #[cfg(feature = "debugprint")] + println!("\ntarget/ exists\n"); + } else { // Set out_dir to OUT_DIR out_dir = Path::new(&out_str); @@ -80,24 +86,19 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { .to_str() .unwrap() .starts_with(target_triple_prefix) - //|| path.ends_with(&out_dir_root) { if let Some(out) = path.parent() { out_dir = out; #[cfg(feature = "debugprint")] println!("{:#?}\n", out_dir); break; - } else { - // If no parent, just use it - out_dir = path; - break; } + // If no parent, just use it + out_dir = path; + break; } } } - } else { - #[cfg(feature = "debugprint")] - println!("\ntarget/ exists\n"); } // Try to write the expanded code to disk |