diff options
author | Igor Mammedov <imammedo@redhat.com> | 2017-10-05 15:51:03 +0200 |
---|---|---|
committer | Eduardo Habkost <ehabkost@redhat.com> | 2017-10-27 16:04:27 +0200 |
commit | b9ad9d5b2110e4078819626d9a606679656d2498 (patch) | |
tree | 057df5780cdea133973d16e635ef6c18269ff03d /target/tricore | |
parent | 1aaa63193b307fe42ba714e0615646cec7b37c51 (diff) |
tricore: cleanup cpu type name composition
introduce TRICORE_CPU_TYPE_NAME macro and use it to construct
cpu type names. While at it move cpu type_infos into one
array and register it directly with type_init_from_array()
instead of custom tricore_cpu_register_types()/cpu_register()
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Message-Id: <1507211474-188400-30-git-send-email-imammedo@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'target/tricore')
-rw-r--r-- | target/tricore/cpu.c | 68 | ||||
-rw-r--r-- | target/tricore/cpu.h | 2 |
2 files changed, 22 insertions, 48 deletions
diff --git a/target/tricore/cpu.c b/target/tricore/cpu.c index cd93806d47..179c997aa4 100644 --- a/target/tricore/cpu.c +++ b/target/tricore/cpu.c @@ -116,7 +116,7 @@ static ObjectClass *tricore_cpu_class_by_name(const char *cpu_model) ObjectClass *oc; char *typename; - typename = g_strdup_printf("%s-" TYPE_TRICORE_CPU, cpu_model); + typename = g_strdup_printf(TRICORE_CPU_TYPE_NAME("%s"), cpu_model); oc = object_class_by_name(typename); g_free(typename); if (!oc || !object_class_dynamic_cast(oc, TYPE_TRICORE_CPU) || @@ -147,19 +147,6 @@ static void tc27x_initfn(Object *obj) set_feature(&cpu->env, TRICORE_FEATURE_161); } -typedef struct TriCoreCPUInfo { - const char *name; - void (*initfn)(Object *obj); - void (*class_init)(ObjectClass *oc, void *data); -} TriCoreCPUInfo; - -static const TriCoreCPUInfo tricore_cpus[] = { - { .name = "tc1796", .initfn = tc1796_initfn }, - { .name = "tc1797", .initfn = tc1797_initfn }, - { .name = "tc27x", .initfn = tc27x_initfn }, - { .name = NULL } -}; - static void tricore_cpu_class_init(ObjectClass *c, void *data) { TriCoreCPUClass *mcc = TRICORE_CPU_CLASS(c); @@ -181,41 +168,26 @@ static void tricore_cpu_class_init(ObjectClass *c, void *data) cc->tcg_initialize = tricore_tcg_init; } -static void cpu_register(const TriCoreCPUInfo *info) -{ - TypeInfo type_info = { - .parent = TYPE_TRICORE_CPU, +#define DEFINE_TRICORE_CPU_TYPE(cpu_model, initfn) \ + { \ + .parent = TYPE_TRICORE_CPU, \ + .instance_init = initfn, \ + .name = TRICORE_CPU_TYPE_NAME(cpu_model), \ + } + +static const TypeInfo tricore_cpu_type_infos[] = { + { + .name = TYPE_TRICORE_CPU, + .parent = TYPE_CPU, .instance_size = sizeof(TriCoreCPU), - .instance_init = info->initfn, + .instance_init = tricore_cpu_initfn, + .abstract = true, .class_size = sizeof(TriCoreCPUClass), - .class_init = info->class_init, - }; - - type_info.name = g_strdup_printf("%s-" TYPE_TRICORE_CPU, info->name); - type_register(&type_info); - g_free((void *)type_info.name); -} - -static const TypeInfo tricore_cpu_type_info = { - .name = TYPE_TRICORE_CPU, - .parent = TYPE_CPU, - .instance_size = sizeof(TriCoreCPU), - .instance_init = tricore_cpu_initfn, - .abstract = true, - .class_size = sizeof(TriCoreCPUClass), - .class_init = tricore_cpu_class_init, + .class_init = tricore_cpu_class_init, + }, + DEFINE_TRICORE_CPU_TYPE("tc1796", tc1796_initfn), + DEFINE_TRICORE_CPU_TYPE("tc1797", tc1797_initfn), + DEFINE_TRICORE_CPU_TYPE("tc27x", tc27x_initfn), }; -static void tricore_cpu_register_types(void) -{ - const TriCoreCPUInfo *info = tricore_cpus; - - type_register_static(&tricore_cpu_type_info); - - while (info->name) { - cpu_register(info); - info++; - } -} - -type_init(tricore_cpu_register_types) +DEFINE_TYPES(tricore_cpu_type_infos) diff --git a/target/tricore/cpu.h b/target/tricore/cpu.h index bc53c40774..f41d2ceb69 100644 --- a/target/tricore/cpu.h +++ b/target/tricore/cpu.h @@ -413,6 +413,8 @@ static inline void cpu_get_tb_cpu_state(CPUTriCoreState *env, target_ulong *pc, #define cpu_init(cpu_model) cpu_generic_init(TYPE_TRICORE_CPU, cpu_model) +#define TRICORE_CPU_TYPE_SUFFIX "-" TYPE_TRICORE_CPU +#define TRICORE_CPU_TYPE_NAME(model) model TRICORE_CPU_TYPE_SUFFIX /* helpers.c */ int cpu_tricore_handle_mmu_fault(CPUState *cpu, target_ulong address, |