Commit 78c04153 authored by Sam Ravnborg's avatar Sam Ravnborg

kbuild: Lindent genksyms.c

No fix-ups applied yet. Just the raw Lindent output.
Signed-off-by: default avatarSam Ravnborg <sam@ravnborg.org>
parent c79c7b09
...@@ -51,14 +51,13 @@ static int nsyms; ...@@ -51,14 +51,13 @@ static int nsyms;
static struct symbol *expansion_trail; static struct symbol *expansion_trail;
static const char * const symbol_type_name[] = { static const char *const symbol_type_name[] = {
"normal", "typedef", "enum", "struct", "union" "normal", "typedef", "enum", "struct", "union"
}; };
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
static const unsigned int crctab32[] = static const unsigned int crctab32[] = {
{
0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U, 0x00000000U, 0x77073096U, 0xee0e612cU, 0x990951baU, 0x076dc419U,
0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U, 0x706af48fU, 0xe963a535U, 0x9e6495a3U, 0x0edb8832U, 0x79dcb8a4U,
0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U, 0xe0d5e91eU, 0x97d2d988U, 0x09b64c2bU, 0x7eb17cbdU, 0xe7b82d07U,
...@@ -119,25 +118,21 @@ partial_crc32_one(unsigned char c, unsigned long crc) ...@@ -119,25 +118,21 @@ partial_crc32_one(unsigned char c, unsigned long crc)
return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8); return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8);
} }
static inline unsigned long static inline unsigned long partial_crc32(const char *s, unsigned long crc)
partial_crc32(const char *s, unsigned long crc)
{ {
while (*s) while (*s)
crc = partial_crc32_one(*s++, crc); crc = partial_crc32_one(*s++, crc);
return crc; return crc;
} }
static inline unsigned long static inline unsigned long crc32(const char *s)
crc32(const char *s)
{ {
return partial_crc32(s, 0xffffffff) ^ 0xffffffff; return partial_crc32(s, 0xffffffff) ^ 0xffffffff;
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
static inline enum symbol_type static inline enum symbol_type map_to_ns(enum symbol_type t)
map_to_ns(enum symbol_type t)
{ {
if (t == SYM_TYPEDEF) if (t == SYM_TYPEDEF)
t = SYM_NORMAL; t = SYM_NORMAL;
...@@ -146,29 +141,28 @@ map_to_ns(enum symbol_type t) ...@@ -146,29 +141,28 @@ map_to_ns(enum symbol_type t)
return t; return t;
} }
struct symbol * struct symbol *find_symbol(const char *name, enum symbol_type ns)
find_symbol(const char *name, enum symbol_type ns)
{ {
unsigned long h = crc32(name) % HASH_BUCKETS; unsigned long h = crc32(name) % HASH_BUCKETS;
struct symbol *sym; struct symbol *sym;
for (sym = symtab[h]; sym ; sym = sym->hash_next) for (sym = symtab[h]; sym; sym = sym->hash_next)
if (map_to_ns(sym->type) == map_to_ns(ns) && strcmp(name, sym->name) == 0) if (map_to_ns(sym->type) == map_to_ns(ns)
&& strcmp(name, sym->name) == 0)
break; break;
return sym; return sym;
} }
struct symbol * struct symbol *add_symbol(const char *name, enum symbol_type type,
add_symbol(const char *name, enum symbol_type type, struct string_list *defn, int is_extern) struct string_list *defn, int is_extern)
{ {
unsigned long h = crc32(name) % HASH_BUCKETS; unsigned long h = crc32(name) % HASH_BUCKETS;
struct symbol *sym; struct symbol *sym;
for (sym = symtab[h]; sym ; sym = sym->hash_next) for (sym = symtab[h]; sym; sym = sym->hash_next)
if (map_to_ns(sym->type) == map_to_ns(type) if (map_to_ns(sym->type) == map_to_ns(type)
&& strcmp(name, sym->name) == 0) && strcmp(name, sym->name) == 0) {
{
if (!equal_list(sym->defn, defn)) if (!equal_list(sym->defn, defn))
error_with_pos("redefinition of %s", name); error_with_pos("redefinition of %s", name);
return sym; return sym;
...@@ -184,9 +178,9 @@ add_symbol(const char *name, enum symbol_type type, struct string_list *defn, in ...@@ -184,9 +178,9 @@ add_symbol(const char *name, enum symbol_type type, struct string_list *defn, in
sym->hash_next = symtab[h]; sym->hash_next = symtab[h];
symtab[h] = sym; symtab[h] = sym;
if (flag_debug) if (flag_debug) {
{ fprintf(debugfile, "Defn for %s %s == <",
fprintf(debugfile, "Defn for %s %s == <", symbol_type_name[type], name); symbol_type_name[type], name);
if (is_extern) if (is_extern)
fputs("extern ", debugfile); fputs("extern ", debugfile);
print_list(debugfile, defn); print_list(debugfile, defn);
...@@ -197,29 +191,24 @@ add_symbol(const char *name, enum symbol_type type, struct string_list *defn, in ...@@ -197,29 +191,24 @@ add_symbol(const char *name, enum symbol_type type, struct string_list *defn, in
return sym; return sym;
} }
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
inline void inline void free_node(struct string_list *node)
free_node(struct string_list *node)
{ {
free(node->string); free(node->string);
free(node); free(node);
} }
void void free_list(struct string_list *s, struct string_list *e)
free_list(struct string_list *s, struct string_list *e)
{ {
while (s != e) while (s != e) {
{
struct string_list *next = s->next; struct string_list *next = s->next;
free_node(s); free_node(s);
s = next; s = next;
} }
} }
inline struct string_list * inline struct string_list *copy_node(struct string_list *node)
copy_node(struct string_list *node)
{ {
struct string_list *newnode; struct string_list *newnode;
...@@ -230,8 +219,7 @@ copy_node(struct string_list *node) ...@@ -230,8 +219,7 @@ copy_node(struct string_list *node)
return newnode; return newnode;
} }
struct string_list * struct string_list *copy_list(struct string_list *s, struct string_list *e)
copy_list(struct string_list *s, struct string_list *e)
{ {
struct string_list *h, *p; struct string_list *h, *p;
...@@ -246,11 +234,9 @@ copy_list(struct string_list *s, struct string_list *e) ...@@ -246,11 +234,9 @@ copy_list(struct string_list *s, struct string_list *e)
return h; return h;
} }
int int equal_list(struct string_list *a, struct string_list *b)
equal_list(struct string_list *a, struct string_list *b)
{ {
while (a && b) while (a && b) {
{
if (a->tag != b->tag || strcmp(a->string, b->string)) if (a->tag != b->tag || strcmp(a->string, b->string))
return 0; return 0;
a = a->next; a = a->next;
...@@ -260,11 +246,9 @@ equal_list(struct string_list *a, struct string_list *b) ...@@ -260,11 +246,9 @@ equal_list(struct string_list *a, struct string_list *b)
return !a && !b; return !a && !b;
} }
static inline void static inline void print_node(FILE * f, struct string_list *list)
print_node(FILE *f, struct string_list *list)
{ {
switch (list->tag) switch (list->tag) {
{
case SYM_STRUCT: case SYM_STRUCT:
putc('s', f); putc('s', f);
goto printit; goto printit;
...@@ -286,21 +270,19 @@ print_node(FILE *f, struct string_list *list) ...@@ -286,21 +270,19 @@ print_node(FILE *f, struct string_list *list)
} }
} }
void void print_list(FILE * f, struct string_list *list)
print_list(FILE *f, struct string_list *list)
{ {
struct string_list **e, **b; struct string_list **e, **b;
struct string_list *tmp, **tmp2; struct string_list *tmp, **tmp2;
int elem = 1; int elem = 1;
if (list == NULL) if (list == NULL) {
{
fputs("(nil)", f); fputs("(nil)", f);
return; return;
} }
tmp = list; tmp = list;
while((tmp = tmp->next) != NULL) while ((tmp = tmp->next) != NULL)
elem++; elem++;
b = alloca(elem * sizeof(*e)); b = alloca(elem * sizeof(*e));
...@@ -308,11 +290,10 @@ print_list(FILE *f, struct string_list *list) ...@@ -308,11 +290,10 @@ print_list(FILE *f, struct string_list *list)
tmp2 = e - 1; tmp2 = e - 1;
(*tmp2--) = list; (*tmp2--) = list;
while((list = list->next) != NULL) while ((list = list->next) != NULL)
*(tmp2--) = list; *(tmp2--) = list;
while (b != e) while (b != e) {
{
print_node(f, *b++); print_node(f, *b++);
putc(' ', f); putc(' ', f);
} }
...@@ -329,7 +310,7 @@ expand_and_crc_list(struct string_list *list, unsigned long crc) ...@@ -329,7 +310,7 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
return crc; return crc;
tmp = list; tmp = list;
while((tmp = tmp->next) != NULL) while ((tmp = tmp->next) != NULL)
elem++; elem++;
b = alloca(elem * sizeof(*e)); b = alloca(elem * sizeof(*e));
...@@ -340,14 +321,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc) ...@@ -340,14 +321,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
while ((list = list->next) != NULL) while ((list = list->next) != NULL)
*(tmp2--) = list; *(tmp2--) = list;
while (b != e) while (b != e) {
{
struct string_list *cur; struct string_list *cur;
struct symbol *subsym; struct symbol *subsym;
cur = *(b++); cur = *(b++);
switch (cur->tag) switch (cur->tag) {
{
case SYM_NORMAL: case SYM_NORMAL:
if (flag_dump_defs) if (flag_dump_defs)
fprintf(debugfile, "%s ", cur->string); fprintf(debugfile, "%s ", cur->string);
...@@ -357,15 +336,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc) ...@@ -357,15 +336,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
case SYM_TYPEDEF: case SYM_TYPEDEF:
subsym = find_symbol(cur->string, cur->tag); subsym = find_symbol(cur->string, cur->tag);
if (subsym->expansion_trail) if (subsym->expansion_trail) {
{
if (flag_dump_defs) if (flag_dump_defs)
fprintf(debugfile, "%s ", cur->string); fprintf(debugfile, "%s ", cur->string);
crc = partial_crc32(cur->string, crc); crc = partial_crc32(cur->string, crc);
crc = partial_crc32_one(' ', crc); crc = partial_crc32_one(' ', crc);
} } else {
else
{
subsym->expansion_trail = expansion_trail; subsym->expansion_trail = expansion_trail;
expansion_trail = subsym; expansion_trail = subsym;
crc = expand_and_crc_list(subsym->defn, crc); crc = expand_and_crc_list(subsym->defn, crc);
...@@ -376,12 +352,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc) ...@@ -376,12 +352,12 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
case SYM_UNION: case SYM_UNION:
case SYM_ENUM: case SYM_ENUM:
subsym = find_symbol(cur->string, cur->tag); subsym = find_symbol(cur->string, cur->tag);
if (!subsym) if (!subsym) {
{
struct string_list *n, *t = NULL; struct string_list *n, *t = NULL;
error_with_pos("expand undefined %s %s", error_with_pos("expand undefined %s %s",
symbol_type_name[cur->tag], cur->string); symbol_type_name[cur->tag],
cur->string);
n = xmalloc(sizeof(*n)); n = xmalloc(sizeof(*n));
n->string = xstrdup(symbol_type_name[cur->tag]); n->string = xstrdup(symbol_type_name[cur->tag]);
...@@ -400,23 +376,23 @@ expand_and_crc_list(struct string_list *list, unsigned long crc) ...@@ -400,23 +376,23 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
n->tag = SYM_NORMAL; n->tag = SYM_NORMAL;
n->next = t; n->next = t;
subsym = add_symbol(cur->string, cur->tag, n, 0); subsym =
add_symbol(cur->string, cur->tag, n, 0);
} }
if (subsym->expansion_trail) if (subsym->expansion_trail) {
{ if (flag_dump_defs) {
if (flag_dump_defs) fprintf(debugfile, "%s %s ",
{ symbol_type_name[cur->tag],
fprintf(debugfile, "%s %s ", symbol_type_name[cur->tag],
cur->string); cur->string);
} }
crc = partial_crc32(symbol_type_name[cur->tag], crc); crc =
partial_crc32(symbol_type_name[cur->tag],
crc);
crc = partial_crc32_one(' ', crc); crc = partial_crc32_one(' ', crc);
crc = partial_crc32(cur->string, crc); crc = partial_crc32(cur->string, crc);
crc = partial_crc32_one(' ', crc); crc = partial_crc32_one(' ', crc);
} } else {
else
{
subsym->expansion_trail = expansion_trail; subsym->expansion_trail = expansion_trail;
expansion_trail = subsym; expansion_trail = subsym;
crc = expand_and_crc_list(subsym->defn, crc); crc = expand_and_crc_list(subsym->defn, crc);
...@@ -428,16 +404,14 @@ expand_and_crc_list(struct string_list *list, unsigned long crc) ...@@ -428,16 +404,14 @@ expand_and_crc_list(struct string_list *list, unsigned long crc)
return crc; return crc;
} }
void void export_symbol(const char *name)
export_symbol(const char *name)
{ {
struct symbol *sym; struct symbol *sym;
sym = find_symbol(name, SYM_NORMAL); sym = find_symbol(name, SYM_NORMAL);
if (!sym) if (!sym)
error_with_pos("export undefined symbol %s", name); error_with_pos("export undefined symbol %s", name);
else else {
{
unsigned long crc; unsigned long crc;
if (flag_dump_defs) if (flag_dump_defs)
...@@ -448,8 +422,7 @@ export_symbol(const char *name) ...@@ -448,8 +422,7 @@ export_symbol(const char *name)
crc = expand_and_crc_list(sym->defn, 0xffffffff) ^ 0xffffffff; crc = expand_and_crc_list(sym->defn, 0xffffffff) ^ 0xffffffff;
sym = expansion_trail; sym = expansion_trail;
while (sym != (struct symbol *)-1L) while (sym != (struct symbol *)-1L) {
{
struct symbol *n = sym->expansion_trail; struct symbol *n = sym->expansion_trail;
sym->expansion_trail = 0; sym->expansion_trail = 0;
sym = n; sym = n;
...@@ -465,13 +438,11 @@ export_symbol(const char *name) ...@@ -465,13 +438,11 @@ export_symbol(const char *name)
/*----------------------------------------------------------------------*/ /*----------------------------------------------------------------------*/
void void error(const char *fmt, ...)
error(const char *fmt, ...)
{ {
va_list args; va_list args;
if (flag_warnings) if (flag_warnings) {
{
va_start(args, fmt); va_start(args, fmt);
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);
va_end(args); va_end(args);
...@@ -481,14 +452,13 @@ error(const char *fmt, ...) ...@@ -481,14 +452,13 @@ error(const char *fmt, ...)
} }
} }
void void error_with_pos(const char *fmt, ...)
error_with_pos(const char *fmt, ...)
{ {
va_list args; va_list args;
if (flag_warnings) if (flag_warnings) {
{ fprintf(stderr, "%s:%d: ", cur_filename ? : "<stdin>",
fprintf(stderr, "%s:%d: ", cur_filename ? : "<stdin>", cur_line); cur_line);
va_start(args, fmt); va_start(args, fmt);
vfprintf(stderr, fmt, args); vfprintf(stderr, fmt, args);
...@@ -499,12 +469,9 @@ error_with_pos(const char *fmt, ...) ...@@ -499,12 +469,9 @@ error_with_pos(const char *fmt, ...)
} }
} }
void genksyms_usage(void) void genksyms_usage(void)
{ {
fputs("Usage:\n" fputs("Usage:\n" "genksyms [-dDwqhV] > /path/to/.tmp_obj.ver\n" "\n"
"genksyms [-dDwqhV] > /path/to/.tmp_obj.ver\n"
"\n"
#ifdef __GNU_LIBRARY__ #ifdef __GNU_LIBRARY__
" -d, --debug Increment the debug level (repeatable)\n" " -d, --debug Increment the debug level (repeatable)\n"
" -D, --dump Dump expanded symbol defs (for debugging only)\n" " -D, --dump Dump expanded symbol defs (for debugging only)\n"
...@@ -523,8 +490,7 @@ void genksyms_usage(void) ...@@ -523,8 +490,7 @@ void genksyms_usage(void)
, stderr); , stderr);
} }
int int main(int argc, char **argv)
main(int argc, char **argv)
{ {
int o; int o;
...@@ -545,8 +511,7 @@ main(int argc, char **argv) ...@@ -545,8 +511,7 @@ main(int argc, char **argv)
#else /* __GNU_LIBRARY__ */ #else /* __GNU_LIBRARY__ */
while ((o = getopt(argc, argv, "a:dwqVDk:p:")) != EOF) while ((o = getopt(argc, argv, "a:dwqVDk:p:")) != EOF)
#endif /* __GNU_LIBRARY__ */ #endif /* __GNU_LIBRARY__ */
switch (o) switch (o) {
{
case 'a': case 'a':
arch = optarg; arch = optarg;
break; break;
...@@ -572,8 +537,7 @@ main(int argc, char **argv) ...@@ -572,8 +537,7 @@ main(int argc, char **argv)
genksyms_usage(); genksyms_usage();
return 1; return 1;
} }
if ((strcmp(arch, "v850") == 0) || if ((strcmp(arch, "v850") == 0) || (strcmp(arch, "h8300") == 0))
(strcmp(arch, "h8300") == 0))
mod_prefix = "_"; mod_prefix = "_";
{ {
extern int yydebug; extern int yydebug;
...@@ -588,10 +552,10 @@ main(int argc, char **argv) ...@@ -588,10 +552,10 @@ main(int argc, char **argv)
yyparse(); yyparse();
if (flag_debug) if (flag_debug) {
{
fprintf(debugfile, "Hash table occupancy %d/%d = %g\n", fprintf(debugfile, "Hash table occupancy %d/%d = %g\n",
nsyms, HASH_BUCKETS, (double)nsyms / (double)HASH_BUCKETS); nsyms, HASH_BUCKETS,
(double)nsyms / (double)HASH_BUCKETS);
} }
return errors != 0; return errors != 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment