12b74dd91SManos Pitsidianakis // Copyright 2024, Linaro Limited 22b74dd91SManos Pitsidianakis // Author(s): Manos Pitsidianakis <manos.pitsidianakis@linaro.org> 32b74dd91SManos Pitsidianakis // SPDX-License-Identifier: GPL-2.0-or-later 42b74dd91SManos Pitsidianakis 52b74dd91SManos Pitsidianakis use proc_macro::TokenStream; 6*e90d4707SPaolo Bonzini use quote::quote; 72b74dd91SManos Pitsidianakis use syn::{parse_macro_input, DeriveInput}; 82b74dd91SManos Pitsidianakis 92b74dd91SManos Pitsidianakis #[proc_macro_derive(Object)] 102b74dd91SManos Pitsidianakis pub fn derive_object(input: TokenStream) -> TokenStream { 112b74dd91SManos Pitsidianakis let input = parse_macro_input!(input as DeriveInput); 122b74dd91SManos Pitsidianakis let name = input.ident; 132b74dd91SManos Pitsidianakis 142b74dd91SManos Pitsidianakis let expanded = quote! { 15*e90d4707SPaolo Bonzini ::qemu_api::module_init! { 16*e90d4707SPaolo Bonzini MODULE_INIT_QOM => unsafe { 172b74dd91SManos Pitsidianakis ::qemu_api::bindings::type_register_static(&<#name as ::qemu_api::definitions::ObjectImpl>::TYPE_INFO); 182b74dd91SManos Pitsidianakis } 192b74dd91SManos Pitsidianakis } 202b74dd91SManos Pitsidianakis }; 212b74dd91SManos Pitsidianakis 222b74dd91SManos Pitsidianakis TokenStream::from(expanded) 232b74dd91SManos Pitsidianakis } 24