diff options
author | Igor Mammedov <imammedo@redhat.com> | 2017-10-05 15:50:49 +0200 |
---|---|---|
committer | Eduardo Habkost <ehabkost@redhat.com> | 2017-10-27 16:03:54 +0200 |
commit | 0255db239eba48669f93e12974ab3d68ca5d6a13 (patch) | |
tree | 4b642310e0496c4a63f980a74a017a353eb4526a /target/moxie | |
parent | a7f981cc9f3e5a99c6690c144ba1d6a77394c39b (diff) | |
download | qemu-0255db239eba48669f93e12974ab3d68ca5d6a13.zip qemu-0255db239eba48669f93e12974ab3d68ca5d6a13.tar.gz qemu-0255db239eba48669f93e12974ab3d68ca5d6a13.tar.bz2 |
moxie: cleanup cpu type name composition
introduce MOXIE_CPU_TYPE_NAME macro and consistently use it
to construct cpu type names. While at it replace dynamic
cpu type name composition with static data.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <1507211474-188400-16-git-send-email-imammedo@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'target/moxie')
-rw-r--r-- | target/moxie/cpu.c | 56 | ||||
-rw-r--r-- | target/moxie/cpu.h | 3 |
2 files changed, 20 insertions, 39 deletions
diff --git a/target/moxie/cpu.c b/target/moxie/cpu.c index 44441b2..f1389e5 100644 --- a/target/moxie/cpu.c +++ b/target/moxie/cpu.c @@ -86,7 +86,7 @@ static ObjectClass *moxie_cpu_class_by_name(const char *cpu_model) ObjectClass *oc; char *typename; - typename = g_strdup_printf("%s-" TYPE_MOXIE_CPU, cpu_model); + 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) || @@ -134,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) diff --git a/target/moxie/cpu.h b/target/moxie/cpu.h index 75decaa..d37e6a5 100644 --- a/target/moxie/cpu.h +++ b/target/moxie/cpu.h @@ -122,6 +122,9 @@ int cpu_moxie_signal_handler(int host_signum, void *pinfo, #define cpu_init(cpu_model) cpu_generic_init(TYPE_MOXIE_CPU, cpu_model) +#define MOXIE_CPU_TYPE_SUFFIX "-" TYPE_MOXIE_CPU +#define MOXIE_CPU_TYPE_NAME(model) model MOXIE_CPU_TYPE_SUFFIX + #define cpu_signal_handler cpu_moxie_signal_handler static inline int cpu_mmu_index(CPUMoxieState *env, bool ifetch) |