mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 12:09:58 +00:00
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>
This commit is contained in:
parent
5eab493d7a
commit
c6678108ba
@ -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,
|
||||
};
|
||||
#define DEFINE_LM32_CPU_TYPE(cpu_model, initfn) \
|
||||
{ \
|
||||
.parent = TYPE_LM32_CPU, \
|
||||
.name = LM32_CPU_TYPE_NAME(cpu_model), \
|
||||
.instance_init = initfn, \
|
||||
}
|
||||
|
||||
type_info.name = g_strdup_printf("%s-" TYPE_LM32_CPU, info->name);
|
||||
type_register(&type_info);
|
||||
g_free((void *)type_info.name);
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user