diff options
Diffstat (limited to 'scripts/genksyms')
-rw-r--r-- | scripts/genksyms/genksyms.c | 80 | ||||
-rw-r--r-- | scripts/genksyms/genksyms.h | 57 |
2 files changed, 43 insertions, 94 deletions
diff --git a/scripts/genksyms/genksyms.c b/scripts/genksyms/genksyms.c index b798e284e1fc..5b0344e20d61 100644 --- a/scripts/genksyms/genksyms.c +++ b/scripts/genksyms/genksyms.c | |||
@@ -37,14 +37,14 @@ | |||
37 | #define HASH_BUCKETS 4096 | 37 | #define HASH_BUCKETS 4096 |
38 | 38 | ||
39 | static struct symbol *symtab[HASH_BUCKETS]; | 39 | static struct symbol *symtab[HASH_BUCKETS]; |
40 | FILE *debugfile; | 40 | static FILE *debugfile; |
41 | 41 | ||
42 | int cur_line = 1; | 42 | int cur_line = 1; |
43 | char *cur_filename, *output_directory; | 43 | char *cur_filename; |
44 | 44 | ||
45 | int flag_debug, flag_dump_defs, flag_warnings; | 45 | static int flag_debug, flag_dump_defs, flag_warnings; |
46 | const char *arch = ""; | 46 | static const char *arch = ""; |
47 | const char *mod_prefix = ""; | 47 | static const char *mod_prefix = ""; |
48 | 48 | ||
49 | static int errors; | 49 | static int errors; |
50 | static int nsyms; | 50 | static int nsyms; |
@@ -55,6 +55,9 @@ static const char *const symbol_type_name[] = { | |||
55 | "normal", "typedef", "enum", "struct", "union" | 55 | "normal", "typedef", "enum", "struct", "union" |
56 | }; | 56 | }; |
57 | 57 | ||
58 | static int equal_list(struct string_list *a, struct string_list *b); | ||
59 | static void print_list(FILE * f, struct string_list *list); | ||
60 | |||
58 | /*----------------------------------------------------------------------*/ | 61 | /*----------------------------------------------------------------------*/ |
59 | 62 | ||
60 | static const unsigned int crctab32[] = { | 63 | static const unsigned int crctab32[] = { |
@@ -112,27 +115,26 @@ static const unsigned int crctab32[] = { | |||
112 | 0x2d02ef8dU | 115 | 0x2d02ef8dU |
113 | }; | 116 | }; |
114 | 117 | ||
115 | static inline unsigned long | 118 | static unsigned long partial_crc32_one(unsigned char c, unsigned long crc) |
116 | partial_crc32_one(unsigned char c, unsigned long crc) | ||
117 | { | 119 | { |
118 | return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8); | 120 | return crctab32[(crc ^ c) & 0xff] ^ (crc >> 8); |
119 | } | 121 | } |
120 | 122 | ||
121 | static inline unsigned long partial_crc32(const char *s, unsigned long crc) | 123 | static unsigned long partial_crc32(const char *s, unsigned long crc) |
122 | { | 124 | { |
123 | while (*s) | 125 | while (*s) |
124 | crc = partial_crc32_one(*s++, crc); | 126 | crc = partial_crc32_one(*s++, crc); |
125 | return crc; | 127 | return crc; |
126 | } | 128 | } |
127 | 129 | ||
128 | static inline unsigned long crc32(const char *s) | 130 | static unsigned long crc32(const char *s) |
129 | { | 131 | { |
130 | return partial_crc32(s, 0xffffffff) ^ 0xffffffff; | 132 | return partial_crc32(s, 0xffffffff) ^ 0xffffffff; |
131 | } | 133 | } |
132 | 134 | ||
133 | /*----------------------------------------------------------------------*/ | 135 | /*----------------------------------------------------------------------*/ |
134 | 136 | ||
135 | static inline enum symbol_type map_to_ns(enum symbol_type t) | 137 | static enum symbol_type map_to_ns(enum symbol_type t) |
136 | { | 138 | { |
137 | if (t == SYM_TYPEDEF) | 139 | if (t == SYM_TYPEDEF) |
138 | t = SYM_NORMAL; | 140 | t = SYM_NORMAL; |
@@ -147,8 +149,8 @@ struct symbol *find_symbol(const char *name, enum symbol_type ns) | |||
147 | struct symbol *sym; | 149 | struct symbol *sym; |
148 | 150 | ||
149 | for (sym = symtab[h]; sym; sym = sym->hash_next) | 151 | for (sym = symtab[h]; sym; sym = sym->hash_next) |
150 | if (map_to_ns(sym->type) == map_to_ns(ns) | 152 | if (map_to_ns(sym->type) == map_to_ns(ns) && |
151 | && strcmp(name, sym->name) == 0) | 153 | strcmp(name, sym->name) == 0) |
152 | break; | 154 | break; |
153 | 155 | ||
154 | return sym; | 156 | return sym; |
@@ -160,13 +162,14 @@ struct symbol *add_symbol(const char *name, enum symbol_type type, | |||
160 | unsigned long h = crc32(name) % HASH_BUCKETS; | 162 | unsigned long h = crc32(name) % HASH_BUCKETS; |
161 | struct symbol *sym; | 163 | struct symbol *sym; |
162 | 164 | ||
163 | for (sym = symtab[h]; sym; sym = sym->hash_next) | 165 | for (sym = symtab[h]; sym; sym = sym->hash_next) { |
164 | if (map_to_ns(sym->type) == map_to_ns(type) | 166 | if (map_to_ns(sym->type) == map_to_ns(type) |
165 | && strcmp(name, sym->name) == 0) { | 167 | && strcmp(name, sym->name) == 0) { |
166 | if (!equal_list(sym->defn, defn)) | 168 | if (!equal_list(sym->defn, defn)) |
167 | error_with_pos("redefinition of %s", name); | 169 | error_with_pos("redefinition of %s", name); |
168 | return sym; | 170 | return sym; |
169 | } | 171 | } |
172 | } | ||
170 | 173 | ||
171 | sym = xmalloc(sizeof(*sym)); | 174 | sym = xmalloc(sizeof(*sym)); |
172 | sym->name = name; | 175 | sym->name = name; |
@@ -193,7 +196,7 @@ struct symbol *add_symbol(const char *name, enum symbol_type type, | |||
193 | 196 | ||
194 | /*----------------------------------------------------------------------*/ | 197 | /*----------------------------------------------------------------------*/ |
195 | 198 | ||
196 | inline void free_node(struct string_list *node) | 199 | void free_node(struct string_list *node) |
197 | { | 200 | { |
198 | free(node->string); | 201 | free(node->string); |
199 | free(node); | 202 | free(node); |
@@ -208,7 +211,7 @@ void free_list(struct string_list *s, struct string_list *e) | |||
208 | } | 211 | } |
209 | } | 212 | } |
210 | 213 | ||
211 | inline struct string_list *copy_node(struct string_list *node) | 214 | struct string_list *copy_node(struct string_list *node) |
212 | { | 215 | { |
213 | struct string_list *newnode; | 216 | struct string_list *newnode; |
214 | 217 | ||
@@ -219,22 +222,7 @@ inline struct string_list *copy_node(struct string_list *node) | |||
219 | return newnode; | 222 | return newnode; |
220 | } | 223 | } |
221 | 224 | ||
222 | struct string_list *copy_list(struct string_list *s, struct string_list *e) | 225 | static int equal_list(struct string_list *a, struct string_list *b) |
223 | { | ||
224 | struct string_list *h, *p; | ||
225 | |||
226 | if (s == e) | ||
227 | return NULL; | ||
228 | |||
229 | p = h = copy_node(s); | ||
230 | while ((s = s->next) != e) | ||
231 | p = p->next = copy_node(s); | ||
232 | p->next = NULL; | ||
233 | |||
234 | return h; | ||
235 | } | ||
236 | |||
237 | int equal_list(struct string_list *a, struct string_list *b) | ||
238 | { | 226 | { |
239 | while (a && b) { | 227 | while (a && b) { |
240 | if (a->tag != b->tag || strcmp(a->string, b->string)) | 228 | if (a->tag != b->tag || strcmp(a->string, b->string)) |
@@ -246,7 +234,7 @@ int equal_list(struct string_list *a, struct string_list *b) | |||
246 | return !a && !b; | 234 | return !a && !b; |
247 | } | 235 | } |
248 | 236 | ||
249 | static inline void print_node(FILE * f, struct string_list *list) | 237 | static void print_node(FILE * f, struct string_list *list) |
250 | { | 238 | { |
251 | switch (list->tag) { | 239 | switch (list->tag) { |
252 | case SYM_STRUCT: | 240 | case SYM_STRUCT: |
@@ -270,7 +258,7 @@ static inline void print_node(FILE * f, struct string_list *list) | |||
270 | } | 258 | } |
271 | } | 259 | } |
272 | 260 | ||
273 | void print_list(FILE * f, struct string_list *list) | 261 | static void print_list(FILE * f, struct string_list *list) |
274 | { | 262 | { |
275 | struct string_list **e, **b; | 263 | struct string_list **e, **b; |
276 | struct string_list *tmp, **tmp2; | 264 | struct string_list *tmp, **tmp2; |
@@ -299,8 +287,8 @@ void print_list(FILE * f, struct string_list *list) | |||
299 | } | 287 | } |
300 | } | 288 | } |
301 | 289 | ||
302 | static unsigned long | 290 | static unsigned long expand_and_crc_list(struct string_list *list, |
303 | expand_and_crc_list(struct string_list *list, unsigned long crc) | 291 | unsigned long crc) |
304 | { | 292 | { |
305 | struct string_list **e, **b; | 293 | struct string_list **e, **b; |
306 | struct string_list *tmp, **tmp2; | 294 | struct string_list *tmp, **tmp2; |
@@ -386,9 +374,8 @@ expand_and_crc_list(struct string_list *list, unsigned long crc) | |||
386 | cur->string); | 374 | cur->string); |
387 | } | 375 | } |
388 | 376 | ||
389 | crc = | 377 | crc = partial_crc32(symbol_type_name[cur->tag], |
390 | partial_crc32(symbol_type_name[cur->tag], | 378 | crc); |
391 | crc); | ||
392 | crc = partial_crc32_one(' ', crc); | 379 | crc = partial_crc32_one(' ', crc); |
393 | crc = partial_crc32(cur->string, crc); | 380 | crc = partial_crc32(cur->string, crc); |
394 | crc = partial_crc32_one(' ', crc); | 381 | crc = partial_crc32_one(' ', crc); |
@@ -437,21 +424,6 @@ void export_symbol(const char *name) | |||
437 | } | 424 | } |
438 | 425 | ||
439 | /*----------------------------------------------------------------------*/ | 426 | /*----------------------------------------------------------------------*/ |
440 | |||
441 | void error(const char *fmt, ...) | ||
442 | { | ||
443 | va_list args; | ||
444 | |||
445 | if (flag_warnings) { | ||
446 | va_start(args, fmt); | ||
447 | vfprintf(stderr, fmt, args); | ||
448 | va_end(args); | ||
449 | putc('\n', stderr); | ||
450 | |||
451 | errors++; | ||
452 | } | ||
453 | } | ||
454 | |||
455 | void error_with_pos(const char *fmt, ...) | 427 | void error_with_pos(const char *fmt, ...) |
456 | { | 428 | { |
457 | va_list args; | 429 | va_list args; |
@@ -469,7 +441,7 @@ void error_with_pos(const char *fmt, ...) | |||
469 | } | 441 | } |
470 | } | 442 | } |
471 | 443 | ||
472 | void genksyms_usage(void) | 444 | static void genksyms_usage(void) |
473 | { | 445 | { |
474 | fputs("Usage:\n" "genksyms [-dDwqhV] > /path/to/.tmp_obj.ver\n" "\n" | 446 | fputs("Usage:\n" "genksyms [-dDwqhV] > /path/to/.tmp_obj.ver\n" "\n" |
475 | #ifdef __GNU_LIBRARY__ | 447 | #ifdef __GNU_LIBRARY__ |
diff --git a/scripts/genksyms/genksyms.h b/scripts/genksyms/genksyms.h index f09af47ab281..ab6f34f38735 100644 --- a/scripts/genksyms/genksyms.h +++ b/scripts/genksyms/genksyms.h | |||
@@ -20,74 +20,51 @@ | |||
20 | along with this program; if not, write to the Free Software Foundation, | 20 | along with this program; if not, write to the Free Software Foundation, |
21 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | 21 | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
22 | 22 | ||
23 | |||
24 | #ifndef MODUTILS_GENKSYMS_H | 23 | #ifndef MODUTILS_GENKSYMS_H |
25 | #define MODUTILS_GENKSYMS_H 1 | 24 | #define MODUTILS_GENKSYMS_H 1 |
26 | 25 | ||
27 | #include <stdio.h> | 26 | #include <stdio.h> |
28 | 27 | ||
29 | 28 | enum symbol_type { | |
30 | enum symbol_type | 29 | SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION |
31 | { | ||
32 | SYM_NORMAL, SYM_TYPEDEF, SYM_ENUM, SYM_STRUCT, SYM_UNION | ||
33 | }; | 30 | }; |
34 | 31 | ||
35 | struct string_list | 32 | struct string_list { |
36 | { | 33 | struct string_list *next; |
37 | struct string_list *next; | 34 | enum symbol_type tag; |
38 | enum symbol_type tag; | 35 | char *string; |
39 | char *string; | ||
40 | }; | 36 | }; |
41 | 37 | ||
42 | struct symbol | 38 | struct symbol { |
43 | { | 39 | struct symbol *hash_next; |
44 | struct symbol *hash_next; | 40 | const char *name; |
45 | const char *name; | 41 | enum symbol_type type; |
46 | enum symbol_type type; | 42 | struct string_list *defn; |
47 | struct string_list *defn; | 43 | struct symbol *expansion_trail; |
48 | struct symbol *expansion_trail; | 44 | int is_extern; |
49 | int is_extern; | ||
50 | }; | 45 | }; |
51 | 46 | ||
52 | typedef struct string_list **yystype; | 47 | typedef struct string_list **yystype; |
53 | #define YYSTYPE yystype | 48 | #define YYSTYPE yystype |
54 | 49 | ||
55 | extern FILE *outfile, *debugfile; | ||
56 | |||
57 | extern int cur_line; | 50 | extern int cur_line; |
58 | extern char *cur_filename, *output_directory; | 51 | extern char *cur_filename; |
59 | |||
60 | extern int flag_debug, flag_dump_defs, flag_warnings; | ||
61 | extern int checksum_version, kernel_version; | ||
62 | |||
63 | extern int want_brace_phrase, want_exp_phrase, discard_phrase_contents; | ||
64 | extern struct string_list *current_list, *next_list; | ||
65 | |||
66 | 52 | ||
67 | struct symbol *find_symbol(const char *name, enum symbol_type ns); | 53 | struct symbol *find_symbol(const char *name, enum symbol_type ns); |
68 | struct symbol *add_symbol(const char *name, enum symbol_type type, | 54 | struct symbol *add_symbol(const char *name, enum symbol_type type, |
69 | struct string_list *defn, int is_extern); | 55 | struct string_list *defn, int is_extern); |
70 | void export_symbol(const char *); | 56 | void export_symbol(const char *); |
71 | 57 | ||
72 | struct string_list *reset_list(void); | ||
73 | void free_list(struct string_list *s, struct string_list *e); | ||
74 | void free_node(struct string_list *list); | 58 | void free_node(struct string_list *list); |
59 | void free_list(struct string_list *s, struct string_list *e); | ||
75 | struct string_list *copy_node(struct string_list *); | 60 | struct string_list *copy_node(struct string_list *); |
76 | struct string_list *copy_list(struct string_list *s, struct string_list *e); | ||
77 | int equal_list(struct string_list *a, struct string_list *b); | ||
78 | void print_list(FILE *, struct string_list *list); | ||
79 | 61 | ||
80 | int yylex(void); | 62 | int yylex(void); |
81 | int yyparse(void); | 63 | int yyparse(void); |
82 | 64 | ||
83 | void error_with_pos(const char *, ...); | 65 | void error_with_pos(const char *, ...); |
84 | 66 | ||
85 | #define version(a,b,c) ((a << 16) | (b << 8) | (c)) | ||
86 | |||
87 | /*----------------------------------------------------------------------*/ | 67 | /*----------------------------------------------------------------------*/ |
88 | |||
89 | #define MODUTILS_VERSION "<in-kernel>" | ||
90 | |||
91 | #define xmalloc(size) ({ void *__ptr = malloc(size); \ | 68 | #define xmalloc(size) ({ void *__ptr = malloc(size); \ |
92 | if(!__ptr && size != 0) { \ | 69 | if(!__ptr && size != 0) { \ |
93 | fprintf(stderr, "out of memory\n"); \ | 70 | fprintf(stderr, "out of memory\n"); \ |
@@ -101,4 +78,4 @@ void error_with_pos(const char *, ...); | |||
101 | } \ | 78 | } \ |
102 | __str; }) | 79 | __str; }) |
103 | 80 | ||
104 | #endif /* genksyms.h */ | 81 | #endif /* genksyms.h */ |