| 1 | extern crate proc_macro; |
| 2 | |
| 3 | use std::iter::FromIterator; |
| 4 | |
| 5 | use proc_macro::TokenStream; |
| 6 | use quote::quote; |
| 7 | |
| 8 | #[proc_macro_attribute ] |
| 9 | pub fn cold_for_target_arch (attr: TokenStream, item: TokenStream) -> TokenStream { |
| 10 | let arch_list: String = attr.to_string(); |
| 11 | let mut out: Vec<TokenStream> = arch_list.split("," ).map(|a: &str| { |
| 12 | let a: &str = a.trim().split(" \"" ).nth(1).expect(msg:"A ','-separated list of \"arguments \" expected" ); |
| 13 | (quote! { |
| 14 | #[cfg_attr(target_arch = #a, cold)] |
| 15 | }).into() |
| 16 | }).collect(); |
| 17 | |
| 18 | out.push(item); |
| 19 | |
| 20 | TokenStream::from_iter(out.into_iter()) |
| 21 | } |
| 22 | |
| 23 | |
| 24 | |