Skip to content

Commit d5ebe62

Browse files
Igor Mammedovehabkost
Igor Mammedov
authored andcommitted
sh4: simplify superh_cpu_class_by_name()
currently for sh4 cpu_model argument for '-cpu' option could be either 'cpu model' name or cpu_typename. however typically '-cpu' takes 'cpu model' name and cpu type for sh4 target isn't advertised publicly ('-cpu help' prints only 'cpu model' names) so we shouldn't care about this use case (it's more of a bug). 1. Drop '-cpu cpu_typename' to align with the rest of targets. 2. Compose searched for typename from cpu model and use it with object_class_by_name() directly instead of over-complicated object_class_get_list() g_slist_find_custom() + superh_cpu_name_compare() With #1 droped, #2 could be used for both lookups which simplifies superh_cpu_class_by_name() quite a bit. Signed-off-by: Igor Mammedov <[email protected]> Acked-by: Philippe Mathieu-Daudé <[email protected]> Message-Id: <[email protected]> [ehabkost: Include fixup sent by Igor] Reviewed-by: Philippe Mathieu-Daudé <[email protected]> Signed-off-by: Eduardo Habkost <[email protected]>
1 parent 974e58d commit d5ebe62

File tree

2 files changed

+13
-23
lines changed

2 files changed

+13
-23
lines changed

Diff for: linux-user/main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -4331,7 +4331,7 @@ int main(int argc, char **argv, char **envp)
43314331
cpu_model = "750";
43324332
# endif
43334333
#elif defined TARGET_SH4
4334-
cpu_model = TYPE_SH7785_CPU;
4334+
cpu_model = "sh7785";
43354335
#elif defined TARGET_S390X
43364336
cpu_model = "qemu";
43374337
#else

Diff for: target/sh4/cpu.c

+12-22
Original file line numberDiff line numberDiff line change
@@ -120,36 +120,26 @@ void sh4_cpu_list(FILE *f, fprintf_function cpu_fprintf)
120120
g_slist_free(list);
121121
}
122122

123-
static gint superh_cpu_name_compare(gconstpointer a, gconstpointer b)
124-
{
125-
const SuperHCPUClass *scc = SUPERH_CPU_CLASS(a);
126-
const char *name = b;
127-
128-
return strcasecmp(scc->name, name);
129-
}
130-
131123
static ObjectClass *superh_cpu_class_by_name(const char *cpu_model)
132124
{
133125
ObjectClass *oc;
134-
GSList *list, *item;
126+
char *s, *typename = NULL;
135127

136-
if (strcasecmp(cpu_model, "any") == 0) {
137-
return object_class_by_name(TYPE_SH7750R_CPU);
128+
s = g_ascii_strdown(cpu_model, -1);
129+
if (strcmp(s, "any") == 0) {
130+
oc = object_class_by_name(TYPE_SH7750R_CPU);
131+
goto out;
138132
}
139133

140-
oc = object_class_by_name(cpu_model);
141-
if (oc != NULL && object_class_dynamic_cast(oc, TYPE_SUPERH_CPU) != NULL
142-
&& !object_class_is_abstract(oc)) {
143-
return oc;
134+
typename = g_strdup_printf(SUPERH_CPU_TYPE_NAME("%s"), s);
135+
oc = object_class_by_name(typename);
136+
if (oc != NULL && object_class_is_abstract(oc)) {
137+
oc = NULL;
144138
}
145139

146-
oc = NULL;
147-
list = object_class_get_list(TYPE_SUPERH_CPU, false);
148-
item = g_slist_find_custom(list, cpu_model, superh_cpu_name_compare);
149-
if (item != NULL) {
150-
oc = item->data;
151-
}
152-
g_slist_free(list);
140+
out:
141+
g_free(s);
142+
g_free(typename);
153143
return oc;
154144
}
155145

0 commit comments

Comments
 (0)