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/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 +++-- 10 files changed, 533 insertions(+), 398 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/codegen') 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 From ef5307d83a1d62df0569d78db75d4006147c927d Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Tue, 6 Jul 2021 22:47:48 +0200 Subject: Minimal app now compiles --- macros/src/codegen/dispatchers.rs | 12 +-- macros/src/codegen/hardware_tasks.rs | 48 +++++---- macros/src/codegen/idle.rs | 29 +++--- macros/src/codegen/init.rs | 130 ++++++++++++++--------- macros/src/codegen/local_resources.rs | 145 ++++++-------------------- macros/src/codegen/local_resources_struct.rs | 4 +- macros/src/codegen/module.rs | 69 ++++++------ macros/src/codegen/post_init.rs | 51 +++++---- macros/src/codegen/pre_init.rs | 2 +- macros/src/codegen/shared_resources.rs | 84 ++++----------- macros/src/codegen/shared_resources_struct.rs | 6 +- macros/src/codegen/software_tasks.rs | 25 +++-- macros/src/codegen/util.rs | 16 ++- 13 files changed, 276 insertions(+), 345 deletions(-) (limited to 'macros/src/codegen') diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs index dfa52d5..1c31195 100644 --- a/macros/src/codegen/dispatchers.rs +++ b/macros/src/codegen/dispatchers.rs @@ -76,11 +76,12 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec Vec ! { + fn #name(#context: #name::Context) -> ! { use rtic::Mutex as _; use rtic::mutex_prelude::*; @@ -74,9 +71,7 @@ pub fn codegen( } )); - let locals_new = locals_new.iter(); let call_idle = quote!(#name( - #(#locals_new,)* #name::Context::new(&rtic::export::Priority::new(0)) )); diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index fe8a126..e3f7408 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -5,7 +5,7 @@ use rtic_syntax::{ast::App, Context}; use crate::{ analyze::Analysis, check::Extra, - codegen::{locals, module, resources_struct}, + codegen::{local_resources_struct, module}, }; type CodegenResult = ( @@ -18,68 +18,96 @@ type CodegenResult = ( // - the `${init}` module, which contains types like `${init}::Context` Vec, // user_init -- the `#[init]` function written by the user - Option, - // call_init -- the call to the user `#[init]` if there's one - Option, + TokenStream2, + // call_init -- the call to the user `#[init]` + TokenStream2, ); /// Generates support code for `#[init]` functions pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { - if !app.inits.is_empty() { - let init = &app.inits.first().unwrap(); - let mut needs_lt = false; - let name = &init.name; + let init = &app.init; + let mut needs_lt = false; + let name = &init.name; - let mut root_init = vec![]; + let mut root_init = vec![]; - let mut locals_pat = None; - let mut locals_new = None; - if !init.locals.is_empty() { - let (struct_, pat) = locals::codegen(Context::Init, &init.locals, app); + // TODO: Fix locals + // let mut locals_pat = None; + // let mut locals_new = None; + // if !init.locals.is_empty() { + // let (struct_, pat) = locals::codegen(Context::Init, &init.locals, app); - locals_new = Some(quote!(#name::Locals::new())); - locals_pat = Some(pat); - root_init.push(struct_); - } + // locals_new = Some(quote!(#name::Locals::new())); + // locals_pat = Some(pat); + // root_init.push(struct_); + // } - let context = &init.context; - let attrs = &init.attrs; - let stmts = &init.stmts; - let locals_pat = locals_pat.iter(); + let context = &init.context; + let attrs = &init.attrs; + let stmts = &init.stmts; + let shared = &init.user_shared_struct; + let local = &init.user_local_struct; - let user_init_return = quote! {#name::LateResources, #name::Monotonics}; + let shared_resources: Vec<_> = app + .shared_resources + .iter() + .map(|(k, v)| { + let ty = &v.ty; + let cfgs = &v.cfgs; + quote!( + #(#cfgs)* + #k: #ty, + ) + }) + .collect(); + let local_resources: Vec<_> = app + .local_resources + .iter() + .map(|(k, v)| { + let ty = &v.ty; + let cfgs = &v.cfgs; + quote!( + #(#cfgs)* + #k: #ty, + ) + }) + .collect(); + root_init.push(quote! { + struct #shared { + #(#shared_resources)* + } - let user_init = Some(quote!( - #(#attrs)* - #[allow(non_snake_case)] - fn #name(#(#locals_pat,)* #context: #name::Context) -> (#user_init_return) { - #(#stmts)* - } - )); + struct #local { + #(#local_resources)* + } + }); - let mut mod_app = None; - if !init.args.resources.is_empty() { - let (item, constructor) = resources_struct::codegen(Context::Init, &mut needs_lt, app); + // let locals_pat = locals_pat.iter(); - root_init.push(item); - mod_app = Some(constructor); + let user_init_return = quote! {#shared, #local, #name::Monotonics}; + + let user_init = quote!( + #(#attrs)* + #[allow(non_snake_case)] + fn #name(#context: #name::Context) -> (#user_init_return) { + #(#stmts)* } + ); + + let mut mod_app = None; + + // let locals_new = locals_new.iter(); + let call_init = quote! { + let (shared_resources, local_resources, mut monotonics) = #name(#name::Context::new(core.into())); + }; + + root_init.push(module::codegen( + Context::Init, + needs_lt, + app, + analysis, + extra, + )); - let locals_new = locals_new.iter(); - let call_init = Some( - quote!(let (late, mut monotonics) = #name(#(#locals_new,)* #name::Context::new(core.into()));), - ); - - root_init.push(module::codegen( - Context::Init, - needs_lt, - app, - analysis, - extra, - )); - - (mod_app, root_init, user_init, call_init) - } else { - (None, vec![], None, None) - } + (mod_app, root_init, user_init, call_init) } diff --git a/macros/src/codegen/local_resources.rs b/macros/src/codegen/local_resources.rs index dd3cbb4..13891f9 100644 --- a/macros/src/codegen/local_resources.rs +++ b/macros/src/codegen/local_resources.rs @@ -1,10 +1,12 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use rtic_syntax::{analyze::Ownership, ast::App}; +use rtic_syntax::ast::App; use crate::{analyze::Analysis, check::Extra, codegen::util}; /// Generates `local` variables and local resource proxies +/// +/// I.e. the `static` variables and theirs proxies. pub fn codegen( app: &App, analysis: &Analysis, @@ -16,131 +18,42 @@ pub fn codegen( TokenStream2, ) { let mut mod_app = vec![]; - let mut mod_resources = vec![]; + // let mut mod_resources: _ = vec![]; - for (name, res) in app.local_resources { + // All local resources declared in the `#[local]' struct + 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); + let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); - { - // late resources in `util::link_section_uninit` - let section = if expr.is_none() { - util::link_section_uninit(true) - } else { - None - }; + let ty = quote!(rtic::RacyCell>); + let expr = quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())); - // 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; + // late resources in `util::link_section_uninit` + let section = util::link_section_uninit(true); - 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, - )); - } + mod_app.push(quote!( + #[allow(non_upper_case_globals)] + // #[doc = #doc] + #[doc(hidden)] + #(#attrs)* + #(#cfgs)* + #section + static #mangled_name: #ty = #expr; + )); } - let mod_resources = if mod_resources.is_empty() { - quote!() - } else { - quote!(mod resources { - use rtic::export::Priority; - - #(#mod_resources)* - }) - }; + // let mod_resources = if mod_resources.is_empty() { + // quote!() + // } else { + // quote!(mod local_resources { + // #(#mod_resources)* + // }) + // }; - (mod_app, mod_resources) + (mod_app, TokenStream2::new()) } diff --git a/macros/src/codegen/local_resources_struct.rs b/macros/src/codegen/local_resources_struct.rs index 3016f37..14706a5 100644 --- a/macros/src/codegen/local_resources_struct.rs +++ b/macros/src/codegen/local_resources_struct.rs @@ -10,7 +10,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, let resources = match ctxt { Context::Init => &app.init.args.local_resources, - Context::Idle => &app.idle.unwrap().args.local_resources, + Context::Idle => &app.idle.as_ref().unwrap().args.local_resources, Context::HardwareTask(name) => &app.hardware_tasks[name].args.local_resources, Context::SoftwareTask(name) => &app.software_tasks[name].args.local_resources, }; @@ -33,7 +33,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, }; let ty = &res.ty; - let mangled_name = util::mark_internal_ident(&name); + let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); fields.push(quote!( #(#cfgs)* diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index a3d3fab..adf64d5 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -56,16 +56,39 @@ pub fn codegen( Context::SoftwareTask(_) => {} } - if ctxt.has_locals(app) { - let ident = util::locals_ident(ctxt, app); + // if ctxt.has_locals(app) { + // let ident = util::locals_ident(ctxt, app); + // module_items.push(quote!( + // #[doc(inline)] + // pub use super::#ident as Locals; + // )); + // } + + if ctxt.has_local_resources(app) { + let ident = util::local_resources_ident(ctxt, app); + let ident = util::mark_internal_ident(&ident); + let lt = if resources_tick { + lt = Some(quote!('a)); + Some(quote!('a)) + } else { + None + }; + module_items.push(quote!( #[doc(inline)] - pub use super::#ident as Locals; + pub use super::#ident as LocalResources; + )); + + fields.push(quote!( + /// Local Resources this task has access to + pub local: #name::LocalResources<#lt> )); + + values.push(quote!(local: #name::LocalResources::new())); } - if ctxt.has_resources(app) { - let ident = util::resources_ident(ctxt, app); + if ctxt.has_shared_resources(app) { + let ident = util::shared_resources_ident(ctxt, app); let ident = util::mark_internal_ident(&ident); let lt = if resources_tick { lt = Some(quote!('a)); @@ -76,12 +99,12 @@ pub fn codegen( module_items.push(quote!( #[doc(inline)] - pub use super::#ident as Resources; + pub use super::#ident as SharedResources; )); fields.push(quote!( - /// Resources this task has access to - pub resources: #name::Resources<#lt> + /// Shared Resources this task has access to + pub shared: #name::SharedResources<#lt> )); let priority = if ctxt.is_init() { @@ -89,38 +112,10 @@ pub fn codegen( } else { Some(quote!(priority)) }; - values.push(quote!(resources: #name::Resources::new(#priority))); + values.push(quote!(shared: #name::SharedResources::new(#priority))); } if let Context::Init = ctxt { - let late_fields = analysis - .late_resources - .iter() - .flat_map(|resources| { - resources.iter().map(|name| { - let ty = &app.late_resources[name].ty; - let cfgs = &app.late_resources[name].cfgs; - - quote!( - #(#cfgs)* - pub #name: #ty - ) - }) - }) - .collect::>(); - - let internal_late_ident = util::mark_internal_name("LateResources"); - items.push(quote!( - /// Resources initialized at runtime - #[allow(non_snake_case)] - pub struct #internal_late_ident { - #(#late_fields),* - } - )); - module_items.push(quote!( - pub use super::#internal_late_ident as LateResources; - )); - let monotonic_types: Vec<_> = app .monotonics .iter() diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs index 78548bc..161068d 100644 --- a/macros/src/codegen/post_init.rs +++ b/macros/src/codegen/post_init.rs @@ -9,24 +9,39 @@ use crate::{analyze::Analysis, codegen::util}; pub fn codegen(app: &App, analysis: &Analysis) -> Vec { let mut stmts = vec![]; - // Initialize late resources - if !analysis.late_resources.is_empty() { - // BTreeSet wrapped in a vector - for name in analysis.late_resources.first().unwrap() { - let mangled_name = util::mark_internal_ident(&name); - // If it's live - let cfgs = app.late_resources[name].cfgs.clone(); - if analysis.locations.get(name).is_some() { - stmts.push(quote!( - // We include the cfgs - #(#cfgs)* - // Late resource is a RacyCell> - // - `get_mut_unchecked` to obtain `MaybeUninit` - // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit` - // - `write` the defined value for the late resource T - #mangled_name.get_mut_unchecked().as_mut_ptr().write(late.#name); - )); - } + // Initialize shared resources + for (name, res) in &app.shared_resources { + let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(name)); + // If it's live + let cfgs = res.cfgs.clone(); + if analysis.shared_resource_locations.get(name).is_some() { + stmts.push(quote!( + // We include the cfgs + #(#cfgs)* + // Resource is a RacyCell> + // - `get_mut_unchecked` to obtain `MaybeUninit` + // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit` + // - `write` the defined value for the late resource T + #mangled_name.get_mut_unchecked().as_mut_ptr().write(shared_resources.#name); + )); + } + } + + // Initialize local resources + for (name, res) in &app.local_resources { + let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); + // If it's live + let cfgs = res.cfgs.clone(); + if analysis.local_resource_locations.get(name).is_some() { + stmts.push(quote!( + // We include the cfgs + #(#cfgs)* + // Resource is a RacyCell> + // - `get_mut_unchecked` to obtain `MaybeUninit` + // - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit` + // - `write` the defined value for the late resource T + #mangled_name.get_mut_unchecked().as_mut_ptr().write(local_resources.#name); + )); } } diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs index 531deba..ae628f6 100644 --- a/macros/src/codegen/pre_init.rs +++ b/macros/src/codegen/pre_init.rs @@ -126,7 +126,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec), - quote!(rtic::RacyCell::new(#expr)), - ) - } else { - // late resource - ( - quote!(rtic::RacyCell>), - quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())), - ) - }; + let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(&name)); - let attrs = &res.attrs; + // late resources in `util::link_section_uninit` + let section = util::link_section_uninit(true); + 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; - )); - } + // 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: rtic::RacyCell> = rtic::RacyCell::new(core::mem::MaybeUninit::uninit()); + )); - let r_prop = &res.properties; // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); - if !r_prop.task_local && !r_prop.lock_free { + if !res.properties.lock_free { mod_resources.push(quote!( // #[doc = #doc] #[doc(hidden)] @@ -89,25 +66,10 @@ pub fn codegen( } )); - 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 ptr = quote!( + #(#cfgs)* + #mangled_name.get_mut_unchecked().as_mut_ptr() + ); let ceiling = match analysis.ownerships.get(name) { Some(Ownership::Owned { priority }) => *priority, @@ -123,7 +85,7 @@ pub fn codegen( extra, cfgs, true, - name, + &name, quote!(#ty), ceiling, ptr, @@ -134,7 +96,7 @@ pub fn codegen( let mod_resources = if mod_resources.is_empty() { quote!() } else { - quote!(mod resources { + quote!(mod shared_resources { use rtic::export::Priority; #(#mod_resources)* diff --git a/macros/src/codegen/shared_resources_struct.rs b/macros/src/codegen/shared_resources_struct.rs index 4bdc8fa..df7f38d 100644 --- a/macros/src/codegen/shared_resources_struct.rs +++ b/macros/src/codegen/shared_resources_struct.rs @@ -10,7 +10,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, let resources = match ctxt { Context::Init => unreachable!("Tried to generate shared resources struct for init"), - Context::Idle => &app.idle.unwrap().args.shared_resources, + Context::Idle => &app.idle.as_ref().unwrap().args.shared_resources, Context::HardwareTask(name) => &app.hardware_tasks[name].args.shared_resources, Context::SoftwareTask(name) => &app.software_tasks[name].args.shared_resources, }; @@ -48,12 +48,12 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, fields.push(quote!( #(#cfgs)* - pub #name: resources::#name<'a> + pub #name: shared_resources::#name<'a> )); values.push(quote!( #(#cfgs)* - #name: resources::#name::new(priority) + #name: shared_resources::#name::new(priority) )); diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 0372e8e..da594e7 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -5,7 +5,7 @@ use rtic_syntax::{ast::App, Context}; use crate::{ analyze::Analysis, check::Extra, - codegen::{locals, module, resources_struct, util}, + codegen::{local_resources_struct, module, shared_resources_struct, util}, }; pub fn codegen( @@ -91,35 +91,38 @@ pub fn codegen( // `${task}Resources` let mut needs_lt = false; - if !task.args.resources.is_empty() { + + // TODO: Fix locals + // `${task}Locals` + if !task.args.local_resources.is_empty() { let (item, constructor) = - resources_struct::codegen(Context::SoftwareTask(name), &mut needs_lt, app); + local_resources_struct::codegen(Context::SoftwareTask(name), &mut needs_lt, app); root.push(item); mod_app.push(constructor); } - // `${task}Locals` - let mut locals_pat = None; - if !task.locals.is_empty() { - let (struct_, pat) = locals::codegen(Context::SoftwareTask(name), &task.locals, app); + if !task.args.shared_resources.is_empty() { + let (item, constructor) = + shared_resources_struct::codegen(Context::SoftwareTask(name), &mut needs_lt, app); - locals_pat = Some(pat); - root.push(struct_); + root.push(item); + + mod_app.push(constructor); } + if !&task.is_extern { let context = &task.context; let attrs = &task.attrs; let cfgs = &task.cfgs; let stmts = &task.stmts; - let locals_pat = locals_pat.iter(); user_tasks.push(quote!( #(#attrs)* #(#cfgs)* #[allow(non_snake_case)] - fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) { + fn #name(#context: #name::Context #(,#inputs)*) { use rtic::Mutex as _; use rtic::mutex_prelude::*; diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 21b3141..dd0fb6d 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -41,7 +41,7 @@ pub fn impl_mutex( ptr: TokenStream2, ) -> TokenStream2 { let (path, priority) = if resources_prefix { - (quote!(resources::#name), quote!(self.priority())) + (quote!(shared_resources::#name), quote!(self.priority())) } else { (quote!(#name), quote!(self.priority)) }; @@ -167,7 +167,7 @@ pub fn link_section_uninit(empty_expr: bool) -> Option { pub fn locals_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::Idle => app.idle.as_ref().unwrap().name.to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; @@ -229,7 +229,7 @@ pub fn regroup_inputs( 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.unwrap().name.to_string(), + Context::Idle => app.idle.as_ref().unwrap().name.to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; @@ -242,7 +242,7 @@ 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.unwrap().name.to_string(), + Context::Idle => app.idle.as_ref().unwrap().name.to_string(), Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), }; @@ -288,6 +288,14 @@ pub fn monotonic_ident(name: &str) -> Ident { Ident::new(&format!("MONOTONIC_STORAGE_{}", name), Span::call_site()) } +pub fn static_shared_resource_ident(name: &Ident) -> Ident { + Ident::new(&format!("shared_{}", name.to_string()), Span::call_site()) +} + +pub fn static_local_resource_ident(name: &Ident) -> Ident { + Ident::new(&format!("local_{}", name.to_string()), Span::call_site()) +} + /// The name to get better RT flag errors pub fn rt_err_ident() -> Ident { Ident::new( -- cgit v1.2.3 From d7393c5b27fc95f3569d12137ee0c4d03ff7e2ba Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 7 Jul 2021 21:03:56 +0200 Subject: Full local resource syntax working --- macros/src/codegen/hardware_tasks.rs | 31 +++++++++++++--------------- macros/src/codegen/idle.rs | 31 +++++++++++++++------------- macros/src/codegen/init.rs | 15 ++++++++++++-- macros/src/codegen/local_resources.rs | 31 +++++++++++++++++++++------- macros/src/codegen/local_resources_struct.rs | 24 ++++++++++++++++----- macros/src/codegen/module.rs | 7 ++++--- macros/src/codegen/software_tasks.rs | 22 +++++++++++++------- macros/src/codegen/util.rs | 13 ------------ 8 files changed, 105 insertions(+), 69 deletions(-) (limited to 'macros/src/codegen') diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index a69f9c9..c7f3e7d 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -57,13 +57,17 @@ pub fn codegen( } )); - let mut needs_lt = false; + let mut shared_needs_lt = false; + let mut local_needs_lt = false; // TODO: Fix locals // `${task}Locals` if !task.args.local_resources.is_empty() { - let (item, constructor) = - local_resources_struct::codegen(Context::HardwareTask(name), &mut needs_lt, app); + let (item, constructor) = local_resources_struct::codegen( + Context::HardwareTask(name), + &mut local_needs_lt, + app, + ); root.push(item); @@ -72,8 +76,11 @@ pub fn codegen( // `${task}Resources` if !task.args.shared_resources.is_empty() { - let (item, constructor) = - shared_resources_struct::codegen(Context::HardwareTask(name), &mut needs_lt, app); + let (item, constructor) = shared_resources_struct::codegen( + Context::HardwareTask(name), + &mut shared_needs_lt, + app, + ); root.push(item); @@ -82,23 +89,13 @@ pub fn codegen( root.push(module::codegen( Context::HardwareTask(name), - needs_lt, + shared_needs_lt, + local_needs_lt, app, analysis, extra, )); - // TODO: Fix locals - // // `${task}Locals` - // let mut locals_pat = None; - // if !task.locals.is_empty() { - // let (struct_, pat) = - // local_resources_struct::codegen(Context::HardwareTask(name), &task.locals, app); - - // root.push(struct_); - // locals_pat = Some(pat); - // } - if !task.is_extern { let attrs = &task.attrs; let context = &task.context; diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs index 9c8a5f7..d653931 100644 --- a/macros/src/codegen/idle.rs +++ b/macros/src/codegen/idle.rs @@ -15,7 +15,7 @@ pub fn codegen( extra: &Extra, ) -> ( // mod_app_idle -- the `${idle}Resources` constructor - Option, + Vec, // root_idle -- items that must be placed in the root of the crate: // - the `${idle}Locals` struct // - the `${idle}Resources` struct @@ -27,31 +27,34 @@ pub fn codegen( TokenStream2, ) { if let Some(idle) = &app.idle { - let mut needs_lt = false; - let mut mod_app = None; + let mut shared_needs_lt = false; + let mut local_needs_lt = false; + let mut mod_app = vec![]; let mut root_idle = vec![]; let name = &idle.name; if !idle.args.shared_resources.is_empty() { - let (item, constructor) = shared_resources_struct::codegen(Context::Idle, &mut needs_lt, app); + let (item, constructor) = + shared_resources_struct::codegen(Context::Idle, &mut shared_needs_lt, app); root_idle.push(item); - mod_app = Some(constructor); + mod_app.push(constructor); } - // TODO: Fix locals - // if !idle.locals.is_empty() { - // let (locals, pat) = locals::codegen(Context::Idle, &idle.locals, app); + if !idle.args.local_resources.is_empty() { + let (item, constructor) = + local_resources_struct::codegen(Context::Idle, &mut local_needs_lt, app); - // locals_new = Some(quote!(#name::Locals::new())); - // locals_pat = Some(pat); - // root_idle.push(locals); - // } + root_idle.push(item); + + mod_app.push(constructor); + } root_idle.push(module::codegen( Context::Idle, - needs_lt, + shared_needs_lt, + local_needs_lt, app, analysis, extra, @@ -78,7 +81,7 @@ pub fn codegen( (mod_app, root_idle, user_idle, call_idle) } else { ( - None, + vec![], vec![], None, quote!(loop { diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index e3f7408..1bea7b7 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -26,7 +26,7 @@ type CodegenResult = ( /// Generates support code for `#[init]` functions pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { let init = &app.init; - let mut needs_lt = false; + let mut local_needs_lt = false; let name = &init.name; let mut root_init = vec![]; @@ -96,6 +96,16 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { let mut mod_app = None; + // `${task}Locals` + if !init.args.local_resources.is_empty() { + let (item, constructor) = + local_resources_struct::codegen(Context::Init, &mut local_needs_lt, app); + + root_init.push(item); + + mod_app = Some(constructor); + } + // let locals_new = locals_new.iter(); let call_init = quote! { let (shared_resources, local_resources, mut monotonics) = #name(#name::Context::new(core.into())); @@ -103,7 +113,8 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { root_init.push(module::codegen( Context::Init, - needs_lt, + false, + local_needs_lt, app, analysis, extra, diff --git a/macros/src/codegen/local_resources.rs b/macros/src/codegen/local_resources.rs index 13891f9..70f7580 100644 --- a/macros/src/codegen/local_resources.rs +++ b/macros/src/codegen/local_resources.rs @@ -9,8 +9,8 @@ use crate::{analyze::Analysis, check::Extra, codegen::util}; /// I.e. the `static` variables and theirs proxies. pub fn codegen( app: &App, - analysis: &Analysis, - extra: &Extra, + _analysis: &Analysis, + _extra: &Extra, ) -> ( // mod_app -- the `static` variables behind the proxies Vec, @@ -22,14 +22,10 @@ pub fn codegen( // All local resources declared in the `#[local]' struct 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(&util::static_local_resource_ident(name)); - let ty = quote!(rtic::RacyCell>); - let expr = quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())); - let attrs = &res.attrs; // late resources in `util::link_section_uninit` let section = util::link_section_uninit(true); @@ -43,7 +39,28 @@ pub fn codegen( #(#attrs)* #(#cfgs)* #section - static #mangled_name: #ty = #expr; + static #mangled_name: rtic::RacyCell> = rtic::RacyCell::new(core::mem::MaybeUninit::uninit()); + )); + } + + // All declared `local = [NAME: TY = EXPR]` local resources + for (name, task_local) in app.declared_local_resources() { + let cfgs = &task_local.cfgs; + let ty = &task_local.ty; + let expr = &task_local.expr; + let attrs = &task_local.attrs; + + let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); + + // 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)* + static #mangled_name: rtic::RacyCell<#ty> = rtic::RacyCell::new(#expr); )); } diff --git a/macros/src/codegen/local_resources_struct.rs b/macros/src/codegen/local_resources_struct.rs index 14706a5..0283d52 100644 --- a/macros/src/codegen/local_resources_struct.rs +++ b/macros/src/codegen/local_resources_struct.rs @@ -1,6 +1,9 @@ use proc_macro2::TokenStream as TokenStream2; use quote::quote; -use rtic_syntax::{ast::App, Context}; +use rtic_syntax::{ + ast::{App, TaskLocal}, + Context, +}; use crate::codegen::util; @@ -20,9 +23,15 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, let mut has_cfgs = false; for (name, task_local) in resources { - let res = app.local_resources.get(name).expect("UNREACHABLE"); + let (cfgs, ty, is_declared) = match task_local { + TaskLocal::External => { + let r = app.local_resources.get(name).expect("UNREACHABLE"); + (&r.cfgs, &r.ty, false) + } + TaskLocal::Declared(r) => (&r.cfgs, &r.ty, true), + _ => unreachable!(), + }; - let cfgs = &res.cfgs; has_cfgs |= !cfgs.is_empty(); let lt = if ctxt.runs_once() { @@ -32,7 +41,6 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, quote!('a) }; - let ty = &res.ty; let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); fields.push(quote!( @@ -40,7 +48,13 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, pub #name: &#lt mut #ty )); - let expr = quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr()); + let expr = if is_declared { + // If the local resources is already initialized, we only need to access its value and + // not go through an `MaybeUninit` + quote!(#mangled_name.get_mut_unchecked()) + } else { + quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr()) + }; values.push(quote!( #(#cfgs)* diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index adf64d5..4fba2f3 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -5,7 +5,8 @@ use rtic_syntax::{ast::App, Context}; pub fn codegen( ctxt: Context, - resources_tick: bool, + shared_resources_tick: bool, + local_resources_tick: bool, app: &App, analysis: &Analysis, extra: &Extra, @@ -67,7 +68,7 @@ pub fn codegen( if ctxt.has_local_resources(app) { let ident = util::local_resources_ident(ctxt, app); let ident = util::mark_internal_ident(&ident); - let lt = if resources_tick { + let lt = if local_resources_tick { lt = Some(quote!('a)); Some(quote!('a)) } else { @@ -90,7 +91,7 @@ pub fn codegen( if ctxt.has_shared_resources(app) { let ident = util::shared_resources_ident(ctxt, app); let ident = util::mark_internal_ident(&ident); - let lt = if resources_tick { + let lt = if shared_resources_tick { lt = Some(quote!('a)); Some(quote!('a)) } else { diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index da594e7..6941d9a 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -90,13 +90,16 @@ pub fn codegen( )); // `${task}Resources` - let mut needs_lt = false; + let mut shared_needs_lt = false; + let mut local_needs_lt = false; - // TODO: Fix locals // `${task}Locals` if !task.args.local_resources.is_empty() { - let (item, constructor) = - local_resources_struct::codegen(Context::SoftwareTask(name), &mut needs_lt, app); + let (item, constructor) = local_resources_struct::codegen( + Context::SoftwareTask(name), + &mut local_needs_lt, + app, + ); root.push(item); @@ -104,15 +107,17 @@ pub fn codegen( } if !task.args.shared_resources.is_empty() { - let (item, constructor) = - shared_resources_struct::codegen(Context::SoftwareTask(name), &mut needs_lt, app); + let (item, constructor) = shared_resources_struct::codegen( + Context::SoftwareTask(name), + &mut shared_needs_lt, + app, + ); root.push(item); mod_app.push(constructor); } - if !&task.is_extern { let context = &task.context; let attrs = &task.attrs; @@ -133,7 +138,8 @@ pub fn codegen( root.push(module::codegen( Context::SoftwareTask(name), - needs_lt, + shared_needs_lt, + local_needs_lt, app, analysis, extra, diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index dd0fb6d..e3df207 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -163,19 +163,6 @@ pub fn link_section_uninit(empty_expr: bool) -> Option { Some(quote!(#[link_section = #section])) } -/// 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.init.name.to_string(), - Context::Idle => app.idle.as_ref().unwrap().name.to_string(), - Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(), - }; - - s.push_str("Locals"); - - Ident::new(&s, Span::call_site()) -} - // Regroups the inputs of a task // // `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`] -- cgit v1.2.3 From 98d2af9d73da56910c8bb6cb662fbc4d609a704a Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Wed, 7 Jul 2021 22:50:59 +0200 Subject: Fixing tests --- macros/src/codegen/dispatchers.rs | 7 ------- macros/src/codegen/hardware_tasks.rs | 8 -------- macros/src/codegen/init.rs | 11 ----------- macros/src/codegen/local_resources.rs | 15 +++++--------- macros/src/codegen/local_resources_struct.rs | 10 +++++++++- macros/src/codegen/shared_resources_struct.rs | 2 +- macros/src/codegen/util.rs | 28 +++++++++++++++++++++++++-- 7 files changed, 41 insertions(+), 40 deletions(-) (limited to 'macros/src/codegen') diff --git a/macros/src/codegen/dispatchers.rs b/macros/src/codegen/dispatchers.rs index 1c31195..ac55003 100644 --- a/macros/src/codegen/dispatchers.rs +++ b/macros/src/codegen/dispatchers.rs @@ -76,13 +76,6 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec { diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs index c7f3e7d..e6192e2 100644 --- a/macros/src/codegen/hardware_tasks.rs +++ b/macros/src/codegen/hardware_tasks.rs @@ -29,13 +29,6 @@ pub fn codegen( let mut user_tasks = vec![]; for (name, task) in &app.hardware_tasks { - // TODO: Fix locals - // let locals_new = if task.args.local_resources.is_empty() { - // quote!() - // } else { - // quote!(#name::Locals::new(),) - // }; - let symbol = task.args.binds.clone(); let priority = task.args.priority; let cfgs = &task.cfgs; @@ -60,7 +53,6 @@ pub fn codegen( let mut shared_needs_lt = false; let mut local_needs_lt = false; - // TODO: Fix locals // `${task}Locals` if !task.args.local_resources.is_empty() { let (item, constructor) = local_resources_struct::codegen( diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 1bea7b7..b6d3f72 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -31,17 +31,6 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult { let mut root_init = vec![]; - // TODO: Fix locals - // let mut locals_pat = None; - // let mut locals_new = None; - // if !init.locals.is_empty() { - // let (struct_, pat) = locals::codegen(Context::Init, &init.locals, app); - - // locals_new = Some(quote!(#name::Locals::new())); - // locals_pat = Some(pat); - // root_init.push(struct_); - // } - let context = &init.context; let attrs = &init.attrs; let stmts = &init.stmts; diff --git a/macros/src/codegen/local_resources.rs b/macros/src/codegen/local_resources.rs index 70f7580..c5cddfb 100644 --- a/macros/src/codegen/local_resources.rs +++ b/macros/src/codegen/local_resources.rs @@ -44,13 +44,16 @@ pub fn codegen( } // All declared `local = [NAME: TY = EXPR]` local resources - for (name, task_local) in app.declared_local_resources() { + for (task_name, resource_name, task_local) in app.declared_local_resources() { let cfgs = &task_local.cfgs; let ty = &task_local.ty; let expr = &task_local.expr; let attrs = &task_local.attrs; - let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); + let mangled_name = util::mark_internal_ident(&util::declared_static_local_resource_ident( + resource_name, + &task_name, + )); // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); @@ -64,13 +67,5 @@ pub fn codegen( )); } - // let mod_resources = if mod_resources.is_empty() { - // quote!() - // } else { - // quote!(mod local_resources { - // #(#mod_resources)* - // }) - // }; - (mod_app, TokenStream2::new()) } diff --git a/macros/src/codegen/local_resources_struct.rs b/macros/src/codegen/local_resources_struct.rs index 0283d52..4bd9e2a 100644 --- a/macros/src/codegen/local_resources_struct.rs +++ b/macros/src/codegen/local_resources_struct.rs @@ -18,6 +18,8 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, Context::SoftwareTask(name) => &app.software_tasks[name].args.local_resources, }; + let task_name = util::get_task_name(ctxt, app); + let mut fields = vec![]; let mut values = vec![]; let mut has_cfgs = false; @@ -41,7 +43,13 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, quote!('a) }; - let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name)); + let mangled_name = if matches!(task_local, TaskLocal::External) { + util::mark_internal_ident(&util::static_local_resource_ident(name)) + } else { + util::mark_internal_ident(&util::declared_static_local_resource_ident( + name, &task_name, + )) + }; fields.push(quote!( #(#cfgs)* diff --git a/macros/src/codegen/shared_resources_struct.rs b/macros/src/codegen/shared_resources_struct.rs index df7f38d..301bef7 100644 --- a/macros/src/codegen/shared_resources_struct.rs +++ b/macros/src/codegen/shared_resources_struct.rs @@ -32,7 +32,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, None }; let ty = &res.ty; - let mangled_name = util::mark_internal_ident(&name); + let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(&name)); if !res.properties.lock_free { if access.is_shared() { diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index e3df207..3b0b9e4 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -212,6 +212,17 @@ pub fn regroup_inputs( } } +/// 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().unwrap().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 { @@ -276,11 +287,24 @@ pub fn monotonic_ident(name: &str) -> Ident { } pub fn static_shared_resource_ident(name: &Ident) -> Ident { - Ident::new(&format!("shared_{}", name.to_string()), Span::call_site()) + Ident::new( + &format!("shared_resource_{}", name.to_string()), + Span::call_site(), + ) } pub fn static_local_resource_ident(name: &Ident) -> Ident { - Ident::new(&format!("local_{}", name.to_string()), Span::call_site()) + Ident::new( + &format!("local_resource_{}", name.to_string()), + Span::call_site(), + ) +} + +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(), + ) } /// The name to get better RT flag errors -- cgit v1.2.3 From 8f3704378295fe8007290dbddbc1f4946ac599f9 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Thu, 8 Jul 2021 23:18:44 +0200 Subject: Cleanup from review (needs releases to compile) --- macros/src/codegen/local_resources.rs | 2 +- macros/src/codegen/module.rs | 3 --- macros/src/codegen/shared_resources.rs | 2 +- macros/src/codegen/software_tasks.rs | 2 +- macros/src/codegen/util.rs | 9 ++------- 5 files changed, 5 insertions(+), 13 deletions(-) (limited to 'macros/src/codegen') diff --git a/macros/src/codegen/local_resources.rs b/macros/src/codegen/local_resources.rs index c5cddfb..a9ffa92 100644 --- a/macros/src/codegen/local_resources.rs +++ b/macros/src/codegen/local_resources.rs @@ -28,7 +28,7 @@ pub fn codegen( let attrs = &res.attrs; // late resources in `util::link_section_uninit` - let section = util::link_section_uninit(true); + let section = util::link_section_uninit(); // For future use // let doc = format!(" RTIC internal: {}:{}", file!(), line!()); diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 4fba2f3..a59d662 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -198,9 +198,6 @@ pub fn codegen( pub use super::#internal_context_name as Context; )); - // not sure if this is the right way, maybe its backwards, - // that spawn_module should put in in root - if let Context::SoftwareTask(..) = ctxt { let spawnee = &app.software_tasks[name]; let priority = spawnee.args.priority; diff --git a/macros/src/codegen/shared_resources.rs b/macros/src/codegen/shared_resources.rs index d6336b3..181832f 100644 --- a/macros/src/codegen/shared_resources.rs +++ b/macros/src/codegen/shared_resources.rs @@ -24,7 +24,7 @@ pub fn codegen( let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(&name)); // late resources in `util::link_section_uninit` - let section = util::link_section_uninit(true); + let section = util::link_section_uninit(); let attrs = &res.attrs; // For future use diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs index 6941d9a..cfd21e4 100644 --- a/macros/src/codegen/software_tasks.rs +++ b/macros/src/codegen/software_tasks.rs @@ -45,7 +45,7 @@ pub fn codegen( quote!(rtic::export::Queue(unsafe { rtic::export::iQueue::u8_sc() })), - Box::new(|| util::link_section_uninit(true)), + Box::new(|| util::link_section_uninit()), ) }; mod_app.push(quote!( diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 3b0b9e4..86bd695 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -152,13 +152,8 @@ fn link_section_index() -> usize { } // NOTE `None` means in shared memory -pub fn link_section_uninit(empty_expr: bool) -> Option { - let section = if empty_expr { - let index = link_section_index(); - format!(".uninit.rtic{}", index) - } else { - format!(".uninit.rtic{}", link_section_index()) - }; +pub fn link_section_uninit() -> Option { + let section = format!(".uninit.rtic{}", link_section_index()); Some(quote!(#[link_section = #section])) } -- cgit v1.2.3