aboutsummaryrefslogtreecommitdiff
path: root/target
diff options
context:
space:
mode:
authorIgor Mammedov <imammedo@redhat.com>2017-10-05 15:50:42 +0200
committerEduardo Habkost <ehabkost@redhat.com>2017-10-27 16:03:54 +0200
commitc6678108ba2c427d2cac19a5e1ec4c5c58e10fcb (patch)
tree89735f7279c779dfa5228d17df44a9533a57abff /target
parent5eab493d7a01a3650f25f2e396e37fca913cb97e (diff)
lm32: cleanup cpu type name composition
introduce LM32_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> Acked-by: Michael Walle <michael@walle.cc> Message-Id: <1507211474-188400-9-git-send-email-imammedo@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Diffstat (limited to 'target')
-rw-r--r--target/lm32/cpu.c74
-rw-r--r--target/lm32/cpu.h3
2 files changed, 25 insertions, 52 deletions
diff --git a/target/lm32/cpu.c b/target/lm32/cpu.c
index 7f3a292f2b..6f5c14767b 100644
--- a/target/lm32/cpu.c
+++ b/target/lm32/cpu.c
@@ -51,7 +51,7 @@ static void lm32_cpu_list_entry(gpointer data, gpointer user_data)
const char *typename = object_class_get_name(oc);
char *name;
- name = g_strndup(typename, strlen(typename) - strlen("-" TYPE_LM32_CPU));
+ name = g_strndup(typename, strlen(typename) - strlen(LM32_CPU_TYPE_SUFFIX));
(*s->cpu_fprintf)(s->file, " %s\n", name);
g_free(name);
}
@@ -215,32 +215,12 @@ static void lm32_full_cpu_initfn(Object *obj)
| LM32_FEATURE_CYCLE_COUNT;
}
-typedef struct LM32CPUInfo {
- const char *name;
- void (*initfn)(Object *obj);
-} LM32CPUInfo;
-
-static const LM32CPUInfo lm32_cpus[] = {
- {
- .name = "lm32-basic",
- .initfn = lm32_basic_cpu_initfn,
- },
- {
- .name = "lm32-standard",
- .initfn = lm32_standard_cpu_initfn,
- },
- {
- .name = "lm32-full",
- .initfn = lm32_full_cpu_initfn,
- },
-};
-
static ObjectClass *lm32_cpu_class_by_name(const char *cpu_model)
{
ObjectClass *oc;
char *typename;
- typename = g_strdup_printf("%s-" TYPE_LM32_CPU, cpu_model);
+ typename = g_strdup_printf(LM32_CPU_TYPE_NAME("%s"), cpu_model);
oc = object_class_by_name(typename);
g_free(typename);
if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_LM32_CPU) ||
@@ -283,36 +263,26 @@ static void lm32_cpu_class_init(ObjectClass *oc, void *data)
cc->tcg_initialize = lm32_translate_init;
}
-static void lm32_register_cpu_type(const LM32CPUInfo *info)
-{
- TypeInfo type_info = {
- .parent = TYPE_LM32_CPU,
- .instance_init = info->initfn,
- };
-
- type_info.name = g_strdup_printf("%s-" TYPE_LM32_CPU, info->name);
- type_register(&type_info);
- g_free((void *)type_info.name);
-}
+#define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \
+ { \
+ .parent = TYPE_LM32_CPU, \
+ .name = LM32_CPU_TYPE_NAME(cpu_model), \
+ .instance_init = initfn, \
+ }
-static const TypeInfo lm32_cpu_type_info = {
- .name = TYPE_LM32_CPU,
- .parent = TYPE_CPU,
- .instance_size = sizeof(LM32CPU),
- .instance_init = lm32_cpu_initfn,
- .abstract = true,
- .class_size = sizeof(LM32CPUClass),
- .class_init = lm32_cpu_class_init,
+static const TypeInfo lm32_cpus_type_infos[] = {
+ { /* base class should be registered first */
+ .name = TYPE_LM32_CPU,
+ .parent = TYPE_CPU,
+ .instance_size = sizeof(LM32CPU),
+ .instance_init = lm32_cpu_initfn,
+ .abstract = true,
+ .class_size = sizeof(LM32CPUClass),
+ .class_init = lm32_cpu_class_init,
+ },
+ DEFINE_LM32_CPU_TYPE("lm32-basic", lm32_basic_cpu_initfn),
+ DEFINE_LM32_CPU_TYPE("lm32-standard", lm32_standard_cpu_initfn),
+ DEFINE_LM32_CPU_TYPE("lm32-full", lm32_full_cpu_initfn),
};
-static void lm32_cpu_register_types(void)
-{
- int i;
-
- type_register_static(&lm32_cpu_type_info);
- for (i = 0; i < ARRAY_SIZE(lm32_cpus); i++) {
- lm32_register_cpu_type(&lm32_cpus[i]);
- }
-}
-
-type_init(lm32_cpu_register_types)
+DEFINE_TYPES(lm32_cpus_type_infos)
diff --git a/target/lm32/cpu.h b/target/lm32/cpu.h
index de265b50d1..2279594f40 100644
--- a/target/lm32/cpu.h
+++ b/target/lm32/cpu.h
@@ -257,6 +257,9 @@ bool lm32_cpu_do_semihosting(CPUState *cs);
#define cpu_init(cpu_model) cpu_generic_init(TYPE_LM32_CPU, cpu_model)
+#define LM32_CPU_TYPE_SUFFIX "-" TYPE_LM32_CPU
+#define LM32_CPU_TYPE_NAME(model) model LM32_CPU_TYPE_SUFFIX
+
#define cpu_list lm32_cpu_list
#define cpu_signal_handler cpu_lm32_signal_handler