ipcs_codegen/
lib.rs

1extern crate proc_macro;
2
3use proc_macro::TokenStream;
4
5use quote::quote;
6use syn::parse_macro_input;
7
8/// Check the function provided to be in correct format and generate actual entrypoint, which
9/// will invoke this function. TODO: This will be replaced by more general solution, where the actual function
10/// will not have to execute static functions to load arguments (either by providing streams, or some other abstraction
11#[proc_macro_attribute]
12pub fn entrypoint(_attr: TokenStream, item: TokenStream) -> TokenStream {
13    let fun = parse_macro_input!(item as syn::ItemFn);
14
15    if fun.sig.inputs.len() > 0 {
16        panic!("Function must have 0 arguments")
17    }
18    let name = fun.sig.ident.clone();
19
20    let res = quote! {
21        #fun
22
23        #[no_mangle]
24        fn _ipcs_start() {
25            #name();
26        }
27    };
28
29    res.into()
30}