diff options
author | 2023-02-04 16:47:17 +0100 | |
---|---|---|
committer | 2023-03-01 00:35:13 +0100 | |
commit | 9e445b3583c15c7701f3167eaa8dfe4afd541691 (patch) | |
tree | 167565d51598f42c0454d60b34e1170589ae1056 /rtic-macros/src/codegen/assertions.rs | |
parent | 4124fbdd61ff823c6217a2a16ebb4d813146116c (diff) | |
download | rtic-9e445b3583c15c7701f3167eaa8dfe4afd541691.tar.gz rtic-9e445b3583c15c7701f3167eaa8dfe4afd541691.tar.zst rtic-9e445b3583c15c7701f3167eaa8dfe4afd541691.zip |
Move rtic macros to repo root, tune xtask
Diffstat (limited to 'rtic-macros/src/codegen/assertions.rs')
-rw-r--r-- | rtic-macros/src/codegen/assertions.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/rtic-macros/src/codegen/assertions.rs b/rtic-macros/src/codegen/assertions.rs new file mode 100644 index 00000000..dd94aa6d --- /dev/null +++ b/rtic-macros/src/codegen/assertions.rs @@ -0,0 +1,53 @@ +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; + +use crate::syntax::ast::App; +use crate::{analyze::Analysis, codegen::util}; + +/// Generates compile-time assertions that check that types implement the `Send` / `Sync` traits +pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> { + let mut stmts = vec![]; + + for ty in &analysis.send_types { + stmts.push(quote!(rtic::export::assert_send::<#ty>();)); + } + + for ty in &analysis.sync_types { + stmts.push(quote!(rtic::export::assert_sync::<#ty>();)); + } + + let device = &app.args.device; + let chunks_name = util::priority_mask_chunks_ident(); + let no_basepri_checks: Vec<_> = app + .hardware_tasks + .iter() + .filter_map(|(_, task)| { + if !util::is_exception(&task.args.binds) { + let interrupt_name = &task.args.binds; + Some(quote!( + if (#device::Interrupt::#interrupt_name as usize) >= (#chunks_name * 32) { + ::core::panic!("An interrupt out of range is used while in armv6 or armv8m.base"); + } + )) + } else { + None + } + }) + .collect(); + + let const_check = quote! { + const _CONST_CHECK: () = { + if !rtic::export::have_basepri() { + #(#no_basepri_checks)* + } else { + // TODO: Add armv7 checks here + } + }; + + let _ = _CONST_CHECK; + }; + + stmts.push(const_check); + + stmts +} |