From 7614b96fe45240dafe91ae549e712b560e2d4c10 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sat, 31 Dec 2022 14:45:13 +0100 Subject: RTIC v2: Initial commit rtic-syntax is now part of RTIC repository --- macros/src/codegen/util.rs | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 0a3edc2..151906d 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -1,12 +1,10 @@ use core::sync::atomic::{AtomicUsize, Ordering}; +use crate::syntax::{ast::App, Context}; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; -use rtic_syntax::{ast::App, Context}; use syn::{Attribute, Ident, LitInt, PatType}; -use crate::check::Extra; - const RTIC_INTERNAL: &str = "__rtic_internal"; /// Turns `capacity` into an unsuffixed integer literal @@ -21,7 +19,7 @@ pub fn fq_ident(task: &Ident) -> Ident { /// Generates a `Mutex` implementation pub fn impl_mutex( - extra: &Extra, + app: &App, cfgs: &[Attribute], resources_prefix: bool, name: &Ident, @@ -35,7 +33,7 @@ pub fn impl_mutex( (quote!(#name), quote!(self.priority)) }; - let device = &extra.device; + let device = &app.args.device; let masks_name = priority_masks_ident(); quote!( #(#cfgs)* @@ -67,6 +65,11 @@ pub fn inputs_ident(task: &Ident) -> Ident { mark_internal_name(&format!("{}_INPUTS", task)) } +/// Generates an identifier for the `EXECUTOR_RUN` atomics (`async` API) +pub fn executor_run_ident(task: &Ident) -> Ident { + mark_internal_name(&format!("{}_EXECUTOR_RUN", task)) +} + /// Generates an identifier for the `INSTANTS` buffer (`schedule` API) pub fn monotonic_instants_ident(task: &Ident, monotonic: &Ident) -> Ident { mark_internal_name(&format!("{}_{}_INSTANTS", task, monotonic)) @@ -179,7 +182,12 @@ pub fn regroup_inputs( pub fn get_task_name(ctxt: Context, app: &App) -> Ident { let s = match ctxt { Context::Init => app.init.name.to_string(), - Context::Idle => app.idle.as_ref().unwrap().name.to_string(), + Context::Idle => app + .idle + .as_ref() + .expect("RTIC-ICE: unable to find idle name") + .name + .to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; @@ -190,7 +198,12 @@ pub fn get_task_name(ctxt: Context, app: &App) -> Ident { pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident { let mut s = match ctxt { Context::Init => app.init.name.to_string(), - Context::Idle => app.idle.as_ref().unwrap().name.to_string(), + Context::Idle => app + .idle + .as_ref() + .expect("RTIC-ICE: unable to find idle name") + .name + .to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; @@ -203,7 +216,12 @@ pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident { pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { let mut s = match ctxt { Context::Init => app.init.name.to_string(), - Context::Idle => app.idle.as_ref().unwrap().name.to_string(), + Context::Idle => app + .idle + .as_ref() + .expect("RTIC-ICE: unable to find idle name") + .name + .to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; @@ -220,9 +238,14 @@ pub fn rq_ident(priority: u8) -> Ident { mark_internal_name(&format!("P{}_RQ", priority)) } +/// Generates an identifier for a ready queue, async task version +pub fn rq_async_ident(async_task_name: &Ident) -> Ident { + mark_internal_name(&format!("ASYNC_TACK_{}_RQ", async_task_name)) +} + /// Generates an identifier for the `enum` of `schedule`-able tasks pub fn schedule_t_ident() -> Ident { - Ident::new("SCHED_T", Span::call_site()) + mark_internal_name("SCHED_T") } /// Generates an identifier for the `enum` of `spawn`-able tasks @@ -230,7 +253,7 @@ pub fn schedule_t_ident() -> Ident { /// This identifier needs the same structure as the `RQ` identifier because there's one ready queue /// for each of these `T` enums pub fn spawn_t_ident(priority: u8) -> Ident { - Ident::new(&format!("P{}_T", priority), Span::call_site()) + mark_internal_name(&format!("P{}_T", priority)) } /// Suffixed identifier -- cgit v1.2.3 From f8352122a301c30db7c7851ebf50ad1608ebdad3 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 3 Jan 2023 15:10:59 +0100 Subject: Min codegen --- macros/src/codegen/util.rs | 111 +-------------------------------------------- 1 file changed, 1 insertion(+), 110 deletions(-) (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 151906d..61bde98 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -3,20 +3,10 @@ use core::sync::atomic::{AtomicUsize, Ordering}; use crate::syntax::{ast::App, Context}; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; -use syn::{Attribute, Ident, LitInt, PatType}; +use syn::{Attribute, Ident}; const RTIC_INTERNAL: &str = "__rtic_internal"; -/// Turns `capacity` into an unsuffixed integer literal -pub fn capacity_literal(capacity: usize) -> LitInt { - LitInt::new(&capacity.to_string(), Span::call_site()) -} - -/// Identifier for the free queue -pub fn fq_ident(task: &Ident) -> Ident { - mark_internal_name(&format!("{}_FQ", task)) -} - /// Generates a `Mutex` implementation pub fn impl_mutex( app: &App, @@ -60,30 +50,16 @@ pub fn impl_mutex( ) } -/// Generates an identifier for the `INPUTS` buffer (`spawn` & `schedule` API) -pub fn inputs_ident(task: &Ident) -> Ident { - mark_internal_name(&format!("{}_INPUTS", task)) -} - /// Generates an identifier for the `EXECUTOR_RUN` atomics (`async` API) pub fn executor_run_ident(task: &Ident) -> Ident { mark_internal_name(&format!("{}_EXECUTOR_RUN", task)) } -/// Generates an identifier for the `INSTANTS` buffer (`schedule` API) -pub fn monotonic_instants_ident(task: &Ident, monotonic: &Ident) -> Ident { - mark_internal_name(&format!("{}_{}_INSTANTS", task, monotonic)) -} - pub fn interrupt_ident() -> Ident { let span = Span::call_site(); Ident::new("interrupt", span) } -pub fn timer_queue_marker_ident() -> Ident { - mark_internal_name("TIMER_QUEUE_MARKER") -} - /// Whether `name` is an exception with configurable priority pub fn is_exception(name: &Ident) -> bool { let s = name.to_string(); @@ -106,11 +82,6 @@ pub fn mark_internal_name(name: &str) -> Ident { Ident::new(&format!("{}_{}", RTIC_INTERNAL, name), Span::call_site()) } -/// Generate an internal identifier for monotonics -pub fn internal_monotonics_ident(task: &Ident, monotonic: &Ident, ident_name: &str) -> Ident { - mark_internal_name(&format!("{}_{}_{}", task, monotonic, ident_name,)) -} - /// Generate an internal identifier for tasks pub fn internal_task_ident(task: &Ident, ident_name: &str) -> Ident { mark_internal_name(&format!("{}_{}", task, ident_name)) @@ -129,55 +100,6 @@ pub fn link_section_uninit() -> TokenStream2 { quote!(#[link_section = #section]) } -// Regroups the inputs of a task -// -// `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`] -pub fn regroup_inputs( - inputs: &[PatType], -) -> ( - // args e.g. &[`_0`], &[`_0: i32`, `_1: i64`] - Vec, - // tupled e.g. `_0`, `(_0, _1)` - TokenStream2, - // untupled e.g. &[`_0`], &[`_0`, `_1`] - Vec, - // ty e.g. `Foo`, `(i32, i64)` - TokenStream2, -) { - if inputs.len() == 1 { - let ty = &inputs[0].ty; - - ( - vec![quote!(_0: #ty)], - quote!(_0), - vec![quote!(_0)], - quote!(#ty), - ) - } else { - let mut args = vec![]; - let mut pats = vec![]; - let mut tys = vec![]; - - for (i, input) in inputs.iter().enumerate() { - let i = Ident::new(&format!("_{}", i), Span::call_site()); - let ty = &input.ty; - - args.push(quote!(#i: #ty)); - - pats.push(quote!(#i)); - - tys.push(quote!(#ty)); - } - - let tupled = { - let pats = pats.clone(); - quote!((#(#pats,)*)) - }; - let ty = quote!((#(#tys,)*)); - (args, tupled, pats, ty) - } -} - /// Get the ident for the name of the task pub fn get_task_name(ctxt: Context, app: &App) -> Ident { let s = match ctxt { @@ -230,48 +152,17 @@ pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { mark_internal_name(&s) } -/// Generates an identifier for a ready queue -/// -/// There may be several task dispatchers, one for each priority level. -/// The ready queues are SPSC queues -pub fn rq_ident(priority: u8) -> Ident { - mark_internal_name(&format!("P{}_RQ", priority)) -} - /// Generates an identifier for a ready queue, async task version pub fn rq_async_ident(async_task_name: &Ident) -> Ident { mark_internal_name(&format!("ASYNC_TACK_{}_RQ", async_task_name)) } -/// Generates an identifier for the `enum` of `schedule`-able tasks -pub fn schedule_t_ident() -> Ident { - mark_internal_name("SCHED_T") -} - -/// Generates an identifier for the `enum` of `spawn`-able tasks -/// -/// This identifier needs the same structure as the `RQ` identifier because there's one ready queue -/// for each of these `T` enums -pub fn spawn_t_ident(priority: u8) -> Ident { - mark_internal_name(&format!("P{}_T", priority)) -} - /// Suffixed identifier pub fn suffixed(name: &str) -> Ident { let span = Span::call_site(); Ident::new(name, span) } -/// Generates an identifier for a timer queue -pub fn tq_ident(name: &str) -> Ident { - mark_internal_name(&format!("TQ_{}", name)) -} - -/// Generates an identifier for monotonic timer storage -pub fn monotonic_ident(name: &str) -> Ident { - mark_internal_name(&format!("MONOTONIC_STORAGE_{}", name)) -} - pub fn static_shared_resource_ident(name: &Ident) -> Ident { mark_internal_name(&format!("shared_resource_{}", name)) } -- cgit v1.2.3 From 3b97531a5c40293e265999db543acec365c629df Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 4 Jan 2023 21:33:41 +0100 Subject: First example builds again --- macros/src/codegen/util.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 61bde98..aa720c0 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -154,7 +154,7 @@ pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { /// Generates an identifier for a ready queue, async task version pub fn rq_async_ident(async_task_name: &Ident) -> Ident { - mark_internal_name(&format!("ASYNC_TACK_{}_RQ", async_task_name)) + mark_internal_name(&format!("ASYNC_TASK_{}_RQ", async_task_name)) } /// Suffixed identifier -- cgit v1.2.3 From 714020a624ca93c42d5da7ebe612e7fc668e1471 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sat, 7 Jan 2023 11:24:13 +0100 Subject: Removed Priority, simplified lifetime handling --- macros/src/codegen/util.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index aa720c0..a071ca2 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -17,10 +17,10 @@ pub fn impl_mutex( ceiling: u8, ptr: &TokenStream2, ) -> TokenStream2 { - let (path, priority) = if resources_prefix { - (quote!(shared_resources::#name), quote!(self.priority())) + let path = if resources_prefix { + quote!(shared_resources::#name) } else { - (quote!(#name), quote!(self.priority)) + quote!(#name) }; let device = &app.args.device; @@ -38,7 +38,6 @@ pub fn impl_mutex( unsafe { rtic::export::lock( #ptr, - #priority, CEILING, #device::NVIC_PRIO_BITS, &#masks_name, -- cgit v1.2.3 From 6d252785e83218eeb5d080836281c90b86ca0e03 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 8 Jan 2023 21:10:06 +0100 Subject: Support 0 prio tasks --- macros/src/codegen/util.rs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index a071ca2..6552839 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -187,6 +187,10 @@ pub fn need_to_lock_ident(name: &Ident) -> Ident { Ident::new(&format!("{}_that_needs_to_be_locked", name), name.span()) } +pub fn zero_prio_dispatcher_ident() -> Ident { + Ident::new("__rtic_internal_async_0_prio_dispatcher", Span::call_site()) +} + /// The name to get better RT flag errors pub fn rt_err_ident() -> Ident { Ident::new( -- cgit v1.2.3 From c40c89bb4edc22c4a60d8677c660a9ab7eb47e92 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 8 Jan 2023 21:30:53 +0100 Subject: Clippy fixes --- macros/src/codegen/util.rs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 6552839..a0caf0a 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -51,7 +51,7 @@ pub fn impl_mutex( /// Generates an identifier for the `EXECUTOR_RUN` atomics (`async` API) pub fn executor_run_ident(task: &Ident) -> Ident { - mark_internal_name(&format!("{}_EXECUTOR_RUN", task)) + mark_internal_name(&format!("{task}_EXECUTOR_RUN")) } pub fn interrupt_ident() -> Ident { @@ -78,12 +78,12 @@ pub fn is_exception(name: &Ident) -> bool { /// Mark a name as internal pub fn mark_internal_name(name: &str) -> Ident { - Ident::new(&format!("{}_{}", RTIC_INTERNAL, name), Span::call_site()) + Ident::new(&format!("{RTIC_INTERNAL}_{name}"), Span::call_site()) } /// Generate an internal identifier for tasks pub fn internal_task_ident(task: &Ident, ident_name: &str) -> Ident { - mark_internal_name(&format!("{}_{}", task, ident_name)) + mark_internal_name(&format!("{task}_{ident_name}")) } fn link_section_index() -> usize { @@ -153,7 +153,7 @@ pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { /// Generates an identifier for a ready queue, async task version pub fn rq_async_ident(async_task_name: &Ident) -> Ident { - mark_internal_name(&format!("ASYNC_TASK_{}_RQ", async_task_name)) + mark_internal_name(&format!("ASYNC_TASK_{async_task_name}_RQ")) } /// Suffixed identifier @@ -163,7 +163,7 @@ pub fn suffixed(name: &str) -> Ident { } pub fn static_shared_resource_ident(name: &Ident) -> Ident { - mark_internal_name(&format!("shared_resource_{}", name)) + mark_internal_name(&format!("shared_resource_{name}")) } /// Generates an Ident for the number of 32 bit chunks used for Mask storage. @@ -176,15 +176,15 @@ pub fn priority_masks_ident() -> Ident { } pub fn static_local_resource_ident(name: &Ident) -> Ident { - mark_internal_name(&format!("local_resource_{}", name)) + mark_internal_name(&format!("local_resource_{name}")) } pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) -> Ident { - mark_internal_name(&format!("local_{}_{}", task_name, name)) + mark_internal_name(&format!("local_{task_name}_{name}")) } pub fn need_to_lock_ident(name: &Ident) -> Ident { - Ident::new(&format!("{}_that_needs_to_be_locked", name), name.span()) + Ident::new(&format!("{name}_that_needs_to_be_locked"), name.span()) } pub fn zero_prio_dispatcher_ident() -> Ident { -- cgit v1.2.3 From cd790a94286cdc307d399b7f7a43e305e90de5bf Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 9 Jan 2023 21:02:53 +0100 Subject: More work on new spawn/executor --- macros/src/codegen/util.rs | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index a0caf0a..0558d9d 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -49,11 +49,6 @@ pub fn impl_mutex( ) } -/// Generates an identifier for the `EXECUTOR_RUN` atomics (`async` API) -pub fn executor_run_ident(task: &Ident) -> Ident { - mark_internal_name(&format!("{task}_EXECUTOR_RUN")) -} - pub fn interrupt_ident() -> Ident { let span = Span::call_site(); Ident::new("interrupt", span) @@ -151,11 +146,6 @@ pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { mark_internal_name(&s) } -/// Generates an identifier for a ready queue, async task version -pub fn rq_async_ident(async_task_name: &Ident) -> Ident { - mark_internal_name(&format!("ASYNC_TASK_{async_task_name}_RQ")) -} - /// Suffixed identifier pub fn suffixed(name: &str) -> Ident { let span = Span::call_site(); -- cgit v1.2.3 From d6d58b0eb88242cf63724e1420bd29f8a4489916 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 10 Jan 2023 21:03:10 +0100 Subject: Async tasks can now take arguments at spawn again --- macros/src/codegen/util.rs | 54 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 0558d9d..e121487 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -1,9 +1,8 @@ -use core::sync::atomic::{AtomicUsize, Ordering}; - use crate::syntax::{ast::App, Context}; +use core::sync::atomic::{AtomicUsize, Ordering}; use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; -use syn::{Attribute, Ident}; +use syn::{Attribute, Ident, PatType}; const RTIC_INTERNAL: &str = "__rtic_internal"; @@ -94,6 +93,55 @@ pub fn link_section_uninit() -> TokenStream2 { quote!(#[link_section = #section]) } +/// Regroups the inputs of a task +/// +/// `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`] +pub fn regroup_inputs( + inputs: &[PatType], +) -> ( + // args e.g. &[`_0`], &[`_0: i32`, `_1: i64`] + Vec, + // tupled e.g. `_0`, `(_0, _1)` + TokenStream2, + // untupled e.g. &[`_0`], &[`_0`, `_1`] + Vec, + // ty e.g. `Foo`, `(i32, i64)` + TokenStream2, +) { + if inputs.len() == 1 { + let ty = &inputs[0].ty; + + ( + vec![quote!(_0: #ty)], + quote!(_0), + vec![quote!(_0)], + quote!(#ty), + ) + } else { + let mut args = vec![]; + let mut pats = vec![]; + let mut tys = vec![]; + + for (i, input) in inputs.iter().enumerate() { + let i = Ident::new(&format!("_{}", i), Span::call_site()); + let ty = &input.ty; + + args.push(quote!(#i: #ty)); + + pats.push(quote!(#i)); + + tys.push(quote!(#ty)); + } + + let tupled = { + let pats = pats.clone(); + quote!((#(#pats,)*)) + }; + let ty = quote!((#(#tys,)*)); + (args, tupled, pats, ty) + } +} + /// Get the ident for the name of the task pub fn get_task_name(ctxt: Context, app: &App) -> Ident { let s = match ctxt { -- cgit v1.2.3 From 306aa47170fd59369b7a184924e287dc3706d64d Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 23 Jan 2023 20:05:47 +0100 Subject: Add rtic-timer (timerqueue + monotonic) and rtic-monotonics (systick-monotonic) --- macros/src/codegen/util.rs | 238 --------------------------------------------- 1 file changed, 238 deletions(-) delete mode 100644 macros/src/codegen/util.rs (limited to 'macros/src/codegen/util.rs') diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs deleted file mode 100644 index e121487..0000000 --- a/macros/src/codegen/util.rs +++ /dev/null @@ -1,238 +0,0 @@ -use crate::syntax::{ast::App, Context}; -use core::sync::atomic::{AtomicUsize, Ordering}; -use proc_macro2::{Span, TokenStream as TokenStream2}; -use quote::quote; -use syn::{Attribute, Ident, PatType}; - -const RTIC_INTERNAL: &str = "__rtic_internal"; - -/// Generates a `Mutex` implementation -pub fn impl_mutex( - app: &App, - cfgs: &[Attribute], - resources_prefix: bool, - name: &Ident, - ty: &TokenStream2, - ceiling: u8, - ptr: &TokenStream2, -) -> TokenStream2 { - let path = if resources_prefix { - quote!(shared_resources::#name) - } else { - quote!(#name) - }; - - let device = &app.args.device; - let masks_name = priority_masks_ident(); - quote!( - #(#cfgs)* - impl<'a> rtic::Mutex for #path<'a> { - type T = #ty; - - #[inline(always)] - fn lock(&mut self, f: impl FnOnce(&mut #ty) -> RTIC_INTERNAL_R) -> RTIC_INTERNAL_R { - /// Priority ceiling - const CEILING: u8 = #ceiling; - - unsafe { - rtic::export::lock( - #ptr, - CEILING, - #device::NVIC_PRIO_BITS, - &#masks_name, - f, - ) - } - } - } - ) -} - -pub fn interrupt_ident() -> Ident { - let span = Span::call_site(); - Ident::new("interrupt", span) -} - -/// Whether `name` is an exception with configurable priority -pub fn is_exception(name: &Ident) -> bool { - let s = name.to_string(); - - matches!( - &*s, - "MemoryManagement" - | "BusFault" - | "UsageFault" - | "SecureFault" - | "SVCall" - | "DebugMonitor" - | "PendSV" - | "SysTick" - ) -} - -/// Mark a name as internal -pub fn mark_internal_name(name: &str) -> Ident { - Ident::new(&format!("{RTIC_INTERNAL}_{name}"), Span::call_site()) -} - -/// Generate an internal identifier for tasks -pub fn internal_task_ident(task: &Ident, ident_name: &str) -> Ident { - mark_internal_name(&format!("{task}_{ident_name}")) -} - -fn link_section_index() -> usize { - static INDEX: AtomicUsize = AtomicUsize::new(0); - - INDEX.fetch_add(1, Ordering::Relaxed) -} - -/// Add `link_section` attribute -pub fn link_section_uninit() -> TokenStream2 { - let section = format!(".uninit.rtic{}", link_section_index()); - - quote!(#[link_section = #section]) -} - -/// Regroups the inputs of a task -/// -/// `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`] -pub fn regroup_inputs( - inputs: &[PatType], -) -> ( - // args e.g. &[`_0`], &[`_0: i32`, `_1: i64`] - Vec, - // tupled e.g. `_0`, `(_0, _1)` - TokenStream2, - // untupled e.g. &[`_0`], &[`_0`, `_1`] - Vec, - // ty e.g. `Foo`, `(i32, i64)` - TokenStream2, -) { - if inputs.len() == 1 { - let ty = &inputs[0].ty; - - ( - vec![quote!(_0: #ty)], - quote!(_0), - vec![quote!(_0)], - quote!(#ty), - ) - } else { - let mut args = vec![]; - let mut pats = vec![]; - let mut tys = vec![]; - - for (i, input) in inputs.iter().enumerate() { - let i = Ident::new(&format!("_{}", i), Span::call_site()); - let ty = &input.ty; - - args.push(quote!(#i: #ty)); - - pats.push(quote!(#i)); - - tys.push(quote!(#ty)); - } - - let tupled = { - let pats = pats.clone(); - quote!((#(#pats,)*)) - }; - let ty = quote!((#(#tys,)*)); - (args, tupled, pats, ty) - } -} - -/// Get the ident for the name of the task -pub fn get_task_name(ctxt: Context, app: &App) -> Ident { - let s = match ctxt { - Context::Init => app.init.name.to_string(), - Context::Idle => app - .idle - .as_ref() - .expect("RTIC-ICE: unable to find idle name") - .name - .to_string(), - Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), - }; - - Ident::new(&s, Span::call_site()) -} - -/// Generates a pre-reexport identifier for the "shared resources" struct -pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident { - let mut s = match ctxt { - Context::Init => app.init.name.to_string(), - Context::Idle => app - .idle - .as_ref() - .expect("RTIC-ICE: unable to find idle name") - .name - .to_string(), - Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), - }; - - s.push_str("SharedResources"); - - mark_internal_name(&s) -} - -/// Generates a pre-reexport identifier for the "local resources" struct -pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { - let mut s = match ctxt { - Context::Init => app.init.name.to_string(), - Context::Idle => app - .idle - .as_ref() - .expect("RTIC-ICE: unable to find idle name") - .name - .to_string(), - Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), - }; - - s.push_str("LocalResources"); - - mark_internal_name(&s) -} - -/// Suffixed identifier -pub fn suffixed(name: &str) -> Ident { - let span = Span::call_site(); - Ident::new(name, span) -} - -pub fn static_shared_resource_ident(name: &Ident) -> Ident { - mark_internal_name(&format!("shared_resource_{name}")) -} - -/// Generates an Ident for the number of 32 bit chunks used for Mask storage. -pub fn priority_mask_chunks_ident() -> Ident { - mark_internal_name("MASK_CHUNKS") -} - -pub fn priority_masks_ident() -> Ident { - mark_internal_name("MASKS") -} - -pub fn static_local_resource_ident(name: &Ident) -> Ident { - mark_internal_name(&format!("local_resource_{name}")) -} - -pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) -> Ident { - mark_internal_name(&format!("local_{task_name}_{name}")) -} - -pub fn need_to_lock_ident(name: &Ident) -> Ident { - Ident::new(&format!("{name}_that_needs_to_be_locked"), name.span()) -} - -pub fn zero_prio_dispatcher_ident() -> Ident { - Ident::new("__rtic_internal_async_0_prio_dispatcher", Span::call_site()) -} - -/// The name to get better RT flag errors -pub fn rt_err_ident() -> Ident { - Ident::new( - "you_must_enable_the_rt_feature_for_the_pac_in_your_cargo_toml", - Span::call_site(), - ) -} -- cgit v1.2.3