aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen/util.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2019-06-29 09:11:42 +0200
committerGravatar Jorge Aparicio <jorge@japaric.io> 2019-06-29 09:11:57 +0200
commitbe92041a592f65f38cee8475b61d35e7fcee3694 (patch)
tree3d7f59dff198183dee3920e790693a93063f3996 /macros/src/codegen/util.rs
parentdf4a7fd3e5df370a83fcdc24aa628bed3fa9f543 (diff)
downloadrtic-be92041a592f65f38cee8475b61d35e7fcee3694.tar.gz
rtic-be92041a592f65f38cee8475b61d35e7fcee3694.tar.zst
rtic-be92041a592f65f38cee8475b61d35e7fcee3694.zip
WIP
Diffstat (limited to 'macros/src/codegen/util.rs')
-rw-r--r--macros/src/codegen/util.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs
index cd01264d..f5f96dea 100644
--- a/macros/src/codegen/util.rs
+++ b/macros/src/codegen/util.rs
@@ -1,3 +1,5 @@
+use core::sync::atomic::{AtomicUsize, Ordering};
+
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::quote;
use rtfm_syntax::{ast::App, Context, Core};
@@ -133,6 +135,43 @@ pub fn late_resources_ident(init: &Ident) -> Ident {
)
}
+fn link_section_index() -> usize {
+ static INDEX: AtomicUsize = AtomicUsize::new(0);
+
+ INDEX.fetch_add(1, Ordering::Relaxed)
+}
+
+pub fn link_section(section: &str, core: Core) -> Option<TokenStream2> {
+ if cfg!(feature = "homogeneous") {
+ let section = format!(".{}_{}.rtfm{}", section, core, link_section_index());
+ Some(quote!(#[link_section = #section]))
+ } else {
+ None
+ }
+}
+
+// NOTE `None` means in shared memory
+pub fn link_section_uninit(core: Option<Core>) -> Option<TokenStream2> {
+ let section = if let Some(core) = core {
+ let index = link_section_index();
+
+ if cfg!(feature = "homogeneous") {
+ format!(".uninit_{}.rtfm{}", core, index)
+ } else {
+ format!(".uninit.rtfm{}", index)
+ }
+ } else {
+ if cfg!(feature = "heterogeneous") {
+ // `#[shared]` attribute sets the linker section
+ return None;
+ }
+
+ format!(".uninit.rtfm{}", link_section_index())
+ };
+
+ 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 {