aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/assertions.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-06-13 23:56:59 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-06-13 23:56:59 +0200
commit81275bfa4f41e2066770087f3a33cad4227eab41 (patch)
treec779a68e7cecf4c2613c7593376f980cea5dbc05 /macros/src/codegen/assertions.rs
parentfafeeb27270ef24fc3852711c6032f65aa7dbcc0 (diff)
downloadrtic-81275bfa4f41e2066770087f3a33cad4227eab41.tar.gz
rtic-81275bfa4f41e2066770087f3a33cad4227eab41.tar.zst
rtic-81275bfa4f41e2066770087f3a33cad4227eab41.zip
rtfm-syntax refactor + heterogeneous multi-core support
Diffstat (limited to 'macros/src/codegen/assertions.rs')
-rw-r--r--macros/src/codegen/assertions.rs26
1 files changed, 26 insertions, 0 deletions
diff --git a/macros/src/codegen/assertions.rs b/macros/src/codegen/assertions.rs
new file mode 100644
index 00000000..95268a2c
--- /dev/null
+++ b/macros/src/codegen/assertions.rs
@@ -0,0 +1,26 @@
+use proc_macro2::TokenStream as TokenStream2;
+use quote::quote;
+
+use crate::analyze::Analysis;
+
+/// Generates compile-time assertions that check that types implement the `Send` / `Sync` traits
+pub fn codegen(core: u8, analysis: &Analysis) -> Vec<TokenStream2> {
+ let mut stmts = vec![];
+
+ // we don't generate *all* assertions on all cores because the user could conditionally import a
+ // type only on some core (e.g. `#[cfg(core = "0")] use some::Type;`)
+
+ if let Some(types) = analysis.send_types.get(&core) {
+ for ty in types {
+ stmts.push(quote!(rtfm::export::assert_send::<#ty>();));
+ }
+ }
+
+ if let Some(types) = analysis.sync_types.get(&core) {
+ for ty in types {
+ stmts.push(quote!(rtfm::export::assert_sync::<#ty>();));
+ }
+ }
+
+ stmts
+}