1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
extern crate proc_macro;

use proc_macro::TokenStream;

use quote::quote;
use syn::parse_macro_input;

/// Check the function provided to be in correct format and generate actual entrypoint, which
/// will invoke this function. TODO: This will be replaced by more general solution, where the actual function
/// will not have to execute static functions to load arguments (either by providing streams, or some other abstraction
#[proc_macro_attribute]
pub fn entrypoint(_attr: TokenStream, item: TokenStream) -> TokenStream {
    let fun = parse_macro_input!(item as syn::ItemFn);

    if fun.sig.inputs.len() > 0 {
        panic!("Function must have 0 arguments")
    }
    let name = fun.sig.ident.clone();

    let res = quote! {
        #fun

        #[no_mangle]
        fn _ipcs_start() {
            #name();
        }
    };

    res.into()
}