Skip to content

Commit 7ec8eda

Browse files
committed
genksyms: Simplify printing of symbol types
Instead of special-casing SYM_NORMAL, do not map any name to it. Also explicitly set the single-letter name of the symbol type, which will be needed by a further patch. The only user-visible change is one debug printf. Signed-off-by: Michal Marek <mmarek@suse.cz> Acked-by: Sam Ravnborg <sam@ravnborg.org>
1 parent 95f1d63 commit 7ec8eda

1 file changed

Lines changed: 27 additions & 16 deletions

File tree

‎scripts/genksyms/genksyms.c‎

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ static int nsyms;
5353
static struct symbol *expansion_trail;
5454
static struct symbol *visited_symbols;
5555

56-
static const char *const symbol_type_name[] = {
57-
"normal", "typedef", "enum", "struct", "union"
56+
static const struct {
57+
int n;
58+
const char *name;
59+
} symbol_types[] = {
60+
[SYM_NORMAL] = { 0, NULL},
61+
[SYM_TYPEDEF] = {'t', "typedef"},
62+
[SYM_ENUM] = {'e', "enum"},
63+
[SYM_STRUCT] = {'s', "struct"},
64+
[SYM_UNION] = {'u', "union"},
5865
};
5966

6067
static int equal_list(struct string_list *a, struct string_list *b);
@@ -247,8 +254,12 @@ static struct symbol *__add_symbol(const char *name, enum symbol_type type,
247254
sym->is_override = 0;
248255

249256
if (flag_debug) {
250-
fprintf(debugfile, "Defn for %s %s == <",
251-
symbol_type_name[type], name);
257+
if (symbol_types[type].name)
258+
fprintf(debugfile, "Defn for %s %s == <",
259+
symbol_types[type].name, name);
260+
else
261+
fprintf(debugfile, "Defn for type%d %s == <",
262+
type, name);
252263
if (is_extern)
253264
fputs("extern ", debugfile);
254265
print_list(debugfile, defn);
@@ -346,8 +357,8 @@ static struct string_list *read_node(FILE *f)
346357
if (node.string[1] == '#') {
347358
int n;
348359

349-
for (n = 0; n < ARRAY_SIZE(symbol_type_name); n++) {
350-
if (node.string[0] == symbol_type_name[n][0]) {
360+
for (n = 0; n < ARRAY_SIZE(symbol_types); n++) {
361+
if (node.string[0] == symbol_types[n].n) {
351362
node.tag = n;
352363
node.string += 2;
353364
return copy_node(&node);
@@ -397,8 +408,8 @@ static void read_reference(FILE *f)
397408

398409
static void print_node(FILE * f, struct string_list *list)
399410
{
400-
if (list->tag != SYM_NORMAL) {
401-
putc(symbol_type_name[list->tag][0], f);
411+
if (symbol_types[list->tag].n) {
412+
putc(symbol_types[list->tag].n, f);
402413
putc('#', f);
403414
}
404415
fputs(list->string, f);
@@ -491,11 +502,11 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
491502
struct string_list *n, *t = NULL;
492503

493504
error_with_pos("expand undefined %s %s",
494-
symbol_type_name[cur->tag],
505+
symbol_types[cur->tag].name,
495506
cur->string);
496507

497508
n = xmalloc(sizeof(*n));
498-
n->string = xstrdup(symbol_type_name[cur->tag]);
509+
n->string = xstrdup(symbol_types[cur->tag].name);
499510
n->tag = SYM_NORMAL;
500511
n->next = t;
501512
t = n;
@@ -530,11 +541,11 @@ static unsigned long expand_and_crc_sym(struct symbol *sym, unsigned long crc)
530541
if (subsym->expansion_trail) {
531542
if (flag_dump_defs) {
532543
fprintf(debugfile, "%s %s ",
533-
symbol_type_name[cur->tag],
544+
symbol_types[cur->tag].name,
534545
cur->string);
535546
}
536547

537-
crc = partial_crc32(symbol_type_name[cur->tag],
548+
crc = partial_crc32(symbol_types[cur->tag].name,
538549
crc);
539550
crc = partial_crc32_one(' ', crc);
540551
crc = partial_crc32(cur->string, crc);
@@ -624,8 +635,8 @@ static void print_location(void)
624635

625636
static void print_type_name(enum symbol_type type, const char *name)
626637
{
627-
if (type != SYM_NORMAL)
628-
fprintf(stderr, "%s %s", symbol_type_name[type], name);
638+
if (symbol_types[type].name)
639+
fprintf(stderr, "%s %s", symbol_types[type].name, name);
629640
else
630641
fprintf(stderr, "%s", name);
631642
}
@@ -771,8 +782,8 @@ int main(int argc, char **argv)
771782

772783
if (sym->is_override)
773784
fputs("override ", dumpfile);
774-
if (sym->type != SYM_NORMAL) {
775-
putc(symbol_type_name[sym->type][0], dumpfile);
785+
if (symbol_types[sym->type].n) {
786+
putc(symbol_types[sym->type].n, dumpfile);
776787
putc('#', dumpfile);
777788
}
778789
fputs(sym->name, dumpfile);

0 commit comments

Comments
 (0)