xref: /linux/rust/macros/export.rs (revision 23b0f90ba871f096474e1c27c3d14f455189d2d9)
1 // SPDX-License-Identifier: GPL-2.0
2 
3 use proc_macro2::TokenStream;
4 use quote::quote;
5 
6 /// Please see [`crate::export`] for documentation.
7 pub(crate) fn export(f: syn::ItemFn) -> TokenStream {
8     let name = &f.sig.ident;
9 
10     quote! {
11         // This verifies that the function has the same signature as the declaration generated by
12         // bindgen. It makes use of the fact that all branches of an if/else must have the same
13         // type.
14         const _: () = {
15             if true {
16                 ::kernel::bindings::#name
17             } else {
18                 #name
19             };
20         };
21 
22         #[no_mangle]
23         #f
24     }
25 }
26