fix some crashes in add_dominators()
[smatch.git] / lib.c
blobde6350439cc4b29fd07e4d8c87c06ca718b99adf
1 /*
2 * 'sparse' library helper routines.
4 * Copyright (C) 2003 Transmeta Corp.
5 * 2003-2004 Linus Torvalds
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 * THE SOFTWARE.
25 #include <ctype.h>
26 #include <fcntl.h>
27 #include <stdarg.h>
28 #include <stddef.h>
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <unistd.h>
33 #include <assert.h>
35 #include <sys/types.h>
37 #include "lib.h"
38 #include "allocate.h"
39 #include "token.h"
40 #include "parse.h"
41 #include "symbol.h"
42 #include "expression.h"
43 #include "scope.h"
44 #include "linearize.h"
45 #include "target.h"
46 #include "version.h"
48 int verbose, optimize, optimize_size, preprocessing;
49 int die_if_error = 0;
50 int has_error = 0;
52 #ifndef __GNUC__
53 # define __GNUC__ 2
54 # define __GNUC_MINOR__ 95
55 # define __GNUC_PATCHLEVEL__ 0
56 #endif
58 int gcc_major = __GNUC__;
59 int gcc_minor = __GNUC_MINOR__;
60 int gcc_patchlevel = __GNUC_PATCHLEVEL__;
62 static const char *gcc_base_dir = GCC_BASE;
63 static const char *multiarch_dir = MULTIARCH_TRIPLET;
65 struct token *skip_to(struct token *token, int op)
67 while (!match_op(token, op) && !eof_token(token))
68 token = token->next;
69 return token;
72 struct token *expect(struct token *token, int op, const char *where)
74 if (!match_op(token, op)) {
75 static struct token bad_token;
76 if (token != &bad_token) {
77 bad_token.next = token;
78 sparse_error(token->pos, "Expected %s %s", show_special(op), where);
79 sparse_error(token->pos, "got %s", show_token(token));
81 if (op == ';')
82 return skip_to(token, op);
83 return &bad_token;
85 return token->next;
88 unsigned int hexval(unsigned int c)
90 int retval = 256;
91 switch (c) {
92 case '0'...'9':
93 retval = c - '0';
94 break;
95 case 'a'...'f':
96 retval = c - 'a' + 10;
97 break;
98 case 'A'...'F':
99 retval = c - 'A' + 10;
100 break;
102 return retval;
105 static void do_warn(const char *type, struct position pos, const char * fmt, va_list args)
107 static char buffer[512];
108 const char *name;
110 vsprintf(buffer, fmt, args);
111 name = stream_name(pos.stream);
113 fprintf(stderr, "%s:%d:%d: %s%s\n",
114 name, pos.line, pos.pos, type, buffer);
117 static int max_warnings = 100;
118 static int show_info = 1;
120 void info(struct position pos, const char * fmt, ...)
122 va_list args;
124 if (!show_info)
125 return;
126 va_start(args, fmt);
127 do_warn("", pos, fmt, args);
128 va_end(args);
131 static void do_error(struct position pos, const char * fmt, va_list args)
133 static int errors = 0;
134 die_if_error = 1;
135 show_info = 1;
136 /* Shut up warnings after an error */
137 has_error |= ERROR_CURR_PHASE;
138 if (errors > 100) {
139 static int once = 0;
140 show_info = 0;
141 if (once)
142 return;
143 fmt = "too many errors";
144 once = 1;
147 do_warn("error: ", pos, fmt, args);
148 errors++;
151 void warning(struct position pos, const char * fmt, ...)
153 va_list args;
155 if (Wsparse_error) {
156 va_start(args, fmt);
157 do_error(pos, fmt, args);
158 va_end(args);
159 return;
162 if (!max_warnings || has_error) {
163 show_info = 0;
164 return;
167 if (!--max_warnings) {
168 show_info = 0;
169 fmt = "too many warnings";
172 va_start(args, fmt);
173 do_warn("warning: ", pos, fmt, args);
174 va_end(args);
177 void sparse_error(struct position pos, const char * fmt, ...)
179 va_list args;
180 va_start(args, fmt);
181 do_error(pos, fmt, args);
182 va_end(args);
185 void expression_error(struct expression *expr, const char *fmt, ...)
187 va_list args;
188 va_start(args, fmt);
189 do_error(expr->pos, fmt, args);
190 va_end(args);
191 expr->ctype = &bad_ctype;
194 void error_die(struct position pos, const char * fmt, ...)
196 va_list args;
197 va_start(args, fmt);
198 do_warn("error: ", pos, fmt, args);
199 va_end(args);
200 exit(1);
203 void die(const char *fmt, ...)
205 va_list args;
206 static char buffer[512];
208 va_start(args, fmt);
209 vsnprintf(buffer, sizeof(buffer), fmt, args);
210 va_end(args);
212 fprintf(stderr, "%s\n", buffer);
213 exit(1);
216 static struct token *pre_buffer_begin = NULL;
217 static struct token *pre_buffer_end = NULL;
219 int Waddress = 0;
220 int Waddress_space = 1;
221 int Wbitwise = 1;
222 int Wcast_to_as = 0;
223 int Wcast_truncate = 1;
224 int Wcontext = 1;
225 int Wdecl = 1;
226 int Wdeclarationafterstatement = -1;
227 int Wdefault_bitfield_sign = 0;
228 int Wdesignated_init = 1;
229 int Wdo_while = 0;
230 int Winit_cstring = 0;
231 int Wenum_mismatch = 1;
232 int Wsparse_error = 0;
233 int Wmemcpy_max_count = 1;
234 int Wnon_pointer_null = 1;
235 int Wold_initializer = 1;
236 int Wone_bit_signed_bitfield = 1;
237 int Woverride_init = 1;
238 int Woverride_init_all = 0;
239 int Woverride_init_whole_range = 0;
240 int Wparen_string = 0;
241 int Wptr_subtraction_blows = 0;
242 int Wreturn_void = 0;
243 int Wshadow = 0;
244 int Wsizeof_bool = 0;
245 int Wtautological_compare = 0;
246 int Wtransparent_union = 0;
247 int Wtypesign = 0;
248 int Wundef = 0;
249 int Wuninitialized = 1;
250 int Wunknown_attribute = 1;
251 int Wvla = 1;
253 int dump_macro_defs = 0;
255 int dbg_entry = 0;
256 int dbg_dead = 0;
258 int fmem_report = 0;
259 int fdump_linearize;
260 unsigned long long fmemcpy_max_count = 100000;
262 int preprocess_only;
264 static enum { STANDARD_C89,
265 STANDARD_C94,
266 STANDARD_C99,
267 STANDARD_C11,
268 STANDARD_GNU11,
269 STANDARD_GNU89,
270 STANDARD_GNU99, } standard = STANDARD_GNU89;
272 #define ARCH_LP32 0
273 #define ARCH_LP64 1
274 #define ARCH_LLP64 2
276 #ifdef __x86_64__
277 #define ARCH_M64_DEFAULT ARCH_LP64
278 #else
279 #define ARCH_M64_DEFAULT ARCH_LP32
280 #endif
282 int arch_m64 = ARCH_M64_DEFAULT;
283 int arch_msize_long = 0;
285 #ifdef __BIG_ENDIAN__
286 #define ARCH_BIG_ENDIAN 1
287 #else
288 #define ARCH_BIG_ENDIAN 0
289 #endif
290 int arch_big_endian = ARCH_BIG_ENDIAN;
293 #define CMDLINE_INCLUDE 20
294 static int cmdline_include_nr = 0;
295 static char *cmdline_include[CMDLINE_INCLUDE];
298 void add_pre_buffer(const char *fmt, ...)
300 va_list args;
301 unsigned int size;
302 struct token *begin, *end;
303 char buffer[4096];
305 va_start(args, fmt);
306 size = vsnprintf(buffer, sizeof(buffer), fmt, args);
307 va_end(args);
308 begin = tokenize_buffer(buffer, size, &end);
309 if (!pre_buffer_begin)
310 pre_buffer_begin = begin;
311 if (pre_buffer_end)
312 pre_buffer_end->next = begin;
313 pre_buffer_end = end;
316 static char **handle_switch_D(char *arg, char **next)
318 const char *name = arg + 1;
319 const char *value = "1";
321 if (!*name || isspace((unsigned char)*name))
322 die("argument to `-D' is missing");
324 for (;;) {
325 char c;
326 c = *++arg;
327 if (!c)
328 break;
329 if (isspace((unsigned char)c) || c == '=') {
330 *arg = '\0';
331 value = arg + 1;
332 break;
335 add_pre_buffer("#define %s %s\n", name, value);
336 return next;
339 static char **handle_switch_E(char *arg, char **next)
341 if (arg[1] == '\0')
342 preprocess_only = 1;
343 return next;
346 static char **handle_switch_I(char *arg, char **next)
348 char *path = arg+1;
350 switch (arg[1]) {
351 case '-':
352 add_pre_buffer("#split_include\n");
353 break;
355 case '\0': /* Plain "-I" */
356 path = *++next;
357 if (!path)
358 die("missing argument for -I option");
359 /* Fall through */
360 default:
361 add_pre_buffer("#add_include \"%s/\"\n", path);
363 return next;
366 static void add_cmdline_include(char *filename)
368 if (cmdline_include_nr >= CMDLINE_INCLUDE)
369 die("too many include files for %s\n", filename);
370 cmdline_include[cmdline_include_nr++] = filename;
373 static char **handle_switch_i(char *arg, char **next)
375 if (*next && !strcmp(arg, "include"))
376 add_cmdline_include(*++next);
377 else if (*next && !strcmp(arg, "imacros"))
378 add_cmdline_include(*++next);
379 else if (*next && !strcmp(arg, "isystem")) {
380 char *path = *++next;
381 if (!path)
382 die("missing argument for -isystem option");
383 add_pre_buffer("#add_isystem \"%s/\"\n", path);
384 } else if (*next && !strcmp(arg, "idirafter")) {
385 char *path = *++next;
386 if (!path)
387 die("missing argument for -idirafter option");
388 add_pre_buffer("#add_dirafter \"%s/\"\n", path);
390 return next;
393 static char **handle_switch_M(char *arg, char **next)
395 if (!strcmp(arg, "MF") || !strcmp(arg,"MQ") || !strcmp(arg,"MT")) {
396 if (!*next)
397 die("missing argument for -%s option", arg);
398 return next + 1;
400 return next;
403 static char **handle_multiarch_dir(char *arg, char **next)
405 multiarch_dir = *++next;
406 if (!multiarch_dir)
407 die("missing argument for -multiarch-dir option");
408 return next;
411 static char **handle_switch_m(char *arg, char **next)
413 if (!strcmp(arg, "m64")) {
414 arch_m64 = ARCH_LP64;
415 } else if (!strcmp(arg, "m32")) {
416 arch_m64 = ARCH_LP32;
417 } else if (!strcmp(arg, "msize-llp64")) {
418 arch_m64 = ARCH_LLP64;
419 } else if (!strcmp(arg, "msize-long")) {
420 arch_msize_long = 1;
421 } else if (!strcmp(arg, "multiarch-dir")) {
422 return handle_multiarch_dir(arg, next);
423 } else if (!strcmp(arg, "mbig-endian")) {
424 arch_big_endian = 1;
425 } else if (!strcmp(arg, "mlittle-endian")) {
426 arch_big_endian = 0;
428 return next;
431 static void handle_arch_m64_finalize(void)
433 switch (arch_m64) {
434 case ARCH_LP32:
435 /* default values */
436 return;
437 case ARCH_LP64:
438 bits_in_long = 64;
439 max_int_alignment = 8;
440 size_t_ctype = &ulong_ctype;
441 ssize_t_ctype = &long_ctype;
442 add_pre_buffer("#weak_define __LP64__ 1\n");
443 add_pre_buffer("#weak_define _LP64 1\n");
444 goto case_64bit_common;
445 case ARCH_LLP64:
446 bits_in_long = 32;
447 max_int_alignment = 4;
448 size_t_ctype = &ullong_ctype;
449 ssize_t_ctype = &llong_ctype;
450 add_pre_buffer("#weak_define __LLP64__ 1\n");
451 goto case_64bit_common;
452 case_64bit_common:
453 bits_in_pointer = 64;
454 pointer_alignment = 8;
455 #ifdef __x86_64__
456 add_pre_buffer("#weak_define __x86_64__ 1\n");
457 #endif
458 break;
462 static void handle_arch_msize_long_finalize(void)
464 if (arch_msize_long) {
465 size_t_ctype = &ulong_ctype;
466 ssize_t_ctype = &long_ctype;
470 static void handle_arch_finalize(void)
472 handle_arch_m64_finalize();
473 handle_arch_msize_long_finalize();
477 static int handle_simple_switch(const char *arg, const char *name, int *flag)
479 int val = 1;
481 // Prefixe "no-" mean to turn flag off.
482 if (strncmp(arg, "no-", 3) == 0) {
483 arg += 3;
484 val = 0;
487 if (strcmp(arg, name) == 0) {
488 *flag = val;
489 return 1;
492 // not handled
493 return 0;
496 static char **handle_switch_o(char *arg, char **next)
498 if (!strcmp (arg, "o")) { // "-o foo"
499 if (!*++next)
500 die("argument to '-o' is missing");
502 // else "-ofoo"
504 return next;
507 static const struct warning {
508 const char *name;
509 int *flag;
510 } warnings[] = {
511 { "address", &Waddress },
512 { "address-space", &Waddress_space },
513 { "bitwise", &Wbitwise },
514 { "cast-to-as", &Wcast_to_as },
515 { "cast-truncate", &Wcast_truncate },
516 { "context", &Wcontext },
517 { "decl", &Wdecl },
518 { "declaration-after-statement", &Wdeclarationafterstatement },
519 { "default-bitfield-sign", &Wdefault_bitfield_sign },
520 { "designated-init", &Wdesignated_init },
521 { "do-while", &Wdo_while },
522 { "enum-mismatch", &Wenum_mismatch },
523 { "init-cstring", &Winit_cstring },
524 { "memcpy-max-count", &Wmemcpy_max_count },
525 { "non-pointer-null", &Wnon_pointer_null },
526 { "old-initializer", &Wold_initializer },
527 { "one-bit-signed-bitfield", &Wone_bit_signed_bitfield },
528 { "override-init", &Woverride_init },
529 { "override-init-all", &Woverride_init_all },
530 { "paren-string", &Wparen_string },
531 { "ptr-subtraction-blows", &Wptr_subtraction_blows },
532 { "return-void", &Wreturn_void },
533 { "shadow", &Wshadow },
534 { "sizeof-bool", &Wsizeof_bool },
535 { "sparse-error", &Wsparse_error },
536 { "tautological-compare", &Wtautological_compare },
537 { "transparent-union", &Wtransparent_union },
538 { "typesign", &Wtypesign },
539 { "undef", &Wundef },
540 { "uninitialized", &Wuninitialized },
541 { "unknown-attribute", &Wunknown_attribute },
542 { "vla", &Wvla },
545 enum {
546 WARNING_OFF,
547 WARNING_ON,
548 WARNING_FORCE_OFF
552 static char **handle_onoff_switch(char *arg, char **next, const struct warning warnings[], int n)
554 int flag = WARNING_ON;
555 char *p = arg + 1;
556 unsigned i;
558 if (!strcmp(p, "sparse-all")) {
559 for (i = 0; i < n; i++) {
560 if (*warnings[i].flag != WARNING_FORCE_OFF && warnings[i].flag != &Wsparse_error)
561 *warnings[i].flag = WARNING_ON;
565 // Prefixes "no" and "no-" mean to turn warning off.
566 if (p[0] == 'n' && p[1] == 'o') {
567 p += 2;
568 if (p[0] == '-')
569 p++;
570 flag = WARNING_FORCE_OFF;
573 for (i = 0; i < n; i++) {
574 if (!strcmp(p,warnings[i].name)) {
575 *warnings[i].flag = flag;
576 return next;
580 // Unknown.
581 return NULL;
584 static char **handle_switch_W(char *arg, char **next)
586 char ** ret = handle_onoff_switch(arg, next, warnings, ARRAY_SIZE(warnings));
587 if (ret)
588 return ret;
590 // Unknown.
591 return next;
594 static struct warning debugs[] = {
595 { "entry", &dbg_entry},
596 { "dead", &dbg_dead},
600 static char **handle_switch_v(char *arg, char **next)
602 char ** ret = handle_onoff_switch(arg, next, debugs, ARRAY_SIZE(debugs));
603 if (ret)
604 return ret;
606 // Unknown.
607 do {
608 verbose++;
609 } while (*++arg == 'v');
610 return next;
613 static struct warning dumps[] = {
614 { "D", &dump_macro_defs},
617 static char **handle_switch_d(char *arg, char **next)
619 char ** ret = handle_onoff_switch(arg, next, dumps, ARRAY_SIZE(dumps));
620 if (ret)
621 return ret;
623 return next;
627 static void handle_onoff_switch_finalize(const struct warning warnings[], int n)
629 unsigned i;
631 for (i = 0; i < n; i++) {
632 if (*warnings[i].flag == WARNING_FORCE_OFF)
633 *warnings[i].flag = WARNING_OFF;
637 static void handle_switch_W_finalize(void)
639 handle_onoff_switch_finalize(warnings, ARRAY_SIZE(warnings));
641 /* default Wdeclarationafterstatement based on the C dialect */
642 if (-1 == Wdeclarationafterstatement)
644 switch (standard)
646 case STANDARD_C89:
647 case STANDARD_C94:
648 Wdeclarationafterstatement = 1;
649 break;
651 case STANDARD_C99:
652 case STANDARD_GNU89:
653 case STANDARD_GNU99:
654 case STANDARD_C11:
655 case STANDARD_GNU11:
656 Wdeclarationafterstatement = 0;
657 break;
659 default:
660 assert (0);
666 static void handle_switch_v_finalize(void)
668 handle_onoff_switch_finalize(debugs, ARRAY_SIZE(debugs));
671 static char **handle_switch_U(char *arg, char **next)
673 const char *name = arg + 1;
674 add_pre_buffer ("#undef %s\n", name);
675 return next;
678 static char **handle_switch_O(char *arg, char **next)
680 int level = 1;
681 if (arg[1] >= '0' && arg[1] <= '9')
682 level = arg[1] - '0';
683 optimize = level;
684 optimize_size = arg[1] == 's';
685 return next;
688 static char **handle_switch_fmemcpy_max_count(char *arg, char **next)
690 unsigned long long val;
691 char *end;
693 val = strtoull(arg, &end, 0);
694 if (*end != '\0' || end == arg)
695 die("error: missing argument to \"-fmemcpy-max-count=\"");
697 if (val == 0)
698 val = ~0ULL;
699 fmemcpy_max_count = val;
700 return next;
703 static char **handle_switch_ftabstop(char *arg, char **next)
705 char *end;
706 unsigned long val;
708 if (*arg == '\0')
709 die("error: missing argument to \"-ftabstop=\"");
711 /* we silently ignore silly values */
712 val = strtoul(arg, &end, 10);
713 if (*end == '\0' && 1 <= val && val <= 100)
714 tabstop = val;
716 return next;
719 static char **handle_switch_fdump(char *arg, char **next)
721 if (!strncmp(arg, "linearize", 9)) {
722 arg += 9;
723 if (*arg == '\0')
724 fdump_linearize = 1;
725 else if (!strcmp(arg, "=only"))
726 fdump_linearize = 2;
727 else
728 goto err;
731 /* ignore others flags */
732 return next;
734 err:
735 die("error: unknown flag \"-fdump-%s\"", arg);
738 static char **handle_switch_f(char *arg, char **next)
740 arg++;
742 if (!strncmp(arg, "tabstop=", 8))
743 return handle_switch_ftabstop(arg+8, next);
744 if (!strncmp(arg, "dump-", 5))
745 return handle_switch_fdump(arg+5, next);
746 if (!strncmp(arg, "memcpy-max-count=", 17))
747 return handle_switch_fmemcpy_max_count(arg+17, next);
749 /* handle switches w/ arguments above, boolean and only boolean below */
750 if (handle_simple_switch(arg, "mem-report", &fmem_report))
751 return next;
753 return next;
756 static char **handle_switch_G(char *arg, char **next)
758 if (!strcmp (arg, "G") && *next)
759 return next + 1; // "-G 0"
760 else
761 return next; // "-G0" or (bogus) terminal "-G"
764 static char **handle_switch_a(char *arg, char **next)
766 if (!strcmp (arg, "ansi"))
767 standard = STANDARD_C89;
769 return next;
772 static char **handle_switch_s(char *arg, char **next)
774 if (!strncmp (arg, "std=", 4))
776 arg += 4;
778 if (!strcmp (arg, "c89") ||
779 !strcmp (arg, "iso9899:1990"))
780 standard = STANDARD_C89;
782 else if (!strcmp (arg, "iso9899:199409"))
783 standard = STANDARD_C94;
785 else if (!strcmp (arg, "c99") ||
786 !strcmp (arg, "c9x") ||
787 !strcmp (arg, "iso9899:1999") ||
788 !strcmp (arg, "iso9899:199x"))
789 standard = STANDARD_C99;
791 else if (!strcmp (arg, "gnu89"))
792 standard = STANDARD_GNU89;
794 else if (!strcmp (arg, "gnu99") || !strcmp (arg, "gnu9x"))
795 standard = STANDARD_GNU99;
797 else if (!strcmp(arg, "c11") ||
798 !strcmp(arg, "c1x") ||
799 !strcmp(arg, "iso9899:2011"))
800 standard = STANDARD_C11;
802 else if (!strcmp(arg, "gnu11"))
803 standard = STANDARD_GNU11;
805 else
806 die ("Unsupported C dialect");
809 return next;
812 static char **handle_nostdinc(char *arg, char **next)
814 add_pre_buffer("#nostdinc\n");
815 return next;
818 static char **handle_switch_n(char *arg, char **next)
820 if (!strcmp (arg, "nostdinc"))
821 return handle_nostdinc(arg, next);
823 return next;
826 static char **handle_base_dir(char *arg, char **next)
828 gcc_base_dir = *++next;
829 if (!gcc_base_dir)
830 die("missing argument for -gcc-base-dir option");
831 return next;
834 static char **handle_switch_g(char *arg, char **next)
836 if (!strcmp (arg, "gcc-base-dir"))
837 return handle_base_dir(arg, next);
839 return next;
843 static char **handle_version(char *arg, char **next)
845 printf("%s\n", SPARSE_VERSION);
846 exit(0);
849 static char **handle_param(char *arg, char **next)
851 char *value = NULL;
853 /* For now just skip any '--param=*' or '--param *' */
854 if (*arg == '\0') {
855 value = *++next;
856 } else if (isspace((unsigned char)*arg) || *arg == '=') {
857 value = ++arg;
860 if (!value)
861 die("missing argument for --param option");
863 return next;
866 struct switches {
867 const char *name;
868 char **(*fn)(char *, char **);
869 unsigned int prefix:1;
872 static char **handle_long_options(char *arg, char **next)
874 static struct switches cmd[] = {
875 { "param", handle_param, 1 },
876 { "version", handle_version },
877 { NULL, NULL }
879 struct switches *s = cmd;
881 while (s->name) {
882 int optlen = strlen(s->name);
883 if (!strncmp(s->name, arg, optlen + !s->prefix))
884 return s->fn(arg + optlen, next);
885 s++;
887 return next;
890 static char **handle_switch(char *arg, char **next)
892 switch (*arg) {
893 case 'a': return handle_switch_a(arg, next);
894 case 'D': return handle_switch_D(arg, next);
895 case 'd': return handle_switch_d(arg, next);
896 case 'E': return handle_switch_E(arg, next);
897 case 'f': return handle_switch_f(arg, next);
898 case 'g': return handle_switch_g(arg, next);
899 case 'G': return handle_switch_G(arg, next);
900 case 'I': return handle_switch_I(arg, next);
901 case 'i': return handle_switch_i(arg, next);
902 case 'M': return handle_switch_M(arg, next);
903 case 'm': return handle_switch_m(arg, next);
904 case 'n': return handle_switch_n(arg, next);
905 case 'o': return handle_switch_o(arg, next);
906 case 'O': return handle_switch_O(arg, next);
907 case 's': return handle_switch_s(arg, next);
908 case 'U': return handle_switch_U(arg, next);
909 case 'v': return handle_switch_v(arg, next);
910 case 'W': return handle_switch_W(arg, next);
911 case '-': return handle_long_options(arg + 1, next);
912 default:
913 break;
917 * Ignore unknown command line options:
918 * they're probably gcc switches
920 return next;
923 static void predefined_sizeof(const char *name, unsigned bits)
925 add_pre_buffer("#weak_define __SIZEOF_%s__ %d\n", name, bits/8);
928 static void predefined_max(const char *name, const char *suffix, unsigned bits)
930 unsigned long long max = (1ULL << (bits - 1 )) - 1;
932 add_pre_buffer("#weak_define __%s_MAX__ %#llx%s\n", name, max, suffix);
935 static void predefined_type_size(const char *name, const char *suffix, unsigned bits)
937 predefined_max(name, suffix, bits);
938 predefined_sizeof(name, bits);
941 static void predefined_macros(void)
943 add_pre_buffer("#define __CHECKER__ 1\n");
945 predefined_sizeof("SHORT", bits_in_short);
946 predefined_max("SHRT", "", bits_in_short);
947 predefined_max("SCHAR", "", bits_in_char);
948 predefined_max("WCHAR", "", bits_in_wchar);
949 add_pre_buffer("#weak_define __CHAR_BIT__ %d\n", bits_in_char);
951 predefined_type_size("INT", "", bits_in_int);
952 predefined_type_size("LONG", "L", bits_in_long);
953 predefined_type_size("LONG_LONG", "LL", bits_in_longlong);
955 predefined_sizeof("INT128", 128);
957 predefined_sizeof("SIZE_T", bits_in_pointer);
958 predefined_sizeof("PTRDIFF_T", bits_in_pointer);
959 predefined_sizeof("POINTER", bits_in_pointer);
961 predefined_sizeof("FLOAT", bits_in_float);
962 predefined_sizeof("DOUBLE", bits_in_double);
963 predefined_sizeof("LONG_DOUBLE", bits_in_longdouble);
965 add_pre_buffer("#weak_define __%s_ENDIAN__ 1\n",
966 arch_big_endian ? "BIG" : "LITTLE");
968 add_pre_buffer("#weak_define __ORDER_LITTLE_ENDIAN__ 1234\n");
969 add_pre_buffer("#weak_define __ORDER_BIG_ENDIAN__ 4321\n");
970 add_pre_buffer("#weak_define __ORDER_PDP_ENDIAN__ 3412\n");
971 add_pre_buffer("#weak_define __BYTE_ORDER__ __ORDER_%s_ENDIAN__\n",
972 arch_big_endian ? "BIG" : "LITTLE");
975 void declare_builtin_functions(void)
977 /* Gaah. gcc knows tons of builtin <string.h> functions */
978 add_pre_buffer("extern void *__builtin_memchr(const void *, int, __SIZE_TYPE__);\n");
979 add_pre_buffer("extern void *__builtin_memcpy(void *, const void *, __SIZE_TYPE__);\n");
980 add_pre_buffer("extern void *__builtin_mempcpy(void *, const void *, __SIZE_TYPE__);\n");
981 add_pre_buffer("extern void *__builtin_memmove(void *, const void *, __SIZE_TYPE__);\n");
982 add_pre_buffer("extern void *__builtin_memset(void *, int, __SIZE_TYPE__);\n");
983 add_pre_buffer("extern int __builtin_memcmp(const void *, const void *, __SIZE_TYPE__);\n");
984 add_pre_buffer("extern char *__builtin_strcat(char *, const char *);\n");
985 add_pre_buffer("extern char *__builtin_strncat(char *, const char *, __SIZE_TYPE__);\n");
986 add_pre_buffer("extern int __builtin_strcmp(const char *, const char *);\n");
987 add_pre_buffer("extern int __builtin_strncmp(const char *, const char *, __SIZE_TYPE__);\n");
988 add_pre_buffer("extern int __builtin_strcasecmp(const char *, const char *);\n");
989 add_pre_buffer("extern int __builtin_strncasecmp(const char *, const char *, __SIZE_TYPE__);\n");
990 add_pre_buffer("extern char *__builtin_strchr(const char *, int);\n");
991 add_pre_buffer("extern char *__builtin_strrchr(const char *, int);\n");
992 add_pre_buffer("extern char *__builtin_strcpy(char *, const char *);\n");
993 add_pre_buffer("extern char *__builtin_strncpy(char *, const char *, __SIZE_TYPE__);\n");
994 add_pre_buffer("extern char *__builtin_strdup(const char *);\n");
995 add_pre_buffer("extern char *__builtin_strndup(const char *, __SIZE_TYPE__);\n");
996 add_pre_buffer("extern __SIZE_TYPE__ __builtin_strspn(const char *, const char *);\n");
997 add_pre_buffer("extern __SIZE_TYPE__ __builtin_strcspn(const char *, const char *);\n");
998 add_pre_buffer("extern char * __builtin_strpbrk(const char *, const char *);\n");
999 add_pre_buffer("extern char* __builtin_stpcpy(const char *, const char*);\n");
1000 add_pre_buffer("extern char* __builtin_stpncpy(const char *, const char*, __SIZE_TYPE__);\n");
1001 add_pre_buffer("extern __SIZE_TYPE__ __builtin_strlen(const char *);\n");
1002 add_pre_buffer("extern char *__builtin_strstr(const char *, const char *);\n");
1003 add_pre_buffer("extern char *__builtin_strcasestr(const char *, const char *);\n");
1004 add_pre_buffer("extern char *__builtin_strnstr(const char *, const char *, __SIZE_TYPE__);\n");
1006 /* And even some from <strings.h> */
1007 add_pre_buffer("extern int __builtin_bcmp(const void *, const void *, __SIZE_TYPE__);\n");
1008 add_pre_buffer("extern void __builtin_bcopy(const void *, void *, __SIZE_TYPE__);\n");
1009 add_pre_buffer("extern void __builtin_bzero(void *, __SIZE_TYPE__);\n");
1010 add_pre_buffer("extern char*__builtin_index(const char *, int);\n");
1011 add_pre_buffer("extern char*__builtin_rindex(const char *, int);\n");
1013 /* And bitwise operations.. */
1014 add_pre_buffer("extern int __builtin_clrsb(int);\n");
1015 add_pre_buffer("extern int __builtin_clrsbl(long);\n");
1016 add_pre_buffer("extern int __builtin_clrsbll(long long);\n");
1017 add_pre_buffer("extern int __builtin_clz(int);\n");
1018 add_pre_buffer("extern int __builtin_clzl(long);\n");
1019 add_pre_buffer("extern int __builtin_clzll(long long);\n");
1020 add_pre_buffer("extern int __builtin_ctz(int);\n");
1021 add_pre_buffer("extern int __builtin_ctzl(long);\n");
1022 add_pre_buffer("extern int __builtin_ctzll(long long);\n");
1023 add_pre_buffer("extern int __builtin_ffs(int);\n");
1024 add_pre_buffer("extern int __builtin_ffsl(long);\n");
1025 add_pre_buffer("extern int __builtin_ffsll(long long);\n");
1026 add_pre_buffer("extern int __builtin_parity(unsigned int);\n");
1027 add_pre_buffer("extern int __builtin_parityl(unsigned long);\n");
1028 add_pre_buffer("extern int __builtin_parityll(unsigned long long);\n");
1029 add_pre_buffer("extern int __builtin_popcount(unsigned int);\n");
1030 add_pre_buffer("extern int __builtin_popcountl(unsigned long);\n");
1031 add_pre_buffer("extern int __builtin_popcountll(unsigned long long);\n");
1033 /* And byte swaps.. */
1034 add_pre_buffer("extern unsigned short __builtin_bswap16(unsigned short);\n");
1035 add_pre_buffer("extern unsigned int __builtin_bswap32(unsigned int);\n");
1036 add_pre_buffer("extern unsigned long long __builtin_bswap64(unsigned long long);\n");
1038 /* And atomic memory access functions.. */
1039 add_pre_buffer("extern int __sync_fetch_and_add(void *, ...);\n");
1040 add_pre_buffer("extern int __sync_fetch_and_sub(void *, ...);\n");
1041 add_pre_buffer("extern int __sync_fetch_and_or(void *, ...);\n");
1042 add_pre_buffer("extern int __sync_fetch_and_and(void *, ...);\n");
1043 add_pre_buffer("extern int __sync_fetch_and_xor(void *, ...);\n");
1044 add_pre_buffer("extern int __sync_fetch_and_nand(void *, ...);\n");
1045 add_pre_buffer("extern int __sync_add_and_fetch(void *, ...);\n");
1046 add_pre_buffer("extern int __sync_sub_and_fetch(void *, ...);\n");
1047 add_pre_buffer("extern int __sync_or_and_fetch(void *, ...);\n");
1048 add_pre_buffer("extern int __sync_and_and_fetch(void *, ...);\n");
1049 add_pre_buffer("extern int __sync_xor_and_fetch(void *, ...);\n");
1050 add_pre_buffer("extern int __sync_nand_and_fetch(void *, ...);\n");
1051 add_pre_buffer("extern int __sync_bool_compare_and_swap(void *, ...);\n");
1052 add_pre_buffer("extern int __sync_val_compare_and_swap(void *, ...);\n");
1053 add_pre_buffer("extern void __sync_synchronize();\n");
1054 add_pre_buffer("extern int __sync_lock_test_and_set(void *, ...);\n");
1055 add_pre_buffer("extern void __sync_lock_release(void *, ...);\n");
1057 /* And some random ones.. */
1058 add_pre_buffer("extern void *__builtin_return_address(unsigned int);\n");
1059 add_pre_buffer("extern void *__builtin_extract_return_addr(void *);\n");
1060 add_pre_buffer("extern void *__builtin_frame_address(unsigned int);\n");
1061 add_pre_buffer("extern void __builtin_trap(void);\n");
1062 add_pre_buffer("extern void *__builtin_alloca(__SIZE_TYPE__);\n");
1063 add_pre_buffer("extern void __builtin_prefetch (const void *, ...);\n");
1064 add_pre_buffer("extern long __builtin_alpha_extbl(long, long);\n");
1065 add_pre_buffer("extern long __builtin_alpha_extwl(long, long);\n");
1066 add_pre_buffer("extern long __builtin_alpha_insbl(long, long);\n");
1067 add_pre_buffer("extern long __builtin_alpha_inswl(long, long);\n");
1068 add_pre_buffer("extern long __builtin_alpha_insql(long, long);\n");
1069 add_pre_buffer("extern long __builtin_alpha_inslh(long, long);\n");
1070 add_pre_buffer("extern long __builtin_alpha_cmpbge(long, long);\n");
1071 add_pre_buffer("extern int __builtin_abs(int);\n");
1072 add_pre_buffer("extern long __builtin_labs(long);\n");
1073 add_pre_buffer("extern long long __builtin_llabs(long long);\n");
1074 add_pre_buffer("extern double __builtin_fabs(double);\n");
1075 add_pre_buffer("extern __SIZE_TYPE__ __builtin_va_arg_pack_len(void);\n");
1077 /* Add Blackfin-specific stuff */
1078 add_pre_buffer(
1079 "#ifdef __bfin__\n"
1080 "extern void __builtin_bfin_csync(void);\n"
1081 "extern void __builtin_bfin_ssync(void);\n"
1082 "extern int __builtin_bfin_norm_fr1x32(int);\n"
1083 "#endif\n"
1086 /* And some floating point stuff.. */
1087 add_pre_buffer("extern int __builtin_isgreater(float, float);\n");
1088 add_pre_buffer("extern int __builtin_isgreaterequal(float, float);\n");
1089 add_pre_buffer("extern int __builtin_isless(float, float);\n");
1090 add_pre_buffer("extern int __builtin_islessequal(float, float);\n");
1091 add_pre_buffer("extern int __builtin_islessgreater(float, float);\n");
1092 add_pre_buffer("extern int __builtin_isunordered(float, float);\n");
1094 /* And some INFINITY / NAN stuff.. */
1095 add_pre_buffer("extern double __builtin_huge_val(void);\n");
1096 add_pre_buffer("extern float __builtin_huge_valf(void);\n");
1097 add_pre_buffer("extern long double __builtin_huge_vall(void);\n");
1098 add_pre_buffer("extern double __builtin_inf(void);\n");
1099 add_pre_buffer("extern float __builtin_inff(void);\n");
1100 add_pre_buffer("extern long double __builtin_infl(void);\n");
1101 add_pre_buffer("extern double __builtin_nan(const char *);\n");
1102 add_pre_buffer("extern float __builtin_nanf(const char *);\n");
1103 add_pre_buffer("extern long double __builtin_nanl(const char *);\n");
1105 /* And some __FORTIFY_SOURCE ones.. */
1106 add_pre_buffer ("extern __SIZE_TYPE__ __builtin_object_size(const void *, int);\n");
1107 add_pre_buffer ("extern void * __builtin___memcpy_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n");
1108 add_pre_buffer ("extern void * __builtin___memmove_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n");
1109 add_pre_buffer ("extern void * __builtin___mempcpy_chk(void *, const void *, __SIZE_TYPE__, __SIZE_TYPE__);\n");
1110 add_pre_buffer ("extern void * __builtin___memset_chk(void *, int, __SIZE_TYPE__, __SIZE_TYPE__);\n");
1111 add_pre_buffer ("extern int __builtin___sprintf_chk(char *, int, __SIZE_TYPE__, const char *, ...);\n");
1112 add_pre_buffer ("extern int __builtin___snprintf_chk(char *, __SIZE_TYPE__, int , __SIZE_TYPE__, const char *, ...);\n");
1113 add_pre_buffer ("extern char * __builtin___stpcpy_chk(char *, const char *, __SIZE_TYPE__);\n");
1114 add_pre_buffer ("extern char * __builtin___strcat_chk(char *, const char *, __SIZE_TYPE__);\n");
1115 add_pre_buffer ("extern char * __builtin___strcpy_chk(char *, const char *, __SIZE_TYPE__);\n");
1116 add_pre_buffer ("extern char * __builtin___strncat_chk(char *, const char *, __SIZE_TYPE__, __SIZE_TYPE__);\n");
1117 add_pre_buffer ("extern char * __builtin___strncpy_chk(char *, const char *, __SIZE_TYPE__, __SIZE_TYPE__);\n");
1118 add_pre_buffer ("extern int __builtin___vsprintf_chk(char *, int, __SIZE_TYPE__, const char *, __builtin_va_list);\n");
1119 add_pre_buffer ("extern int __builtin___vsnprintf_chk(char *, __SIZE_TYPE__, int, __SIZE_TYPE__, const char *, __builtin_va_list ap);\n");
1120 add_pre_buffer ("extern void __builtin_unreachable(void);\n");
1122 /* And some from <stdlib.h> */
1123 add_pre_buffer("extern void __builtin_abort(void);\n");
1124 add_pre_buffer("extern void *__builtin_calloc(__SIZE_TYPE__, __SIZE_TYPE__);\n");
1125 add_pre_buffer("extern void __builtin_exit(int);\n");
1126 add_pre_buffer("extern void *__builtin_malloc(__SIZE_TYPE__);\n");
1127 add_pre_buffer("extern void *__builtin_realloc(void *, __SIZE_TYPE__);\n");
1128 add_pre_buffer("extern void __builtin_free(void *);\n");
1130 /* And some from <stdio.h> */
1131 add_pre_buffer("extern int __builtin_printf(const char *, ...);\n");
1132 add_pre_buffer("extern int __builtin_sprintf(char *, const char *, ...);\n");
1133 add_pre_buffer("extern int __builtin_snprintf(char *, __SIZE_TYPE__, const char *, ...);\n");
1134 add_pre_buffer("extern int __builtin_puts(const char *);\n");
1135 add_pre_buffer("extern int __builtin_vprintf(const char *, __builtin_va_list);\n");
1136 add_pre_buffer("extern int __builtin_vsprintf(char *, const char *, __builtin_va_list);\n");
1137 add_pre_buffer("extern int __builtin_vsnprintf(char *, __SIZE_TYPE__, const char *, __builtin_va_list ap);\n");
1140 void create_builtin_stream(void)
1142 add_pre_buffer("#weak_define __GNUC__ %d\n", gcc_major);
1143 add_pre_buffer("#weak_define __GNUC_MINOR__ %d\n", gcc_minor);
1144 add_pre_buffer("#weak_define __GNUC_PATCHLEVEL__ %d\n", gcc_patchlevel);
1146 /* add the multiarch include directories, if any */
1147 if (multiarch_dir && *multiarch_dir) {
1148 add_pre_buffer("#add_system \"/usr/include/%s\"\n", multiarch_dir);
1149 add_pre_buffer("#add_system \"/usr/local/include/%s\"\n", multiarch_dir);
1152 /* We add compiler headers path here because we have to parse
1153 * the arguments to get it, falling back to default. */
1154 add_pre_buffer("#add_system \"%s/include\"\n", gcc_base_dir);
1155 add_pre_buffer("#add_system \"%s/include-fixed\"\n", gcc_base_dir);
1157 add_pre_buffer("#define __extension__\n");
1158 add_pre_buffer("#define __pragma__\n");
1160 // gcc defines __SIZE_TYPE__ to be size_t. For linux/i86 and
1161 // solaris/sparc that is really "unsigned int" and for linux/x86_64
1162 // it is "long unsigned int". In either case we can probably
1163 // get away with this. We need the #weak_define as cgcc will define
1164 // the right __SIZE_TYPE__.
1165 if (size_t_ctype == &ulong_ctype)
1166 add_pre_buffer("#weak_define __SIZE_TYPE__ long unsigned int\n");
1167 else
1168 add_pre_buffer("#weak_define __SIZE_TYPE__ unsigned int\n");
1169 add_pre_buffer("#weak_define __STDC__ 1\n");
1171 switch (standard)
1173 case STANDARD_C89:
1174 add_pre_buffer("#weak_define __STRICT_ANSI__\n");
1175 break;
1177 case STANDARD_C94:
1178 add_pre_buffer("#weak_define __STDC_VERSION__ 199409L\n");
1179 add_pre_buffer("#weak_define __STRICT_ANSI__\n");
1180 break;
1182 case STANDARD_C99:
1183 add_pre_buffer("#weak_define __STDC_VERSION__ 199901L\n");
1184 add_pre_buffer("#weak_define __STRICT_ANSI__\n");
1185 break;
1187 case STANDARD_GNU89:
1188 break;
1190 case STANDARD_GNU99:
1191 add_pre_buffer("#weak_define __STDC_VERSION__ 199901L\n");
1192 break;
1194 case STANDARD_C11:
1195 add_pre_buffer("#weak_define __STRICT_ANSI__ 1\n");
1196 case STANDARD_GNU11:
1197 add_pre_buffer("#weak_define __STDC_NO_ATOMICS__ 1\n");
1198 add_pre_buffer("#weak_define __STDC_NO_COMPLEX__ 1\n");
1199 add_pre_buffer("#weak_define __STDC_NO_THREADS__ 1\n");
1200 add_pre_buffer("#weak_define __STDC_VERSION__ 201112L\n");
1201 break;
1203 default:
1204 assert (0);
1207 add_pre_buffer("#define __builtin_stdarg_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
1208 add_pre_buffer("#define __builtin_va_start(a,b) ((a) = (__builtin_va_list)(&(b)))\n");
1209 add_pre_buffer("#define __builtin_ms_va_start(a,b) ((a) = (__builtin_ms_va_list)(&(b)))\n");
1210 add_pre_buffer("#define __builtin_va_arg(arg,type) ({ type __va_arg_ret = *(type *)(arg); arg += sizeof(type); __va_arg_ret; })\n");
1211 add_pre_buffer("#define __builtin_va_alist (*(void *)0)\n");
1212 add_pre_buffer("#define __builtin_va_arg_incr(x) ((x) + 1)\n");
1213 add_pre_buffer("#define __builtin_va_copy(dest, src) ({ dest = src; (void)0; })\n");
1214 add_pre_buffer("#define __builtin_ms_va_copy(dest, src) ({ dest = src; (void)0; })\n");
1215 add_pre_buffer("#define __builtin_va_end(arg)\n");
1216 add_pre_buffer("#define __builtin_ms_va_end(arg)\n");
1217 add_pre_buffer("#define __builtin_va_arg_pack()\n");
1219 /* FIXME! We need to do these as special magic macros at expansion time! */
1220 add_pre_buffer("#define __BASE_FILE__ \"base_file.c\"\n");
1222 if (optimize)
1223 add_pre_buffer("#define __OPTIMIZE__ 1\n");
1224 if (optimize_size)
1225 add_pre_buffer("#define __OPTIMIZE_SIZE__ 1\n");
1228 static struct symbol_list *sparse_tokenstream(struct token *token)
1230 int builtin = token && !token->pos.stream;
1232 // Preprocess the stream
1233 token = preprocess(token);
1235 if (dump_macro_defs && !builtin)
1236 dump_macro_definitions();
1238 if (preprocess_only) {
1239 while (!eof_token(token)) {
1240 int prec = 1;
1241 struct token *next = token->next;
1242 const char *separator = "";
1243 if (next->pos.whitespace)
1244 separator = " ";
1245 if (next->pos.newline) {
1246 separator = "\n\t\t\t\t\t";
1247 prec = next->pos.pos;
1248 if (prec > 4)
1249 prec = 4;
1251 printf("%s%.*s", show_token(token), prec, separator);
1252 token = next;
1254 putchar('\n');
1256 return NULL;
1259 // Parse the resulting C code
1260 while (!eof_token(token))
1261 token = external_declaration(token, &translation_unit_used_list, NULL);
1262 return translation_unit_used_list;
1265 static struct symbol_list *sparse_file(const char *filename)
1267 int fd;
1268 struct token *token;
1270 if (strcmp (filename, "-") == 0) {
1271 fd = 0;
1272 } else {
1273 fd = open(filename, O_RDONLY);
1274 if (fd < 0)
1275 die("No such file: %s", filename);
1278 // Tokenize the input stream
1279 token = tokenize(filename, fd, NULL, includepath);
1280 close(fd);
1282 return sparse_tokenstream(token);
1286 * This handles the "-include" directive etc: we're in global
1287 * scope, and all types/macros etc will affect all the following
1288 * files.
1290 * NOTE NOTE NOTE! "#undef" of anything in this stage will
1291 * affect all subsequent files too, i.e. we can have non-local
1292 * behaviour between files!
1294 static struct symbol_list *sparse_initial(void)
1296 int i;
1298 // Prepend any "include" file to the stream.
1299 // We're in global scope, it will affect all files!
1300 for (i = 0; i < cmdline_include_nr; i++)
1301 add_pre_buffer("#argv_include \"%s\"\n", cmdline_include[i]);
1303 return sparse_tokenstream(pre_buffer_begin);
1306 struct symbol_list *sparse_initialize(int argc, char **argv, struct string_list **filelist)
1308 char **args;
1309 struct symbol_list *list;
1311 // Initialize symbol stream first, so that we can add defines etc
1312 init_symbols();
1314 args = argv;
1315 for (;;) {
1316 char *arg = *++args;
1317 if (!arg)
1318 break;
1320 if (arg[0] == '-' && arg[1]) {
1321 args = handle_switch(arg+1, args);
1322 continue;
1324 add_ptr_list_notag(filelist, arg);
1326 handle_switch_W_finalize();
1327 handle_switch_v_finalize();
1329 handle_arch_finalize();
1331 list = NULL;
1332 if (!ptr_list_empty(filelist)) {
1333 // Initialize type system
1334 init_ctype();
1336 create_builtin_stream();
1337 predefined_macros();
1338 if (!preprocess_only)
1339 declare_builtin_functions();
1341 list = sparse_initial();
1344 * Protect the initial token allocations, since
1345 * they need to survive all the others
1347 protect_token_alloc();
1349 return list;
1352 struct symbol_list * sparse_keep_tokens(char *filename)
1354 struct symbol_list *res;
1356 /* Clear previous symbol list */
1357 translation_unit_used_list = NULL;
1359 new_file_scope();
1360 res = sparse_file(filename);
1362 /* And return it */
1363 return res;
1367 struct symbol_list * __sparse(char *filename)
1369 struct symbol_list *res;
1371 res = sparse_keep_tokens(filename);
1373 /* Drop the tokens for this file after parsing */
1374 clear_token_alloc();
1376 /* And return it */
1377 return res;
1380 struct symbol_list * sparse(char *filename)
1382 struct symbol_list *res = __sparse(filename);
1384 if (has_error & ERROR_CURR_PHASE)
1385 has_error = ERROR_PREV_PHASE;
1386 /* Evaluate the complete symbol list */
1387 evaluate_symbol_list(res);
1389 return res;