diff options
Diffstat (limited to 'target/moxie/cpu.c')
-rw-r--r-- | target/moxie/cpu.c | 61 |
1 files changed, 22 insertions, 39 deletions
diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c index 24ab3f3708..f1389e5097 100644 --- a/target/moxie/cpu.c +++ b/target/moxie/cpu.c @@ -83,7 +83,12 @@ static void moxie_cpu_initfn(Object *obj) static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model) { - ObjectClass *oc = object_class_by_name(cpu_model); + ObjectClass *oc; + char *typename; + + typename = g_strdup_printf(MOXIE_CPU_TYPE_NAME("%s"), cpu_model); + oc = object_class_by_name(typename); + g_free(typename); if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_MOXIE_CPU) || object_class_is_abstract(oc))) { return NULL; @@ -129,46 +134,24 @@ static void moxie_any_initfn(Object *obj) /* Set cpu feature flags */ } -typedef struct MoxieCPUInfo { - const char *name; - void (*initfn)(Object *obj); -} MoxieCPUInfo; - -static const MoxieCPUInfo moxie_cpus[] = { - { .name = "MoxieLite", .initfn = moxielite_initfn }, - { .name = "any", .initfn = moxie_any_initfn }, -}; +#define DEFINE_MOXIE_CPU_TYPE(cpu_model, initfn) \ + { \ + .parent = TYPE_MOXIE_CPU, \ + .instance_init = initfn, \ + .name = MOXIE_CPU_TYPE_NAME(cpu_model), \ + } -static void cpu_register(const MoxieCPUInfo *info) -{ - TypeInfo type_info = { - .parent = TYPE_MOXIE_CPU, +static const TypeInfo moxie_cpus_type_infos[] = { + { /* base class should be registered first */ + .name = TYPE_MOXIE_CPU, + .parent = TYPE_CPU, .instance_size = sizeof(MoxieCPU), - .instance_init = info->initfn, + .instance_init = moxie_cpu_initfn, .class_size = sizeof(MoxieCPUClass), - }; - - type_info.name = g_strdup_printf("%s-" TYPE_MOXIE_CPU, info->name); - type_register(&type_info); - g_free((void *)type_info.name); -} - -static const TypeInfo moxie_cpu_type_info = { - .name = TYPE_MOXIE_CPU, - .parent = TYPE_CPU, - .instance_size = sizeof(MoxieCPU), - .instance_init = moxie_cpu_initfn, - .class_size = sizeof(MoxieCPUClass), - .class_init = moxie_cpu_class_init, + .class_init = moxie_cpu_class_init, + }, + DEFINE_MOXIE_CPU_TYPE("MoxieLite", moxielite_initfn), + DEFINE_MOXIE_CPU_TYPE("any", moxie_any_initfn), }; -static void moxie_cpu_register_types(void) -{ - int i; - type_register_static(&moxie_cpu_type_info); - for (i = 0; i < ARRAY_SIZE(moxie_cpus); i++) { - cpu_register(&moxie_cpus[i]); - } -} - -type_init(moxie_cpu_register_types) +DEFINE_TYPES(moxie_cpus_type_infos) |