diff options
author | 2021-08-19 21:32:12 +0200 | |
---|---|---|
committer | 2021-08-20 08:12:13 +0200 | |
commit | cdbd8a2cede668e1181030bd7c439592a8f0e980 (patch) | |
tree | c39efb7e0259faef3f9ca03ac87b9d525c1e6093 /macros/src/codegen/util.rs | |
parent | 3bf5a4f7a06fdb5d341d900c3e937d4c9afd2dda (diff) | |
download | rtic-cdbd8a2cede668e1181030bd7c439592a8f0e980.tar.gz rtic-cdbd8a2cede668e1181030bd7c439592a8f0e980.tar.zst rtic-cdbd8a2cede668e1181030bd7c439592a8f0e980.zip |
Use `mark_internal_name` by default for methods in `util` to make usage of these functions more straightforward.
fq_ident is always internal
rq_ident is always internal
monotonic_ident is always internal
inputs_ident is always internal
local_resources_ident is always internal
shared_resources_ident is always internal
monotonic_instants_ident is always internal
tq_ident is always internal
timer_queue_marker_ident is always internal
static_shared_resource_ident is always internal
static_local_resource_ident is always internal
declared_static_local_resource_ident is always internal
Only names, not idents, are now marked as internal
Use same rtic internal everywhere
Diffstat (limited to 'macros/src/codegen/util.rs')
-rw-r--r-- | macros/src/codegen/util.rs | 81 |
1 files changed, 30 insertions, 51 deletions
diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index c2330d46..8e40ad61 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -7,6 +7,8 @@ use syn::{Attribute, Ident, LitInt, PatType}; use crate::check::Extra; +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()) @@ -14,7 +16,7 @@ pub fn capacity_literal(capacity: usize) -> LitInt { /// Identifier for the free queue pub fn fq_ident(task: &Ident) -> Ident { - Ident::new(&format!("{}_FQ", task.to_string()), Span::call_site()) + mark_internal_name(&format!("{}_FQ", task.to_string())) } /// Generates a `Mutex` implementation @@ -60,15 +62,12 @@ pub fn impl_mutex( /// Generates an identifier for the `INPUTS` buffer (`spawn` & `schedule` API) pub fn inputs_ident(task: &Ident) -> Ident { - Ident::new(&format!("{}_INPUTS", task), Span::call_site()) + mark_internal_name(&format!("{}_INPUTS", task)) } /// Generates an identifier for the `INSTANTS` buffer (`schedule` API) pub fn monotonic_instants_ident(task: &Ident, monotonic: &Ident) -> Ident { - Ident::new( - &format!("{}_{}_INSTANTS", task, monotonic), - Span::call_site(), - ) + mark_internal_name(&format!("{}_{}_INSTANTS", task, monotonic)) } pub fn interrupt_ident() -> Ident { @@ -77,8 +76,7 @@ pub fn interrupt_ident() -> Ident { } pub fn timer_queue_marker_ident() -> Ident { - let span = Span::call_site(); - Ident::new("TIMER_QUEUE_MARKER", span) + mark_internal_name(&"TIMER_QUEUE_MARKER") } /// Whether `name` is an exception with configurable priority @@ -98,38 +96,24 @@ 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()) +} + /// Generate an internal identifier for monotonics pub fn internal_monotonics_ident(task: &Ident, monotonic: &Ident, ident_name: &str) -> Ident { - Ident::new( - &format!( - "__rtic_internal_{}_{}_{}", - task.to_string(), - monotonic.to_string(), - ident_name, - ), - Span::call_site(), - ) + mark_internal_name(&format!( + "{}_{}_{}", + task.to_string(), + monotonic.to_string(), + ident_name, + )) } /// Generate an internal identifier for tasks pub fn internal_task_ident(task: &Ident, ident_name: &str) -> Ident { - Ident::new( - &format!("__rtic_internal_{}_{}", task.to_string(), ident_name,), - Span::call_site(), - ) -} - -/// Mark an ident as internal -pub fn mark_internal_ident(ident: &Ident) -> Ident { - Ident::new( - &format!("__rtic_internal_{}", ident.to_string()), - Span::call_site(), - ) -} - -/// Mark an ident as internal -pub fn mark_internal_name(name: &str) -> Ident { - Ident::new(&format!("__rtic_internal_{}", name), Span::call_site()) + mark_internal_name(&format!("{}_{}", task.to_string(), ident_name)) } fn link_section_index() -> usize { @@ -215,7 +199,7 @@ pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident { s.push_str("SharedResources"); - Ident::new(&s, Span::call_site()) + mark_internal_name(&s) } /// Generates a pre-reexport identifier for the "local resources" struct @@ -228,7 +212,7 @@ pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { s.push_str("LocalResources"); - Ident::new(&s, Span::call_site()) + mark_internal_name(&s) } /// Generates an identifier for a ready queue @@ -236,7 +220,7 @@ pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { /// There may be several task dispatchers, one for each priority level. /// The ready queues are SPSC queues pub fn rq_ident(priority: u8) -> Ident { - Ident::new(&format!("P{}_RQ", priority), Span::call_site()) + mark_internal_name(&format!("P{}_RQ", priority)) } /// Generates an identifier for the `enum` of `schedule`-able tasks @@ -260,33 +244,28 @@ pub fn suffixed(name: &str) -> Ident { /// Generates an identifier for a timer queue pub fn tq_ident(name: &str) -> Ident { - Ident::new(&format!("TQ_{}", name), Span::call_site()) + mark_internal_name(&format!("TQ_{}", name)) } /// Generates an identifier for monotonic timer storage pub fn monotonic_ident(name: &str) -> Ident { - Ident::new(&format!("MONOTONIC_STORAGE_{}", name), Span::call_site()) + mark_internal_name(&format!("MONOTONIC_STORAGE_{}", name)) } pub fn static_shared_resource_ident(name: &Ident) -> Ident { - Ident::new( - &format!("shared_resource_{}", name.to_string()), - Span::call_site(), - ) + mark_internal_name(&format!("shared_resource_{}", name.to_string())) } pub fn static_local_resource_ident(name: &Ident) -> Ident { - Ident::new( - &format!("local_resource_{}", name.to_string()), - Span::call_site(), - ) + mark_internal_name(&format!("local_resource_{}", name.to_string())) } pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) -> Ident { - Ident::new( - &format!("local_{}_{}", task_name.to_string(), name.to_string()), - Span::call_site(), - ) + mark_internal_name(&format!( + "local_{}_{}", + task_name.to_string(), + name.to_string() + )) } /// The name to get better RT flag errors |