1 // Copyright 2024, Linaro Limited 2 // Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org> 3 // SPDX-License-Identifier: GPL-2.0-or-later 4 5 use proc_macro::TokenStream; 6 use quote::quote; 7 use syn::{parse_macro_input, DeriveInput}; 8 9 #[proc_macro_derive(Object)] 10 pub fn derive_object(input: TokenStream) -> TokenStream { 11 let input = parse_macro_input!(input as DeriveInput); 12 let name = input.ident; 13 14 let expanded = quote! { 15 ::qemu_api::module_init! { 16 MODULE_INIT_QOM => unsafe { 17 ::qemu_api::bindings::type_register_static(&<#name as ::qemu_api::definitions::ObjectImpl>::TYPE_INFO); 18 } 19 } 20 }; 21 22 TokenStream::from(expanded) 23 } 24