aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/codegen')
-rw-r--r--macros/src/codegen/local_resources_struct.rs2
-rw-r--r--macros/src/codegen/module.rs13
-rw-r--r--macros/src/codegen/post_init.rs1
-rw-r--r--macros/src/codegen/pre_init.rs8
-rw-r--r--macros/src/codegen/shared_resources.rs7
-rw-r--r--macros/src/codegen/shared_resources_struct.rs55
-rw-r--r--macros/src/codegen/software_tasks.rs2
-rw-r--r--macros/src/codegen/timer_queue.rs1
-rw-r--r--macros/src/codegen/util.rs10
9 files changed, 48 insertions, 51 deletions
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),
+ &quote!(#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