aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen
diff options
context:
space:
mode:
Diffstat (limited to 'macros/src/codegen')
-rw-r--r--macros/src/codegen/hardware_tasks.rs28
-rw-r--r--macros/src/codegen/idle.rs29
-rw-r--r--macros/src/codegen/init.rs33
-rw-r--r--macros/src/codegen/resources.rs24
-rw-r--r--macros/src/codegen/resources_struct.rs2
-rw-r--r--macros/src/codegen/schedule.rs6
-rw-r--r--macros/src/codegen/software_tasks.rs37
-rw-r--r--macros/src/codegen/spawn.rs4
8 files changed, 123 insertions, 40 deletions
diff --git a/macros/src/codegen/hardware_tasks.rs b/macros/src/codegen/hardware_tasks.rs
index 7f14b5e1..25f1df41 100644
--- a/macros/src/codegen/hardware_tasks.rs
+++ b/macros/src/codegen/hardware_tasks.rs
@@ -1,5 +1,5 @@
use proc_macro2::TokenStream as TokenStream2;
-use quote::quote;
+use quote::{format_ident, quote};
use rtic_syntax::{ast::App, Context};
use crate::{
@@ -14,7 +14,7 @@ pub fn codegen(
analysis: &Analysis,
extra: &Extra,
) -> (
- // const_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors
+ // mod_app_hardware_tasks -- interrupt handlers and `${task}Resources` constructors
Vec<TokenStream2>,
// root_hardware_tasks -- items that must be placed in the root of the crate:
// - `${task}Locals` structs
@@ -23,10 +23,13 @@ pub fn codegen(
Vec<TokenStream2>,
// user_hardware_tasks -- the `#[task]` functions written by the user
Vec<TokenStream2>,
+ // user_hardware_tasks_imports -- the imports for `#[task]` functions written by the user
+ Vec<TokenStream2>,
) {
- let mut const_app = vec![];
+ let mut mod_app = vec![];
let mut root = vec![];
let mut user_tasks = vec![];
+ let mut hardware_tasks_imports = vec![];
for (name, task) in &app.hardware_tasks {
let (let_instant, instant) = if app.uses_schedule() {
@@ -49,7 +52,7 @@ pub fn codegen(
let symbol = task.args.binds.clone();
let priority = task.args.priority;
- const_app.push(quote!(
+ mod_app.push(quote!(
#[allow(non_snake_case)]
#[no_mangle]
unsafe fn #symbol() {
@@ -78,9 +81,16 @@ pub fn codegen(
analysis,
);
+ // Add resources to imports
+ let name_res = format_ident!("{}Resources", name);
+ hardware_tasks_imports.push(quote!(
+ #[allow(non_snake_case)]
+ use super::#name_res;
+ ));
+
root.push(item);
- const_app.push(constructor);
+ mod_app.push(constructor);
}
root.push(module::codegen(
@@ -112,7 +122,13 @@ pub fn codegen(
#(#stmts)*
}
));
+
+ hardware_tasks_imports.push(quote!(
+ #(#attrs)*
+ #[allow(non_snake_case)]
+ use super::#name;
+ ));
}
- (const_app, root, user_tasks)
+ (mod_app, root, user_tasks, hardware_tasks_imports)
}
diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs
index d0bff3e7..2e2932d7 100644
--- a/macros/src/codegen/idle.rs
+++ b/macros/src/codegen/idle.rs
@@ -1,5 +1,5 @@
use proc_macro2::TokenStream as TokenStream2;
-use quote::quote;
+use quote::{format_ident, quote};
use rtic_syntax::{ast::App, Context};
use crate::{
@@ -14,7 +14,7 @@ pub fn codegen(
analysis: &Analysis,
extra: &Extra,
) -> (
- // const_app_idle -- the `${idle}Resources` constructor
+ // mod_app_idle -- the `${idle}Resources` constructor
Option<TokenStream2>,
// root_idle -- items that must be placed in the root of the crate:
// - the `${idle}Locals` struct
@@ -23,26 +23,37 @@ pub fn codegen(
Vec<TokenStream2>,
// user_idle
Option<TokenStream2>,
+ // user_idle_imports
+ Vec<TokenStream2>,
// call_idle
TokenStream2,
) {
if app.idles.len() > 0 {
let idle = &app.idles.first().unwrap();
let mut needs_lt = false;
- let mut const_app = None;
+ let mut mod_app = None;
let mut root_idle = vec![];
let mut locals_pat = None;
let mut locals_new = None;
+ let mut user_idle_imports = vec![];
+
+ let name = &idle.name;
+
if !idle.args.resources.is_empty() {
let (item, constructor) =
resources_struct::codegen(Context::Idle, 0, &mut needs_lt, app, analysis);
root_idle.push(item);
- const_app = Some(constructor);
+ mod_app = Some(constructor);
+
+ let name_resource = format_ident!("{}Resources", name);
+ user_idle_imports.push(quote!(
+ #[allow(non_snake_case)]
+ use super::#name_resource;
+ ));
}
- let name = &idle.name;
if !idle.locals.is_empty() {
let (locals, pat) = locals::codegen(Context::Idle, &idle.locals, app);
@@ -66,6 +77,11 @@ pub fn codegen(
#(#stmts)*
}
));
+ user_idle_imports.push(quote!(
+ #(#attrs)*
+ #[allow(non_snake_case)]
+ use super::#name;
+ ));
let locals_new = locals_new.iter();
let call_idle = quote!(crate::#name(
@@ -73,12 +89,13 @@ pub fn codegen(
#name::Context::new(&rtic::export::Priority::new(0))
));
- (const_app, root_idle, user_idle, call_idle)
+ (mod_app, root_idle, user_idle, user_idle_imports, call_idle)
} else {
(
None,
vec![],
None,
+ vec![],
quote!(loop {
rtic::export::wfi()
}),
diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs
index e0b7d699..77d186e5 100644
--- a/macros/src/codegen/init.rs
+++ b/macros/src/codegen/init.rs
@@ -1,5 +1,5 @@
use proc_macro2::TokenStream as TokenStream2;
-use quote::quote;
+use quote::{format_ident, quote};
use rtic_syntax::{ast::App, Context};
use crate::{
@@ -14,7 +14,7 @@ pub fn codegen(
analysis: &Analysis,
extra: &Extra,
) -> (
- // const_app_idle -- the `${init}Resources` constructor
+ // mod_app_idle -- the `${init}Resources` constructor
Option<TokenStream2>,
// root_init -- items that must be placed in the root of the crate:
// - the `${init}Locals` struct
@@ -24,6 +24,8 @@ pub fn codegen(
Vec<TokenStream2>,
// user_init -- the `#[init]` function written by the user
Option<TokenStream2>,
+ // user_init_imports -- the imports for `#[init]` functio written by the user
+ Vec<TokenStream2>,
// call_init -- the call to the user `#[init]` if there's one
Option<TokenStream2>,
) {
@@ -34,6 +36,8 @@ pub fn codegen(
let mut root_init = vec![];
+ let mut user_init_imports = vec![];
+
let ret = {
let late_fields = analysis
.late_resources
@@ -62,6 +66,12 @@ pub fn codegen(
}
));
+ let name_late = format_ident!("{}LateResources", name);
+ user_init_imports.push(quote!(
+ #[allow(non_snake_case)]
+ use super::#name_late;
+ ));
+
Some(quote!(-> #name::LateResources))
} else {
None
@@ -89,14 +99,25 @@ pub fn codegen(
#(#stmts)*
}
));
+ user_init_imports.push(quote!(
+ #(#attrs)*
+ #[allow(non_snake_case)]
+ use super::#name;
+ ));
- let mut const_app = None;
+ let mut mod_app = None;
if !init.args.resources.is_empty() {
let (item, constructor) =
resources_struct::codegen(Context::Init, 0, &mut needs_lt, app, analysis);
root_init.push(item);
- const_app = Some(constructor);
+ mod_app = Some(constructor);
+
+ let name_late = format_ident!("{}Resources", name);
+ user_init_imports.push(quote!(
+ #[allow(non_snake_case)]
+ use super::#name_late;
+ ));
}
let locals_new = locals_new.iter();
@@ -106,8 +127,8 @@ pub fn codegen(
root_init.push(module::codegen(Context::Init, needs_lt, app, extra));
- (const_app, root_init, user_init, call_init)
+ (mod_app, root_init, user_init, user_init_imports, call_init)
} else {
- (None, vec![], None, None)
+ (None, vec![], None, vec![], None)
}
}
diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs
index 4196ee7a..38ea5245 100644
--- a/macros/src/codegen/resources.rs
+++ b/macros/src/codegen/resources.rs
@@ -10,13 +10,16 @@ pub fn codegen(
analysis: &Analysis,
extra: &Extra,
) -> (
- // const_app -- the `static [mut]` variables behind the proxies
+ // mod_app -- the `static [mut]` variables behind the proxies
Vec<TokenStream2>,
// mod_resources -- the `resources` module
TokenStream2,
+ // mod_resources_imports -- the `resources` module imports
+ Vec<TokenStream2>,
) {
- let mut const_app = vec![];
+ let mut mod_app = vec![];
let mut mod_resources = vec![];
+ let mut mod_resources_imports = vec![];
for (name, res, expr, _) in app.resources(analysis) {
let cfgs = &res.cfgs;
@@ -39,7 +42,7 @@ pub fn codegen(
};
let attrs = &res.attrs;
- const_app.push(quote!(
+ mod_app.push(quote!(
#[allow(non_upper_case_globals)]
#(#attrs)*
#(#cfgs)*
@@ -82,7 +85,13 @@ pub fn codegen(
)
};
- const_app.push(util::impl_mutex(
+ mod_resources_imports.push(quote!(
+ #[allow(non_camel_case_types)]
+ #(#cfgs)*
+ use super::resources::#name;
+ ));
+
+ mod_app.push(util::impl_mutex(
extra,
cfgs,
true,
@@ -97,6 +106,11 @@ pub fn codegen(
let mod_resources = if mod_resources.is_empty() {
quote!()
} else {
+ // Also import the resource module
+ mod_resources_imports.push(quote!(
+ use super::resources;
+ ));
+
quote!(mod resources {
use rtic::export::Priority;
@@ -104,5 +118,5 @@ pub fn codegen(
})
};
- (const_app, mod_resources)
+ (mod_app, mod_resources, mod_resources_imports)
}
diff --git a/macros/src/codegen/resources_struct.rs b/macros/src/codegen/resources_struct.rs
index dbbba30e..92d5b666 100644
--- a/macros/src/codegen/resources_struct.rs
+++ b/macros/src/codegen/resources_struct.rs
@@ -165,7 +165,7 @@ pub fn codegen(
let constructor = quote!(
impl<#lt> #ident<#lt> {
#[inline(always)]
- unsafe fn new(#arg) -> Self {
+ pub unsafe fn new(#arg) -> Self {
#ident {
#(#values,)*
}
diff --git a/macros/src/codegen/schedule.rs b/macros/src/codegen/schedule.rs
index 46b0f384..5a887496 100644
--- a/macros/src/codegen/schedule.rs
+++ b/macros/src/codegen/schedule.rs
@@ -34,7 +34,7 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec<TokenStream2> {
methods.push(quote!(
#(#cfgs)*
- fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> {
+ pub fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> {
#body
}
));
@@ -49,7 +49,7 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec<TokenStream2> {
items.push(quote!(
#(#cfgs)*
- unsafe fn #schedule(
+ pub unsafe fn #schedule(
priority: &rtic::export::Priority,
instant: #instant
#(,#args)*
@@ -62,7 +62,7 @@ pub fn codegen(app: &App, extra: &Extra) -> Vec<TokenStream2> {
methods.push(quote!(
#(#cfgs)*
#[inline(always)]
- fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> {
+ pub fn #name(&self, instant: #instant #(,#args)*) -> Result<(), #ty> {
unsafe {
#schedule(self.priority(), instant #(,#untupled)*)
}
diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs
index b56db419..4ae37e4e 100644
--- a/macros/src/codegen/software_tasks.rs
+++ b/macros/src/codegen/software_tasks.rs
@@ -1,5 +1,5 @@
use proc_macro2::TokenStream as TokenStream2;
-use quote::quote;
+use quote::{format_ident, quote};
use rtic_syntax::{ast::App, Context};
use crate::{
@@ -13,7 +13,7 @@ pub fn codegen(
analysis: &Analysis,
extra: &Extra,
) -> (
- // const_app_software_tasks -- free queues, buffers and `${task}Resources` constructors
+ // mod_app_software_tasks -- free queues, buffers and `${task}Resources` constructors
Vec<TokenStream2>,
// root_software_tasks -- items that must be placed in the root of the crate:
// - `${task}Locals` structs
@@ -22,10 +22,13 @@ pub fn codegen(
Vec<TokenStream2>,
// user_software_tasks -- the `#[task]` functions written by the user
Vec<TokenStream2>,
+ // user_software_tasks_imports -- the imports for `#[task]` functions written by the user
+ Vec<TokenStream2>,
) {
- let mut const_app = vec![];
+ let mut mod_app = vec![];
let mut root = vec![];
let mut user_tasks = vec![];
+ let mut software_tasks_imports = vec![];
for (name, task) in &app.software_tasks {
let inputs = &task.inputs;
@@ -48,7 +51,7 @@ pub fn codegen(
Box::new(|| util::link_section_uninit(true)),
)
};
- const_app.push(quote!(
+ mod_app.push(quote!(
/// Queue version of a free-list that keeps track of empty slots in
/// the following buffers
static mut #fq: #fq_ty = #fq_expr;
@@ -56,13 +59,13 @@ pub fn codegen(
// Generate a resource proxy if needed
if let Some(ceiling) = ceiling {
- const_app.push(quote!(
+ mod_app.push(quote!(
struct #fq<'a> {
priority: &'a rtic::export::Priority,
}
));
- const_app.push(util::impl_mutex(
+ mod_app.push(util::impl_mutex(
extra,
&[],
false,
@@ -82,7 +85,7 @@ pub fn codegen(
let instants = util::instants_ident(name);
let uninit = mk_uninit();
- const_app.push(quote!(
+ mod_app.push(quote!(
#uninit
/// Buffer that holds the instants associated to the inputs of a task
static mut #instants:
@@ -93,7 +96,7 @@ pub fn codegen(
let uninit = mk_uninit();
let inputs = util::inputs_ident(name);
- const_app.push(quote!(
+ mod_app.push(quote!(
#uninit
/// Buffer that holds the inputs of a task
static mut #inputs: [core::mem::MaybeUninit<#input_ty>; #cap_lit] =
@@ -112,9 +115,16 @@ pub fn codegen(
analysis,
);
+ // Add resources to imports
+ let name_res = format_ident!("{}Resources", name);
+ software_tasks_imports.push(quote!(
+ #[allow(non_snake_case)]
+ use super::#name_res;
+ ));
+
root.push(item);
- const_app.push(constructor);
+ mod_app.push(constructor);
}
// `${task}Locals`
@@ -135,12 +145,17 @@ pub fn codegen(
#(#attrs)*
#(#cfgs)*
#[allow(non_snake_case)]
- fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) {
+ pub fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) {
use rtic::Mutex as _;
#(#stmts)*
}
));
+ software_tasks_imports.push(quote!(
+ #(#cfgs)*
+ #[allow(non_snake_case)]
+ use super::#name;
+ ));
root.push(module::codegen(
Context::SoftwareTask(name),
@@ -150,5 +165,5 @@ pub fn codegen(
));
}
- (const_app, root, user_tasks)
+ (mod_app, root, user_tasks, software_tasks_imports)
}
diff --git a/macros/src/codegen/spawn.rs b/macros/src/codegen/spawn.rs
index 4b824f56..da281516 100644
--- a/macros/src/codegen/spawn.rs
+++ b/macros/src/codegen/spawn.rs
@@ -40,7 +40,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
methods.push(quote!(
#(#cfgs)*
- fn #name(&self #(,#args)*) -> Result<(), #ty> {
+ pub fn #name(&self #(,#args)*) -> Result<(), #ty> {
#let_instant
#body
}
@@ -92,7 +92,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
methods.push(quote!(
#(#cfgs)*
#[inline(always)]
- fn #name(&self #(,#args)*) -> Result<(), #ty> {
+ pub fn #name(&self #(,#args)*) -> Result<(), #ty> {
unsafe {
#let_instant
#spawn(self.priority() #instant #(,#untupled)*)