compiles new inline asm without errors
[power-instruction-analyzer.git] / power-instruction-analyzer-proc-macro / src / lib.rs
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2 // See Notices.txt for copyright information
3
4 #[macro_use]
5 mod inline_assembly;
6 mod instructions;
7
8 use instructions::Instructions;
9 use proc_macro::TokenStream;
10 use quote::quote;
11 use std::{env, fs, path::Path};
12 use syn::parse_macro_input;
13
14 #[proc_macro]
15 pub fn instructions(input: TokenStream) -> TokenStream {
16 let input = parse_macro_input!(input as Instructions);
17 match input.to_tokens() {
18 Ok(retval) => {
19 fs::write(
20 Path::new(&env::var_os("CARGO_MANIFEST_DIR").unwrap()).join("out.rs"),
21 retval.to_string(),
22 )
23 .unwrap();
24 quote! {
25 include!(concat!(env!("CARGO_MANIFEST_DIR"), "/out.rs"));
26 }
27 }
28 Err(err) => err.to_compile_error(),
29 }
30 .into()
31 }