export.rs 644 B

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