unicore32: cleanup cpu type name composition
use new UNICORE32_CPU_TYPE_NAME to compose CPU type name and get rid of intermediate UniCore32CPUInfo/uc32_cpu_register_types() which is replaced by static TypeInfo array and type_init_from_array() Signed-off-by: Igor Mammedov <imammedo@redhat.com> Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> Message-Id: <1507211474-188400-28-git-send-email-imammedo@redhat.com> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
This commit is contained in:
parent
f83eb10d79
commit
6a82686647
@ -44,7 +44,7 @@ static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
|
||||
ObjectClass *oc;
|
||||
char *typename;
|
||||
|
||||
typename = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, cpu_model);
|
||||
typename = g_strdup_printf(UNICORE32_CPU_TYPE_NAME("%s"), cpu_model);
|
||||
oc = object_class_by_name(typename);
|
||||
g_free(typename);
|
||||
if (oc != NULL && (!object_class_dynamic_cast(oc, TYPE_UNICORE32_CPU) ||
|
||||
@ -54,11 +54,6 @@ static ObjectClass *uc32_cpu_class_by_name(const char *cpu_model)
|
||||
return oc;
|
||||
}
|
||||
|
||||
typedef struct UniCore32CPUInfo {
|
||||
const char *name;
|
||||
void (*instance_init)(Object *obj);
|
||||
} UniCore32CPUInfo;
|
||||
|
||||
static void unicore_ii_cpu_initfn(Object *obj)
|
||||
{
|
||||
UniCore32CPU *cpu = UNICORE32_CPU(obj);
|
||||
@ -90,11 +85,6 @@ static void uc32_any_cpu_initfn(Object *obj)
|
||||
set_snan_bit_is_one(1, &env->ucf64.fp_status);
|
||||
}
|
||||
|
||||
static const UniCore32CPUInfo uc32_cpus[] = {
|
||||
{ .name = "UniCore-II", .instance_init = unicore_ii_cpu_initfn },
|
||||
{ .name = "any", .instance_init = uc32_any_cpu_initfn },
|
||||
};
|
||||
|
||||
static void uc32_cpu_realizefn(DeviceState *dev, Error **errp)
|
||||
{
|
||||
CPUState *cs = CPU(dev);
|
||||
@ -160,36 +150,25 @@ static void uc32_cpu_class_init(ObjectClass *oc, void *data)
|
||||
dc->vmsd = &vmstate_uc32_cpu;
|
||||
}
|
||||
|
||||
static void uc32_register_cpu_type(const UniCore32CPUInfo *info)
|
||||
{
|
||||
TypeInfo type_info = {
|
||||
.parent = TYPE_UNICORE32_CPU,
|
||||
.instance_init = info->instance_init,
|
||||
};
|
||||
#define DEFINE_UNICORE32_CPU_TYPE(cpu_model, initfn) \
|
||||
{ \
|
||||
.parent = TYPE_UNICORE32_CPU, \
|
||||
.instance_init = initfn, \
|
||||
.name = UNICORE32_CPU_TYPE_NAME(cpu_model), \
|
||||
}
|
||||
|
||||
type_info.name = g_strdup_printf("%s-" TYPE_UNICORE32_CPU, info->name);
|
||||
type_register(&type_info);
|
||||
g_free((void *)type_info.name);
|
||||
}
|
||||
|
||||
static const TypeInfo uc32_cpu_type_info = {
|
||||
.name = TYPE_UNICORE32_CPU,
|
||||
.parent = TYPE_CPU,
|
||||
.instance_size = sizeof(UniCore32CPU),
|
||||
.instance_init = uc32_cpu_initfn,
|
||||
.abstract = true,
|
||||
.class_size = sizeof(UniCore32CPUClass),
|
||||
.class_init = uc32_cpu_class_init,
|
||||
static const TypeInfo uc32_cpu_type_infos[] = {
|
||||
{
|
||||
.name = TYPE_UNICORE32_CPU,
|
||||
.parent = TYPE_CPU,
|
||||
.instance_size = sizeof(UniCore32CPU),
|
||||
.instance_init = uc32_cpu_initfn,
|
||||
.abstract = true,
|
||||
.class_size = sizeof(UniCore32CPUClass),
|
||||
.class_init = uc32_cpu_class_init,
|
||||
},
|
||||
DEFINE_UNICORE32_CPU_TYPE("UniCore-II", unicore_ii_cpu_initfn),
|
||||
DEFINE_UNICORE32_CPU_TYPE("any", uc32_any_cpu_initfn),
|
||||
};
|
||||
|
||||
static void uc32_cpu_register_types(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
type_register_static(&uc32_cpu_type_info);
|
||||
for (i = 0; i < ARRAY_SIZE(uc32_cpus); i++) {
|
||||
uc32_register_cpu_type(&uc32_cpus[i]);
|
||||
}
|
||||
}
|
||||
|
||||
type_init(uc32_cpu_register_types)
|
||||
DEFINE_TYPES(uc32_cpu_type_infos)
|
||||
|
@ -167,6 +167,9 @@ static inline int cpu_mmu_index(CPUUniCore32State *env, bool ifetch)
|
||||
|
||||
#define cpu_init(cpu_model) cpu_generic_init(TYPE_UNICORE32_CPU, cpu_model)
|
||||
|
||||
#define UNICORE32_CPU_TYPE_SUFFIX "-" TYPE_UNICORE32_CPU
|
||||
#define UNICORE32_CPU_TYPE_NAME(model) model UNICORE32_CPU_TYPE_SUFFIX
|
||||
|
||||
static inline void cpu_get_tb_cpu_state(CPUUniCore32State *env, target_ulong *pc,
|
||||
target_ulong *cs_base, uint32_t *flags)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user