From 3f85cb5caf1ae930e6551e139978ceec859a2348 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Mon, 5 Jul 2021 21:40:01 +0200 Subject: Started work --- macros/src/codegen.rs | 7 +- macros/src/codegen/dispatchers.rs | 2 +- macros/src/codegen/hardware_tasks.rs | 4 +- macros/src/codegen/local_resources.rs | 146 +++++++++++++++++++++++++ macros/src/codegen/local_resources_struct.rs | 88 +++++++++++++++ macros/src/codegen/locals.rs | 95 ---------------- macros/src/codegen/resources.rs | 152 -------------------------- macros/src/codegen/resources_struct.rs | 141 ------------------------ macros/src/codegen/shared_resources.rs | 145 ++++++++++++++++++++++++ macros/src/codegen/shared_resources_struct.rs | 131 ++++++++++++++++++++++ macros/src/codegen/util.rs | 27 +++-- 11 files changed, 537 insertions(+), 401 deletions(-) create mode 100644 macros/src/codegen/local_resources.rs create mode 100644 macros/src/codegen/local_resources_struct.rs delete mode 100644 macros/src/codegen/locals.rs delete mode 100644 macros/src/codegen/resources.rs delete mode 100644 macros/src/codegen/resources_struct.rs create mode 100644 macros/src/codegen/shared_resources.rs create mode 100644 macros/src/codegen/shared_resources_struct.rs (limited to 'macros/src') diff --git a/macros/src/codegen.rs b/macros/src/codegen.rs index 113d17f..f6fdf02 100644 --- a/macros/src/codegen.rs +++ b/macros/src/codegen.rs @@ -9,12 +9,13 @@ mod dispatchers; mod hardware_tasks; mod idle; mod init; -mod locals; +mod local_resources; +mod shared_resources; +mod local_resources_struct; +mod shared_resources_struct; mod module; mod post_init; mod pre_init; -mod resources; -mod resources_struct; mod software_tasks; mod timer_queue; mod util; diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs index 65a3f5f..dfa52d5 100644 --- a/macros/src/codegen/dispatchers.rs +++ b/macros/src/codegen/dispatchers.rs @@ -76,7 +76,7 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec ( + // mod_app -- the `static` variables behind the proxies + Vec, + // mod_resources -- the `resources` module + TokenStream2, +) { + let mut mod_app = vec![]; + let mut mod_resources = vec![]; + + for (name, res) in app.local_resources { + // let expr = &res.expr; // TODO: Extract from tasks???... + let cfgs = &res.cfgs; + let ty = &res.ty; + let mangled_name = util::mark_internal_ident(&name); + + { + // late resources in `util::link_section_uninit` + let section = if expr.is_none() { + util::link_section_uninit(true) + } else { + None + }; + + // resource type and assigned value + let (ty, expr) = if let Some(expr) = expr { + // early resource + ( + quote!(rtic::RacyCell<#ty>), + quote!(rtic::RacyCell::new(#expr)), + ) + } else { + // late resource + ( + quote!(rtic::RacyCell>), + quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())), + ) + }; + + let attrs = &res.attrs; + + // For future use + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + mod_app.push(quote!( + #[allow(non_upper_case_globals)] + // #[doc = #doc] + #[doc(hidden)] + #(#attrs)* + #(#cfgs)* + #section + static #mangled_name: #ty = #expr; + )); + } + + let r_prop = &res.properties; + // For future use + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + + if !r_prop.task_local && !r_prop.lock_free { + mod_resources.push(quote!( + // #[doc = #doc] + #[doc(hidden)] + #[allow(non_camel_case_types)] + #(#cfgs)* + pub struct #name<'a> { + priority: &'a Priority, + } + + #(#cfgs)* + impl<'a> #name<'a> { + #[inline(always)] + pub unsafe fn new(priority: &'a Priority) -> Self { + #name { priority } + } + + #[inline(always)] + pub unsafe fn priority(&self) -> &Priority { + self.priority + } + } + )); + + let (ptr, _doc) = if expr.is_none() { + // late resource + ( + quote!( + #(#cfgs)* + #mangled_name.get_mut_unchecked().as_mut_ptr() + ), + "late", + ) + } else { + // early resource + ( + quote!( + #(#cfgs)* + #mangled_name.get_mut_unchecked() + ), + "early", + ) + }; + + let ceiling = match analysis.ownerships.get(name) { + Some(Ownership::Owned { priority }) => *priority, + Some(Ownership::CoOwned { priority }) => *priority, + Some(Ownership::Contended { ceiling }) => *ceiling, + None => 0, + }; + + // For future use + // let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!()); + + mod_app.push(util::impl_mutex( + extra, + cfgs, + true, + name, + quote!(#ty), + ceiling, + ptr, + )); + } + } + + let mod_resources = if mod_resources.is_empty() { + quote!() + } else { + quote!(mod resources { + use rtic::export::Priority; + + #(#mod_resources)* + }) + }; + + (mod_app, mod_resources) +} diff --git a/macros/src/codegen/local_resources_struct.rs b/macros/src/codegen/local_resources_struct.rs new file mode 100644 index 0000000..3016f37 --- /dev/null +++ b/macros/src/codegen/local_resources_struct.rs @@ -0,0 +1,88 @@ +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; +use rtic_syntax::{ast::App, Context}; + +use crate::codegen::util; + +/// Generates local resources structs +pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) { + let mut lt = None; + + let resources = match ctxt { + Context::Init => &app.init.args.local_resources, + Context::Idle => &app.idle.unwrap().args.local_resources, + Context::HardwareTask(name) => &app.hardware_tasks[name].args.local_resources, + Context::SoftwareTask(name) => &app.software_tasks[name].args.local_resources, + }; + + let mut fields = vec![]; + let mut values = vec![]; + let mut has_cfgs = false; + + for (name, task_local) in resources { + let res = app.local_resources.get(name).expect("UNREACHABLE"); + + let cfgs = &res.cfgs; + has_cfgs |= !cfgs.is_empty(); + + let lt = if ctxt.runs_once() { + quote!('static) + } else { + lt = Some(quote!('a)); + quote!('a) + }; + + let ty = &res.ty; + let mangled_name = util::mark_internal_ident(&name); + + fields.push(quote!( + #(#cfgs)* + pub #name: &#lt mut #ty + )); + + let expr = quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr()); + + values.push(quote!( + #(#cfgs)* + #name: #expr + )); + } + + if lt.is_some() { + *needs_lt = true; + + // The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused + if has_cfgs { + fields.push(quote!( + #[doc(hidden)] + pub __marker__: core::marker::PhantomData<&'a ()> + )); + + values.push(quote!(__marker__: core::marker::PhantomData)) + } + } + + let doc = format!("Local resources `{}` has access to", ctxt.ident(app)); + let ident = util::local_resources_ident(ctxt, app); + let ident = util::mark_internal_ident(&ident); + let item = quote!( + #[allow(non_snake_case)] + #[doc = #doc] + pub struct #ident<#lt> { + #(#fields,)* + } + ); + + let constructor = quote!( + impl<#lt> #ident<#lt> { + #[inline(always)] + pub unsafe fn new() -> Self { + #ident { + #(#values,)* + } + } + } + ); + + (item, constructor) +} diff --git a/macros/src/codegen/locals.rs b/macros/src/codegen/locals.rs deleted file mode 100644 index 0fb8c6d..0000000 --- a/macros/src/codegen/locals.rs +++ /dev/null @@ -1,95 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{ - ast::{App, Local}, - Context, Map, -}; - -use crate::codegen::util; - -pub fn codegen( - ctxt: Context, - locals: &Map, - app: &App, -) -> ( - // locals - TokenStream2, - // pat - TokenStream2, -) { - assert!(!locals.is_empty()); - - let runs_once = ctxt.runs_once(); - let ident = util::locals_ident(ctxt, app); - - let mut lt = None; - let mut fields = vec![]; - let mut items = vec![]; - let mut names = vec![]; - let mut values = vec![]; - let mut pats = vec![]; - let mut has_cfgs = false; - - for (name, local) in locals { - let lt = if runs_once { - quote!('static) - } else { - lt = Some(quote!('a)); - quote!('a) - }; - - let cfgs = &local.cfgs; - has_cfgs |= !cfgs.is_empty(); - - let expr = &local.expr; - let ty = &local.ty; - fields.push(quote!( - #(#cfgs)* - #name: &#lt mut #ty - )); - items.push(quote!( - #(#cfgs)* - #[doc(hidden)] - static #name: rtic::RacyCell<#ty> = rtic::RacyCell::new(#expr) - )); - values.push(quote!( - #(#cfgs)* - #name: #name.get_mut_unchecked() - )); - names.push(name); - pats.push(quote!( - #(#cfgs)* - #name - )); - } - - if lt.is_some() && has_cfgs { - fields.push(quote!(__marker__: core::marker::PhantomData<&'a ()>)); - values.push(quote!(__marker__: core::marker::PhantomData)); - } - - let locals = quote!( - #[allow(non_snake_case)] - #[doc(hidden)] - pub struct #ident<#lt> { - #(#fields),* - } - - impl<#lt> #ident<#lt> { - #[inline(always)] - unsafe fn new() -> Self { - #(#items;)* - - #ident { - #(#values),* - } - } - } - ); - - let ident = ctxt.ident(app); - ( - locals, - quote!(#ident::Locals { #(#pats,)* .. }: #ident::Locals), - ) -} diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs deleted file mode 100644 index a623ea6..0000000 --- a/macros/src/codegen/resources.rs +++ /dev/null @@ -1,152 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{analyze::Ownership, ast::App}; - -use crate::{analyze::Analysis, check::Extra, codegen::util}; - -/// Generates `static` variables and resource proxies -/// Early resources are stored in `RacyCell` -/// Late resource are stored in `RacyCell>` -/// -/// Safety: -/// - RacyCell access is `unsafe`. -/// - RacyCell is always written to before user access, thus -// the generated code for user access can safely `assume_init`. -pub fn codegen( - app: &App, - analysis: &Analysis, - extra: &Extra, -) -> ( - // mod_app -- the `static` variables behind the proxies - Vec, - // mod_resources -- the `resources` module - TokenStream2, -) { - let mut mod_app = vec![]; - let mut mod_resources = vec![]; - - for (name, res, expr, _) in app.resources(analysis) { - let cfgs = &res.cfgs; - let ty = &res.ty; - let mangled_name = util::mark_internal_ident(&name); - - { - // late resources in `util::link_section_uninit` - let section = if expr.is_none() { - util::link_section_uninit(true) - } else { - None - }; - - // resource type and assigned value - let (ty, expr) = if let Some(expr) = expr { - // early resource - ( - quote!(rtic::RacyCell<#ty>), - quote!(rtic::RacyCell::new(#expr)), - ) - } else { - // late resource - ( - quote!(rtic::RacyCell>), - quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())), - ) - }; - - let attrs = &res.attrs; - - // For future use - // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - mod_app.push(quote!( - #[allow(non_upper_case_globals)] - // #[doc = #doc] - #[doc(hidden)] - #(#attrs)* - #(#cfgs)* - #section - static #mangled_name: #ty = #expr; - )); - } - - let r_prop = &res.properties; - // For future use - // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - - if !r_prop.task_local && !r_prop.lock_free { - mod_resources.push(quote!( - // #[doc = #doc] - #[doc(hidden)] - #[allow(non_camel_case_types)] - #(#cfgs)* - pub struct #name<'a> { - priority: &'a Priority, - } - - #(#cfgs)* - impl<'a> #name<'a> { - #[inline(always)] - pub unsafe fn new(priority: &'a Priority) -> Self { - #name { priority } - } - - #[inline(always)] - pub unsafe fn priority(&self) -> &Priority { - self.priority - } - } - )); - - let (ptr, _doc) = if expr.is_none() { - // late resource - ( - quote!( - #(#cfgs)* - #mangled_name.get_mut_unchecked().as_mut_ptr() - ), - "late", - ) - } else { - // early resource - ( - quote!( - #(#cfgs)* - #mangled_name.get_mut_unchecked() - ), - "early", - ) - }; - - let ceiling = match analysis.ownerships.get(name) { - Some(Ownership::Owned { priority }) => *priority, - Some(Ownership::CoOwned { priority }) => *priority, - Some(Ownership::Contended { ceiling }) => *ceiling, - None => 0, - }; - - // For future use - // let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!()); - - mod_app.push(util::impl_mutex( - extra, - cfgs, - true, - name, - quote!(#ty), - ceiling, - ptr, - )); - } - } - - let mod_resources = if mod_resources.is_empty() { - quote!() - } else { - quote!(mod resources { - use rtic::export::Priority; - - #(#mod_resources)* - }) - }; - - (mod_app, mod_resources) -} diff --git a/macros/src/codegen/resources_struct.rs b/macros/src/codegen/resources_struct.rs deleted file mode 100644 index 6fe4678..0000000 --- a/macros/src/codegen/resources_struct.rs +++ /dev/null @@ -1,141 +0,0 @@ -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use rtic_syntax::{ast::App, Context}; - -use crate::codegen::util; - -pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) { - let mut lt = None; - - let resources = match ctxt { - Context::Init => &app.inits.first().unwrap().args.resources, - Context::Idle => &app.idles.first().unwrap().args.resources, - Context::HardwareTask(name) => &app.hardware_tasks[name].args.resources, - Context::SoftwareTask(name) => &app.software_tasks[name].args.resources, - }; - - let mut fields = vec![]; - let mut values = vec![]; - let mut has_cfgs = false; - - for (name, access) in resources { - let (res, expr) = app.resource(name).expect("UNREACHABLE"); - - let cfgs = &res.cfgs; - has_cfgs |= !cfgs.is_empty(); - - // access hold if the resource is [x] (exclusive) or [&x] (shared) - let mut_ = if access.is_exclusive() { - Some(quote!(mut)) - } else { - None - }; - let ty = &res.ty; - let mangled_name = util::mark_internal_ident(&name); - - // let ownership = &analysis.ownerships[name]; - let r_prop = &res.properties; - - if !r_prop.task_local && !r_prop.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: resources::#name<'a> - )); - - values.push(quote!( - #(#cfgs)* - #name: resources::#name::new(priority) - - )); - - // continue as the value has been filled, - continue; - } - } else { - let lt = if ctxt.runs_once() { - quote!('static) - } else { - lt = Some(quote!('a)); - quote!('a) - }; - - fields.push(quote!( - #(#cfgs)* - pub #name: &#lt #mut_ #ty - )); - } - - let is_late = expr.is_none(); - if is_late { - let expr = if access.is_exclusive() { - quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr()) - } else { - quote!(&*#mangled_name.get_unchecked().as_ptr()) - }; - - values.push(quote!( - #(#cfgs)* - #name: #expr - )); - } else { - values.push(quote!( - #(#cfgs)* - #name: #mangled_name.get_mut_unchecked() - )); - } - } - - if lt.is_some() { - *needs_lt = true; - - // The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused - if has_cfgs { - fields.push(quote!( - #[doc(hidden)] - pub __marker__: core::marker::PhantomData<&'a ()> - )); - - values.push(quote!(__marker__: core::marker::PhantomData)) - } - } - - let doc = format!("Resources `{}` has access to", ctxt.ident(app)); - let ident = util::resources_ident(ctxt, app); - let ident = util::mark_internal_ident(&ident); - let item = quote!( - #[allow(non_snake_case)] - #[doc = #doc] - pub struct #ident<#lt> { - #(#fields,)* - } - ); - - let arg = if ctxt.is_init() { - None - } else { - Some(quote!(priority: &#lt rtic::export::Priority)) - }; - let constructor = quote!( - impl<#lt> #ident<#lt> { - #[inline(always)] - pub unsafe fn new(#arg) -> Self { - #ident { - #(#values,)* - } - } - } - ); - - (item, constructor) -} diff --git a/macros/src/codegen/shared_resources.rs b/macros/src/codegen/shared_resources.rs new file mode 100644 index 0000000..f6d2dcb --- /dev/null +++ b/macros/src/codegen/shared_resources.rs @@ -0,0 +1,145 @@ +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; +use rtic_syntax::{analyze::Ownership, ast::App}; + +use crate::{analyze::Analysis, check::Extra, codegen::util}; + +/// Generates `static` variables and shared resource proxies +pub fn codegen( + app: &App, + analysis: &Analysis, + extra: &Extra, +) -> ( + // mod_app -- the `static` variables behind the proxies + Vec, + // mod_resources -- the `resources` module + TokenStream2, +) { + let mut mod_app = vec![]; + let mut mod_resources = vec![]; + + for (name, res) in app.shared_resources { + let cfgs = &res.cfgs; + let ty = &res.ty; + let mangled_name = util::mark_internal_ident(&name); + + { + // late resources in `util::link_section_uninit` + let section = if expr.is_none() { + util::link_section_uninit(true) + } else { + None + }; + + // resource type and assigned value + let (ty, expr) = if let Some(expr) = expr { + // early resource + ( + quote!(rtic::RacyCell<#ty>), + quote!(rtic::RacyCell::new(#expr)), + ) + } else { + // late resource + ( + quote!(rtic::RacyCell>), + quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())), + ) + }; + + let attrs = &res.attrs; + + // For future use + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + mod_app.push(quote!( + #[allow(non_upper_case_globals)] + // #[doc = #doc] + #[doc(hidden)] + #(#attrs)* + #(#cfgs)* + #section + static #mangled_name: #ty = #expr; + )); + } + + let r_prop = &res.properties; + // For future use + // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); + + if !r_prop.task_local && !r_prop.lock_free { + mod_resources.push(quote!( + // #[doc = #doc] + #[doc(hidden)] + #[allow(non_camel_case_types)] + #(#cfgs)* + pub struct #name<'a> { + priority: &'a Priority, + } + + #(#cfgs)* + impl<'a> #name<'a> { + #[inline(always)] + pub unsafe fn new(priority: &'a Priority) -> Self { + #name { priority } + } + + #[inline(always)] + pub unsafe fn priority(&self) -> &Priority { + self.priority + } + } + )); + + let (ptr, _doc) = if expr.is_none() { + // late resource + ( + quote!( + #(#cfgs)* + #mangled_name.get_mut_unchecked().as_mut_ptr() + ), + "late", + ) + } else { + // early resource + ( + quote!( + #(#cfgs)* + #mangled_name.get_mut_unchecked() + ), + "early", + ) + }; + + let ceiling = match analysis.ownerships.get(name) { + Some(Ownership::Owned { priority }) => *priority, + Some(Ownership::CoOwned { priority }) => *priority, + Some(Ownership::Contended { ceiling }) => *ceiling, + None => 0, + }; + + // For future use + // let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!()); + + mod_app.push(util::impl_mutex( + extra, + cfgs, + true, + name, + quote!(#ty), + ceiling, + ptr, + )); + } + } + + let mod_resources = if mod_resources.is_empty() { + quote!() + } else { + quote!(mod resources { + use rtic::export::Priority; + + #(#mod_resources)* + }) + }; + + (mod_app, mod_resources) +} diff --git a/macros/src/codegen/shared_resources_struct.rs b/macros/src/codegen/shared_resources_struct.rs new file mode 100644 index 0000000..4bdc8fa --- /dev/null +++ b/macros/src/codegen/shared_resources_struct.rs @@ -0,0 +1,131 @@ +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; +use rtic_syntax::{ast::App, Context}; + +use crate::codegen::util; + +/// Generate shared resources structs +pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) { + let mut lt = None; + + let resources = match ctxt { + Context::Init => unreachable!("Tried to generate shared resources struct for init"), + Context::Idle => &app.idle.unwrap().args.shared_resources, + Context::HardwareTask(name) => &app.hardware_tasks[name].args.shared_resources, + Context::SoftwareTask(name) => &app.software_tasks[name].args.shared_resources, + }; + + let mut fields = vec![]; + let mut values = vec![]; + let mut has_cfgs = false; + + for (name, access) in resources { + let res = app.shared_resources.get(name).expect("UNREACHABLE"); + + let cfgs = &res.cfgs; + has_cfgs |= !cfgs.is_empty(); + + // access hold if the resource is [x] (exclusive) or [&x] (shared) + let mut_ = if access.is_exclusive() { + Some(quote!(mut)) + } else { + None + }; + let ty = &res.ty; + let mangled_name = util::mark_internal_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: resources::#name<'a> + )); + + values.push(quote!( + #(#cfgs)* + #name: resources::#name::new(priority) + + )); + + // continue as the value has been filled, + continue; + } + } else { + let lt = if ctxt.runs_once() { + quote!('static) + } else { + lt = Some(quote!('a)); + quote!('a) + }; + + fields.push(quote!( + #(#cfgs)* + pub #name: &#lt #mut_ #ty + )); + } + + let expr = if access.is_exclusive() { + quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr()) + } else { + quote!(&*#mangled_name.get_unchecked().as_ptr()) + }; + + values.push(quote!( + #(#cfgs)* + #name: #expr + )); + } + + if lt.is_some() { + *needs_lt = true; + + // The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused + if has_cfgs { + fields.push(quote!( + #[doc(hidden)] + pub __marker__: core::marker::PhantomData<&'a ()> + )); + + values.push(quote!(__marker__: core::marker::PhantomData)) + } + } + + let doc = format!("Shared resources `{}` has access to", ctxt.ident(app)); + let ident = util::shared_resources_ident(ctxt, app); + let ident = util::mark_internal_ident(&ident); + let item = quote!( + #[allow(non_snake_case)] + #[doc = #doc] + pub struct #ident<#lt> { + #(#fields,)* + } + ); + + let arg = if ctxt.is_init() { + None + } else { + Some(quote!(priority: &#lt rtic::export::Priority)) + }; + let constructor = quote!( + impl<#lt> #ident<#lt> { + #[inline(always)] + pub unsafe fn new(#arg) -> Self { + #ident { + #(#values,)* + } + } + } + ); + + (item, constructor) +} diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 3e42eda..21b3141 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -166,8 +166,8 @@ pub fn link_section_uninit(empty_expr: bool) -> Option { /// Generates a pre-reexport identifier for the "locals" struct pub fn locals_ident(ctxt: Context, app: &App) -> Ident { let mut s = match ctxt { - Context::Init => app.inits.first().unwrap().name.to_string(), - Context::Idle => app.idles.first().unwrap().name.to_string(), + Context::Init => app.init.name.to_string(), + Context::Idle => app.idle.unwrap().name.to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; @@ -225,15 +225,28 @@ pub fn regroup_inputs( } } -/// Generates a pre-reexport identifier for the "resources" struct -pub fn resources_ident(ctxt: Context, app: &App) -> Ident { +/// 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.inits.first().unwrap().name.to_string(), - Context::Idle => app.idles.first().unwrap().name.to_string(), + Context::Init => app.init.name.to_string(), + Context::Idle => app.idle.unwrap().name.to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; - s.push_str("Resources"); + s.push_str("SharedResources"); + + Ident::new(&s, Span::call_site()) +} + +/// 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.unwrap().name.to_string(), + Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), + }; + + s.push_str("LocalResources"); Ident::new(&s, Span::call_site()) } -- cgit v1.2.3