aboutsummaryrefslogtreecommitdiff
path: root/rtic-macros/src/codegen/idle.rs
diff options
context:
space:
mode:
authorGravatar bors[bot] <26634292+bors[bot]@users.noreply.github.com> 2023-03-04 21:10:24 +0000
committerGravatar GitHub <noreply@github.com> 2023-03-04 21:10:24 +0000
commit7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b (patch)
tree80a47f0dc40059014e9448c4c2eb34c54dff45fe /rtic-macros/src/codegen/idle.rs
parent1c5db277e4161470136dbd2a11e914ff1d383581 (diff)
parent98c5490d94950608d31cd5ad9dd260f2f853735c (diff)
downloadrtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.tar.gz
rtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.tar.zst
rtic-7c7d6558f6d9c50fbb4d2487c98c9a5be15f2f7b.zip
Merge #694
694: RTIC 2 r=AfoHT a=korken89 Co-authored-by: Emil Fresk <emil.fresk@gmail.com> Co-authored-by: Per Lindgren <per.lindgren@ltu.se>
Diffstat (limited to 'rtic-macros/src/codegen/idle.rs')
-rw-r--r--rtic-macros/src/codegen/idle.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/rtic-macros/src/codegen/idle.rs b/rtic-macros/src/codegen/idle.rs
new file mode 100644
index 00000000..0c833ef3
--- /dev/null
+++ b/rtic-macros/src/codegen/idle.rs
@@ -0,0 +1,58 @@
+use crate::syntax::{ast::App, Context};
+use crate::{
+ analyze::Analysis,
+ codegen::{local_resources_struct, module, shared_resources_struct},
+};
+use proc_macro2::TokenStream as TokenStream2;
+use quote::quote;
+
+/// Generates support code for `#[idle]` functions
+pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
+ if let Some(idle) = &app.idle {
+ 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, app);
+
+ root_idle.push(item);
+ mod_app.push(constructor);
+ }
+
+ if !idle.args.local_resources.is_empty() {
+ let (item, constructor) = local_resources_struct::codegen(Context::Idle, app);
+
+ root_idle.push(item);
+
+ mod_app.push(constructor);
+ }
+
+ root_idle.push(module::codegen(Context::Idle, app, analysis));
+
+ let attrs = &idle.attrs;
+ let context = &idle.context;
+ let stmts = &idle.stmts;
+ let user_idle = Some(quote!(
+ #(#attrs)*
+ #[allow(non_snake_case)]
+ fn #name(#context: #name::Context) -> ! {
+ use rtic::Mutex as _;
+ use rtic::mutex::prelude::*;
+
+ #(#stmts)*
+ }
+ ));
+
+ quote!(
+ #(#mod_app)*
+
+ #(#root_idle)*
+
+ #user_idle
+ )
+ } else {
+ quote!()
+ }
+}