diff mbox series

[PATCH-for-10.1,2/8] target/mips: Declare CPU QOM types using DEFINE_TYPES() macro

Message ID 20250325154058.92735-3-philmd@linaro.org
State New
Headers show
Series target/mips: Make 'cpu-qom.h' target agnostic | expand

Commit Message

Philippe Mathieu-Daudé March 25, 2025, 3:40 p.m. UTC
When multiple QOM types are registered in the same file,
it is simpler to use the the DEFINE_TYPES() macro. In
particular because type array declared with such macro
are easier to review.

In few commits we are going to add more types, so replace
the type_register_static() to ease further reviews.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
---
 target/mips/cpu.c | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

Comments

Pierrick Bouvier March 26, 2025, 3:21 p.m. UTC | #1
On 3/25/25 08:40, Philippe Mathieu-Daudé wrote:
> When multiple QOM types are registered in the same file,
> it is simpler to use the the DEFINE_TYPES() macro. In
> particular because type array declared with such macro
> are easier to review.
> 
> In few commits we are going to add more types, so replace
> the type_register_static() to ease further reviews.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
> ---
>   target/mips/cpu.c | 23 +++++++++++++----------
>   1 file changed, 13 insertions(+), 10 deletions(-)
> 
> diff --git a/target/mips/cpu.c b/target/mips/cpu.c
> index b207106dd79..097554fd8ae 100644
> --- a/target/mips/cpu.c
> +++ b/target/mips/cpu.c
> @@ -597,17 +597,21 @@ static void mips_cpu_class_init(ObjectClass *c, void *data)
>   #endif /* CONFIG_TCG */
>   }
>   
> -static const TypeInfo mips_cpu_type_info = {
> -    .name = TYPE_MIPS_CPU,
> -    .parent = TYPE_CPU,
> -    .instance_size = sizeof(MIPSCPU),
> -    .instance_align = __alignof(MIPSCPU),
> -    .instance_init = mips_cpu_initfn,
> -    .abstract = true,
> -    .class_size = sizeof(MIPSCPUClass),
> -    .class_init = mips_cpu_class_init,
> +static const TypeInfo mips_cpu_types[] = {
> +    {
> +        .name           = TYPE_MIPS_CPU,
> +        .parent         = TYPE_CPU,
> +        .instance_size  = sizeof(MIPSCPU),
> +        .instance_align = __alignof(MIPSCPU),
> +        .instance_init  = mips_cpu_initfn,
> +        .abstract       = true,
> +        .class_size     = sizeof(MIPSCPUClass),
> +        .class_init     = mips_cpu_class_init,
> +    }
>   };
>   
> +DEFINE_TYPES(mips_cpu_types)
> +
>   static void mips_cpu_cpudef_class_init(ObjectClass *oc, void *data)
>   {
>       MIPSCPUClass *mcc = MIPS_CPU_CLASS(oc);
> @@ -632,7 +636,6 @@ static void mips_cpu_register_types(void)
>   {
>       int i;
>   
> -    type_register_static(&mips_cpu_type_info);
>       for (i = 0; i < mips_defs_number; i++) {
>           mips_register_cpudef_type(&mips_defs[i]);
>       }

Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
diff mbox series

Patch

diff --git a/target/mips/cpu.c b/target/mips/cpu.c
index b207106dd79..097554fd8ae 100644
--- a/target/mips/cpu.c
+++ b/target/mips/cpu.c
@@ -597,17 +597,21 @@  static void mips_cpu_class_init(ObjectClass *c, void *data)
 #endif /* CONFIG_TCG */
 }
 
-static const TypeInfo mips_cpu_type_info = {
-    .name = TYPE_MIPS_CPU,
-    .parent = TYPE_CPU,
-    .instance_size = sizeof(MIPSCPU),
-    .instance_align = __alignof(MIPSCPU),
-    .instance_init = mips_cpu_initfn,
-    .abstract = true,
-    .class_size = sizeof(MIPSCPUClass),
-    .class_init = mips_cpu_class_init,
+static const TypeInfo mips_cpu_types[] = {
+    {
+        .name           = TYPE_MIPS_CPU,
+        .parent         = TYPE_CPU,
+        .instance_size  = sizeof(MIPSCPU),
+        .instance_align = __alignof(MIPSCPU),
+        .instance_init  = mips_cpu_initfn,
+        .abstract       = true,
+        .class_size     = sizeof(MIPSCPUClass),
+        .class_init     = mips_cpu_class_init,
+    }
 };
 
+DEFINE_TYPES(mips_cpu_types)
+
 static void mips_cpu_cpudef_class_init(ObjectClass *oc, void *data)
 {
     MIPSCPUClass *mcc = MIPS_CPU_CLASS(oc);
@@ -632,7 +636,6 @@  static void mips_cpu_register_types(void)
 {
     int i;
 
-    type_register_static(&mips_cpu_type_info);
     for (i = 0; i < mips_defs_number; i++) {
         mips_register_cpudef_type(&mips_defs[i]);
     }