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>
This commit is contained in:
Igor Mammedov 2017-10-05 15:50:49 +02:00 committed by Eduardo Habkost
parent a7f981cc9f
commit 0255db239e
2 changed files with 23 additions and 42 deletions

View File

@ -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 },
};
static void cpu_register(const MoxieCPUInfo *info)
{
TypeInfo type_info = {
.parent = TYPE_MOXIE_CPU,
.instance_size = sizeof(MoxieCPU),
.instance_init = info->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,
};
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]);
#define DEFINE_MOXIE_CPU_TYPE(cpu_model, initfn) \
{ \
.parent = TYPE_MOXIE_CPU, \
.instance_init = initfn, \
.name = MOXIE_CPU_TYPE_NAME(cpu_model), \
}
}
type_init(moxie_cpu_register_types)
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 = moxie_cpu_initfn,
.class_size = sizeof(MoxieCPUClass),
.class_init = moxie_cpu_class_init,
},
DEFINE_MOXIE_CPU_TYPE("MoxieLite", moxielite_initfn),
DEFINE_MOXIE_CPU_TYPE("any", moxie_any_initfn),
};
DEFINE_TYPES(moxie_cpus_type_infos)

View File

@ -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)