1 | use proc_macro::TokenStream; |
2 | use quote::quote; |
3 | use syn::{parse_macro_input, LitStr}; |
4 | |
5 | use crate::construct; |
6 | |
7 | pub(crate) fn expand(args: TokenStream) -> TokenStream { |
8 | let literal = parse_macro_input!(args as LitStr); |
9 | let sym_name = construct::mangled_symbol_name("prim" , &literal.value()); |
10 | |
11 | let prefix = Some("prim" ); |
12 | let section = construct::linker_section(false, prefix, &sym_name); |
13 | let section_for_macos = construct::linker_section(true, prefix, &sym_name); |
14 | |
15 | let var_addr = if cfg!(feature = "unstable-test" ) { |
16 | quote!({ defmt::export::fetch_add_string_index() as u16 }) |
17 | } else { |
18 | quote!({ |
19 | #[cfg_attr(target_os = "macos" , link_section = #section_for_macos)] |
20 | #[cfg_attr(not(target_os = "macos" ), link_section = #section)] |
21 | #[export_name = #sym_name] |
22 | static S: u8 = 0; |
23 | &S as *const u8 as u16 |
24 | }) |
25 | }; |
26 | |
27 | quote!({ |
28 | defmt::export::make_istr(#var_addr) |
29 | }) |
30 | .into() |
31 | } |
32 | |