use ushort wchar_t on mingw
[cparser] / main.c
1 /*
2  * This file is part of cparser.
3  * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
18  * 02111-1307, USA.
19  */
20 #include <config.h>
21
22 #define _GNU_SOURCE
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <stdbool.h>
27 #include <errno.h>
28 #include <string.h>
29 #include <assert.h>
30
31 #ifdef _WIN32
32
33 #include <fcntl.h>
34 #include <io.h>
35
36 /* no eXecute on Win32 */
37 #define X_OK 0
38 #define W_OK 2
39 #define R_OK 4
40
41 #define O_RDWR          _O_RDWR
42 #define O_CREAT         _O_CREAT
43 #define O_EXCL          _O_EXCL
44 #define O_BINARY        _O_BINARY
45
46 /* remap some names, we are not in the POSIX world */
47 #define access(fname, mode)      _access(fname, mode)
48 #define mktemp(tmpl)             _mktemp(tmpl)
49 #define open(fname, oflag, mode) _open(fname, oflag, mode)
50 #define fdopen(fd, mode)         _fdopen(fd, mode)
51 #define popen(cmd, mode)         _popen(cmd, mode)
52 #define pclose(file)             _pclose(file)
53
54 #else
55 #include <unistd.h>
56 #define HAVE_MKSTEMP
57 #endif
58
59 #ifndef WITH_LIBCORE
60 #define WITH_LIBCORE
61 #endif
62
63 #include <libfirm/firm.h>
64 #include <libfirm/be.h>
65
66 #include "lexer.h"
67 #include "token_t.h"
68 #include "types.h"
69 #include "type_hash.h"
70 #include "parser.h"
71 #include "type_t.h"
72 #include "ast2firm.h"
73 #include "diagnostic.h"
74 #include "lang_features.h"
75 #include "driver/firm_opt.h"
76 #include "driver/firm_cmdline.h"
77 #include "adt/error.h"
78 #include "write_fluffy.h"
79 #include "write_caml.h"
80 #include "revision.h"
81 #include "warning.h"
82
83 #ifndef PREPROCESSOR
84 #ifdef __APPLE__
85 #define PREPROCESSOR "gcc -E -std=c99 -m32 -U__STRICT_ANSI__"
86 #else
87 #define PREPROCESSOR "cpp -std=c99 -m32 -U__STRICT_ANSI__"
88 #endif
89 #endif
90
91 #ifndef LINKER
92 #define LINKER    "gcc -m32"
93 #endif
94
95 #ifndef ASSEMBLER
96 #ifdef __APPLE__
97 #define ASSEMBLER "gcc -c -xassembler"
98 #else
99 #define ASSEMBLER "as --32"
100 #endif
101 #endif
102
103 /** The current c mode/dialect. */
104 lang_features_t c_mode = _C89 | _ANSI | _C99 | _GNUC;
105
106 /** The 'machine size', 16, 32 or 64 bit, 32bit is the default. */
107 unsigned int machine_size = 32;
108
109 /** true if the char type is signed. */
110 bool char_is_signed = true;
111
112 /** true for strict language checking. */
113 bool strict_mode = false;
114
115 /** use builtins for some libc functions */
116 bool use_builtins = false;
117
118 /** we have extern function with const attribute. */
119 bool have_const_functions = false;
120
121 /* to switch on printing of implicit casts */
122 extern bool print_implicit_casts;
123
124 /* to switch on printing of parenthesis to indicate operator precedence */
125 extern bool print_parenthesis;
126
127 static int             verbose;
128 static struct obstack  cppflags_obst, ldflags_obst;
129 static char            dep_target[1024];
130 static const char     *outname;
131
132 typedef struct file_list_entry_t file_list_entry_t;
133
134 typedef enum filetype_t {
135         FILETYPE_AUTODETECT,
136         FILETYPE_C,
137         FILETYPE_PREPROCESSED_C,
138         FILETYPE_CXX,
139         FILETYPE_PREPROCESSED_CXX,
140         FILETYPE_ASSEMBLER,
141         FILETYPE_PREPROCESSED_ASSEMBLER,
142         FILETYPE_OBJECT,
143         FILETYPE_UNKNOWN
144 } filetype_t;
145
146 struct file_list_entry_t {
147         const char        *name; /**< filename or NULL for stdin */
148         filetype_t         type;
149         file_list_entry_t *next;
150 };
151
152 #if defined(_DEBUG) || defined(FIRM_DEBUG)
153 /**
154  * Debug printf implementation.
155  *
156  * @param fmt  printf style format parameter
157  */
158 void dbg_printf(const char *fmt, ...)
159 {
160         va_list list;
161
162         if (firm_dump.debug_print) {
163                 va_start(list, fmt);
164                 vprintf(fmt, list);
165                 va_end(list);
166         }  /* if */
167 }
168 #endif /* defined(_DEBUG) || defined(FIRM_DEBUG) */
169
170 static void initialize_firm(void)
171 {
172         firm_early_init();
173
174         dump_consts_local(1);
175         dump_keepalive_edges(1);
176 }
177
178 static void get_output_name(char *buf, size_t buflen, const char *inputname,
179                             const char *newext)
180 {
181         size_t last_dot = 0xffffffff;
182         size_t i = 0;
183
184         if(inputname == NULL) {
185                 snprintf(buf, buflen, "a%s", newext);
186                 return;
187         }
188
189         for(const char *c = inputname; *c != 0; ++c) {
190                 if(*c == '.')
191                         last_dot = i;
192                 ++i;
193         }
194         if(last_dot == 0xffffffff)
195                 last_dot = i;
196
197         if(last_dot >= buflen)
198                 panic("filename too long");
199         memcpy(buf, inputname, last_dot);
200
201         size_t extlen = strlen(newext) + 1;
202         if(extlen + last_dot >= buflen)
203                 panic("filename too long");
204         memcpy(buf+last_dot, newext, extlen);
205 }
206
207 #include "builtins.h"
208
209 static translation_unit_t *do_parsing(FILE *const in, const char *const input_name)
210 {
211         start_parsing();
212
213         if (use_builtins) {
214                 lexer_open_buffer(builtins, sizeof(builtins)-1, "<builtin>");
215                 parse();
216         }
217
218         lexer_open_stream(in, input_name);
219         parse();
220
221         translation_unit_t *unit = finish_parsing();
222         return unit;
223 }
224
225 static void lextest(FILE *in, const char *fname)
226 {
227         lexer_open_stream(in, fname);
228
229         do {
230                 lexer_next_preprocessing_token();
231                 print_token(stdout, &lexer_token);
232                 puts("");
233         } while(lexer_token.type != T_EOF);
234 }
235
236 static void add_flag(struct obstack *obst, const char *format, ...)
237 {
238         va_list ap;
239         va_start(ap, format);
240
241         char buf[4096];
242         vsnprintf(buf, sizeof(buf), format, ap);
243
244         /* escape stuff... */
245         obstack_1grow(obst, ' ');
246         for (char *c = buf; *c != '\0'; ++c) {
247                 switch(*c) {
248                 case '"':
249                 case '\'':
250                 case '`':
251                 case ' ':
252                 case '\t':
253                 case '\n':
254                 case '\r':
255                 case '\\':
256                 case '$':
257                 case '(':
258                 case ')':
259                         obstack_1grow(obst, '\\');
260                         /* fallthrough */
261                 default:
262                         obstack_1grow(obst, *c);
263                         break;
264                 }
265         }
266
267         va_end(ap);
268 }
269
270 static const char *type_to_string(type_t *type)
271 {
272         assert(type->kind == TYPE_ATOMIC);
273         return get_atomic_kind_name(type->atomic.akind);
274 }
275
276 static FILE *preprocess(const char *fname)
277 {
278         obstack_1grow(&cppflags_obst, '\0');
279         const char *flags = obstack_finish(&cppflags_obst);
280
281         obstack_printf(&cppflags_obst, "%s", PREPROCESSOR);
282
283         /* setup default defines */
284         add_flag(&cppflags_obst, "-U__WCHAR_TYPE__");
285         add_flag(&cppflags_obst, "-D__WCHAR_TYPE__=%s",
286                  type_to_string(type_wchar_t));
287         add_flag(&cppflags_obst, "-U__SIZE_TYPE__");
288         add_flag(&cppflags_obst, "-D__SIZE_TYPE__=%s", type_to_string(type_size_t));
289
290         /* handle dependency generation */
291         if (dep_target[0] != '\0') {
292                 add_flag(&cppflags_obst, "-MF");
293                 add_flag(&cppflags_obst, "%s", dep_target);
294                 if (outname != NULL) {
295                                 add_flag(&cppflags_obst, "-MQ");
296                                 add_flag(&cppflags_obst, "%s", outname);
297                 }
298         }
299         if (flags[0] != '\0') {
300                 obstack_printf(&cppflags_obst, " %s", flags);
301         }
302         add_flag(&cppflags_obst, "%s", fname);
303
304         obstack_1grow(&cppflags_obst, '\0');
305         const char *buf = obstack_finish(&cppflags_obst);
306         if(verbose) {
307                 puts(buf);
308         }
309
310         FILE *f = popen(buf, "r");
311         if(f == NULL) {
312                 fprintf(stderr, "invoking preprocessor failed\n");
313                 exit(1);
314         }
315
316         return f;
317 }
318
319 static void assemble(const char *out, const char *in)
320 {
321         char buf[4096];
322
323         snprintf(buf, sizeof(buf), "%s %s -o %s", ASSEMBLER, in, out);
324         if(verbose) {
325                 puts(buf);
326         }
327
328         int err = system(buf);
329         if(err != 0) {
330                 fprintf(stderr, "assembler reported an error\n");
331                 exit(1);
332         }
333 }
334
335 static const char *try_dir(const char *dir)
336 {
337         if(dir == NULL)
338                 return dir;
339         if(access(dir, R_OK | W_OK | X_OK) == 0)
340                 return dir;
341         return NULL;
342 }
343
344 static const char *get_tempdir(void)
345 {
346         static const char *tmpdir = NULL;
347
348         if(tmpdir != NULL)
349                 return tmpdir;
350
351         if(tmpdir == NULL)
352                 tmpdir = try_dir(getenv("TMPDIR"));
353         if(tmpdir == NULL)
354                 tmpdir = try_dir(getenv("TMP"));
355         if(tmpdir == NULL)
356                 tmpdir = try_dir(getenv("TEMP"));
357
358 #ifdef P_tmpdir
359         if(tmpdir == NULL)
360                 tmpdir = try_dir(P_tmpdir);
361 #endif
362
363         if(tmpdir == NULL)
364                 tmpdir = try_dir("/var/tmp");
365         if(tmpdir == NULL)
366                 tmpdir = try_dir("/usr/tmp");
367         if(tmpdir == NULL)
368                 tmpdir = try_dir("/tmp");
369
370         if(tmpdir == NULL)
371                 tmpdir = ".";
372
373         return tmpdir;
374 }
375
376 #ifndef HAVE_MKSTEMP
377 /* cheap and nasty mkstemp replacement */
378 static int mkstemp(char *templ)
379 {
380         mktemp(templ);
381         return open(templ, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600);
382 }
383 #endif
384
385 /**
386  * an own version of tmpnam, which: writes in a buffer, emits no warnings
387  * during linking (like glibc/gnu ld do for tmpnam)...
388  */
389 static FILE *make_temp_file(char *buffer, size_t buflen, const char *prefix)
390 {
391         const char *tempdir = get_tempdir();
392
393         snprintf(buffer, buflen, "%s/%sXXXXXX", tempdir, prefix);
394
395         int fd = mkstemp(buffer);
396         if(fd == -1) {
397                 fprintf(stderr, "couldn't create temporary file: %s\n",
398                         strerror(errno));
399                 exit(1);
400         }
401         FILE *out = fdopen(fd, "w");
402         if(out == NULL) {
403                 fprintf(stderr, "couldn't create temporary file FILE*\n");
404                 exit(1);
405         }
406
407         return out;
408 }
409
410 /**
411  * Do the necessary lowering for compound parameters.
412  */
413 void lower_compound_params(void)
414 {
415         lower_params_t params;
416
417         params.def_ptr_alignment    = 4;
418         params.flags                = LF_COMPOUND_RETURN | LF_RETURN_HIDDEN;
419         params.hidden_params        = ADD_HIDDEN_ALWAYS_IN_FRONT;
420         params.find_pointer_type    = NULL;
421         params.ret_compound_in_regs = NULL;
422         lower_calls_with_compounds(&params);
423 }
424
425 typedef enum compile_mode_t {
426         BenchmarkParser,
427         PreprocessOnly,
428         ParseOnly,
429         Compile,
430         CompileDump,
431         CompileAssemble,
432         CompileAssembleLink,
433         LexTest,
434         PrintAst,
435         PrintFluffy,
436         PrintCaml
437 } compile_mode_t;
438
439 static void usage(const char *argv0)
440 {
441         fprintf(stderr, "Usage %s input [-o output] [-c]\n", argv0);
442 }
443
444 static void print_cparser_version(void) {
445         firm_version_t ver;
446         firm_get_version(&ver);
447
448         printf("cparser (%s) using libFirm (%u.%u",
449                 cparser_REVISION, ver.major, ver.minor);
450         if(ver.revision[0] != 0) {
451                 putchar(' ');
452                 fputs(ver.revision, stdout);
453         }
454         if(ver.build[0] != 0) {
455                 putchar(' ');
456                 fputs(ver.build, stdout);
457         }
458         puts(")\n");
459 }
460
461 static void set_be_option(const char *arg)
462 {
463         int res = firm_be_option(arg);
464         (void) res;
465         assert(res);
466 }
467
468 static void set_option(const char *arg)
469 {
470         int res = firm_option(arg);
471         (void) res;
472         assert(res);
473 }
474
475 static void copy_file(FILE *dest, FILE *input)
476 {
477         char buf[16384];
478
479         while (!feof(input) && !ferror(dest)) {
480                 size_t read = fread(buf, 1, sizeof(buf), input);
481                 if(fwrite(buf, 1, read, dest) != read) {
482                         perror("couldn't write output");
483                 }
484         }
485 }
486
487 static inline bool streq(char const* a, char const* b)
488 {
489         return strcmp(a, b) == 0;
490 }
491
492 static inline bool strstart(char const* str, char const* start)
493 {
494         do {
495                 if (*start == '\0')
496                         return true;
497         } while (*str++ == *start++);
498         return false;
499 }
500
501 static FILE *open_file(const char *filename)
502 {
503         if (streq(filename, "-")) {
504                 return stdin;
505         }
506
507         FILE *in = fopen(filename, "r");
508         if(in == NULL) {
509                 fprintf(stderr, "Couldn't open '%s': %s\n", filename,
510                                 strerror(errno));
511                 exit(1);
512         }
513
514         return in;
515 }
516
517 static filetype_t get_filetype_from_string(const char *string)
518 {
519         if (streq(string, "c") || streq(string, "c-header"))
520                 return FILETYPE_C;
521         if (streq(string, "c++") || streq(string, "c++-header"))
522                 return FILETYPE_CXX;
523         if (streq(string, "assembler"))
524                 return FILETYPE_PREPROCESSED_ASSEMBLER;
525         if (streq(string, "assembler-with-cpp"))
526                 return FILETYPE_ASSEMBLER;
527         if (streq(string, "none"))
528                 return FILETYPE_AUTODETECT;
529
530         return FILETYPE_UNKNOWN;
531 }
532
533 static void init_os_support(void)
534 {
535         /* OS option must be set to the backend */
536         switch (firm_opt.os_support) {
537         case OS_SUPPORT_MINGW:
538                 set_be_option("ia32-gasmode=mingw");
539                 wchar_atomic_kind = ATOMIC_TYPE_USHORT;
540                 break;
541         case OS_SUPPORT_LINUX:
542                 set_be_option("ia32-gasmode=elf");
543                 break;
544         case OS_SUPPORT_MACHO:
545                 set_be_option("ia32-gasmode=macho");
546                 set_be_option("ia32-stackalign=4");
547                 set_be_option("pic");
548                 break;
549         }
550 }
551
552 typedef enum lang_standard_t {
553         STANDARD_DEFAULT, /* gnu99 (for C, GCC does gnu89) or gnu++98 (for C++) */
554         STANDARD_ANSI,    /* c89 (for C) or c++98 (for C++) */
555         STANDARD_C89,     /* ISO C90 (sic) */
556         STANDARD_C90,     /* ISO C90 as modified in amendment 1 */
557         STANDARD_C99,     /* ISO C99 */
558         STANDARD_GNU89,   /* ISO C90 plus GNU extensions (including some C99) */
559         STANDARD_GNU99,   /* ISO C99 plus GNU extensions */
560         STANDARD_CXX98,   /* ISO C++ 1998 plus amendments */
561         STANDARD_GNUXX98  /* ISO C++ 1998 plus amendments and GNU extensions */
562 } lang_standard_t;
563
564 int main(int argc, char **argv)
565 {
566         initialize_firm();
567
568         const char        *dumpfunction         = NULL;
569         compile_mode_t     mode                 = CompileAssembleLink;
570         int                opt_level            = 1;
571         int                result               = EXIT_SUCCESS;
572         char               cpu_arch[16]         = "ia32";
573         file_list_entry_t *files                = NULL;
574         file_list_entry_t *last_file            = NULL;
575         bool               construct_dep_target = false;
576         struct obstack     file_obst;
577
578         /* hack for now... */
579         if (strstr(argv[0], "pptest") != NULL) {
580                 extern int pptest_main(int argc, char **argv);
581                 return pptest_main(argc, argv);
582         }
583
584         obstack_init(&cppflags_obst);
585         obstack_init(&ldflags_obst);
586         obstack_init(&file_obst);
587
588 #define GET_ARG_AFTER(def, args)                                             \
589         def = &arg[sizeof(args)-1];                                              \
590         if(def[0] == '\0') {                                                     \
591                 ++i;                                                                 \
592                 if(i >= argc) {                                                      \
593                         fprintf(stderr, "error: expected argument after '" args "'\n");  \
594                         argument_errors = true;                                          \
595                         break;                                                           \
596                 }                                                                    \
597                 def = argv[i];                                                       \
598                 if(def[0] == '-' && def[1] != '\0') {                                \
599                         fprintf(stderr, "error: expected argument after '" args "'\n");  \
600                         argument_errors = true;                                          \
601                         continue;                                                        \
602                 }                                                                    \
603         }
604
605 #define SINGLE_OPTION(ch) (option[0] == (ch) && option[1] == '\0')
606
607         /* early options parsing (find out optimisation level and OS) */
608         for (int i = 1; i < argc; ++i) {
609                 const char *arg = argv[i];
610                 if(arg[0] != '-')
611                         continue;
612
613                 const char *option = &arg[1];
614                 if (option[0] == 'O') {
615                         sscanf(&option[1], "%d", &opt_level);
616                 }
617                 if (strcmp(arg, "-fwin32") == 0) {
618                         firm_opt.os_support = OS_SUPPORT_MINGW;
619                 } else if (strcmp(arg, "-fmac") == 0) {
620                         firm_opt.os_support = OS_SUPPORT_MACHO;
621                 } else if (strcmp(arg, "-flinux") == 0) {
622                         firm_opt.os_support = OS_SUPPORT_LINUX;
623                 }
624         }
625
626         /* set target/os specific stuff */
627         init_os_support();
628
629         /* apply optimisation level */
630         switch(opt_level) {
631         case 0:
632                 set_option("no-opt");
633                 break;
634         case 1:
635                 set_option("no-inline");
636                 break;
637         default:
638         case 4:
639                 set_option("strict-aliasing");
640                 /* use_builtins = true; */
641                 /* fallthrough */
642         case 3:
643                 set_option("cond-eval");
644                 set_option("if-conv");
645                 /* fallthrough */
646         case 2:
647                 set_option("inline");
648                 set_option("deconv");
649                 set_be_option("omitfp");
650                 break;
651         }
652
653         /* parse rest of options */
654         lang_standard_t standard        = STANDARD_DEFAULT;
655         lang_features_t features_on     = 0;
656         lang_features_t features_off    = 0;
657         filetype_t      forced_filetype = FILETYPE_AUTODETECT;
658         bool            help_displayed  = false;
659         bool            argument_errors = false;
660         for(int i = 1; i < argc; ++i) {
661                 const char *arg = argv[i];
662                 if (arg[0] == '-' && arg[1] != '\0') {
663                         /* an option */
664                         const char *option = &arg[1];
665                         if(option[0] == 'o') {
666                                 GET_ARG_AFTER(outname, "-o");
667                         } else if(option[0] == 'g') {
668                                 set_be_option("debuginfo=stabs");
669                                 set_be_option("omitfp=no");
670                                 set_be_option("ia32-nooptcc=yes");
671                         } else if(SINGLE_OPTION('c')) {
672                                 mode = CompileAssemble;
673                         } else if(SINGLE_OPTION('E')) {
674                                 mode = PreprocessOnly;
675                         } else if(SINGLE_OPTION('S')) {
676                                 mode = Compile;
677                         } else if(option[0] == 'O') {
678                                 continue;
679                         } else if(option[0] == 'I') {
680                                 const char *opt;
681                                 GET_ARG_AFTER(opt, "-I");
682                                 add_flag(&cppflags_obst, "-I%s", opt);
683                         } else if(option[0] == 'D') {
684                                 const char *opt;
685                                 GET_ARG_AFTER(opt, "-D");
686                                 add_flag(&cppflags_obst, "-D%s", opt);
687                         } else if(option[0] == 'U') {
688                                 const char *opt;
689                                 GET_ARG_AFTER(opt, "-U");
690                                 add_flag(&cppflags_obst, "-U%s", opt);
691                         } else if(option[0] == 'l') {
692                                 const char *opt;
693                                 GET_ARG_AFTER(opt, "-l");
694                                 add_flag(&ldflags_obst, "-l%s", opt);
695                         } else if(option[0] == 'L') {
696                                 const char *opt;
697                                 GET_ARG_AFTER(opt, "-L");
698                                 add_flag(&ldflags_obst, "-L%s", opt);
699                         } else if(SINGLE_OPTION('v')) {
700                                 verbose = 1;
701                         } else if(SINGLE_OPTION('w')) {
702                                 memset(&warning, 0, sizeof(warning));
703                         } else if(option[0] == 'x') {
704                                 const char *opt;
705                                 GET_ARG_AFTER(opt, "-x");
706                                 forced_filetype = get_filetype_from_string(opt);
707                                 if (forced_filetype == FILETYPE_UNKNOWN) {
708                                         fprintf(stderr, "Unknown language '%s'\n", opt);
709                                         argument_errors = true;
710                                 }
711                         } else if (streq(option, "M")) {
712                                 mode = PreprocessOnly;
713                                 add_flag(&cppflags_obst, "-M");
714                         } else if (streq(option, "MMD") ||
715                                    streq(option, "MD")) {
716                             construct_dep_target = true;
717                                 add_flag(&cppflags_obst, "-%s", option);
718                         } else if(streq(option, "MM")  ||
719                                    streq(option, "MP")) {
720                                 add_flag(&cppflags_obst, "-%s", option);
721                         } else if (streq(option, "MT") ||
722                                    streq(option, "MQ") ||
723                                    streq(option, "MF")) {
724                                 const char *opt;
725                                 GET_ARG_AFTER(opt, "-MT");
726                                 add_flag(&cppflags_obst, "-%s", option);
727                                 add_flag(&cppflags_obst, "%s", opt);
728                         } else if (streq(option, "pipe")) {
729                                 /* here for gcc compatibility */
730                         } else if (option[0] == 'f') {
731                                 char const *orig_opt;
732                                 GET_ARG_AFTER(orig_opt, "-f");
733
734                                 if (strstart(orig_opt, "align-loops=") ||
735                                     strstart(orig_opt, "align-jumps=") ||
736                                     strstart(orig_opt, "align-functions=")) {
737                                         fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt);
738                                 } else {
739                                         char const *opt         = orig_opt;
740                                         bool        truth_value = true;
741                                         if (opt[0] == 'n' && opt[1] == 'o' && opt[2] == '-') {
742                                                 truth_value = false;
743                                                 opt += 3;
744                                         }
745
746                                         if (streq(opt, "dollars-in-identifiers")) {
747                                                 allow_dollar_in_symbol = truth_value;
748                                         } if (streq(opt, "builtins")) {
749                                                 use_builtins = truth_value;
750                                         } else if (streq(opt, "short-wchar")) {
751                                                 wchar_atomic_kind = truth_value ? ATOMIC_TYPE_USHORT
752                                                         : ATOMIC_TYPE_INT;
753                                         } else if (streq(opt, "syntax-only")) {
754                                                 mode = truth_value ? ParseOnly : CompileAssembleLink;
755                                         } else if (streq(opt, "omit-frame-pointer")) {
756                                                 set_be_option(truth_value ? "omitfp" : "omitfp=no");
757                                         } else if (streq(opt, "strength-reduce")) {
758                                                 firm_option(truth_value ? "strength-red" : "no-strength-red");
759                                         } else if (streq(opt, "fast-math")               ||
760                                                    streq(opt, "jump-tables")             ||
761                                                    streq(opt, "unroll-loops")            ||
762                                                    streq(opt, "expensive-optimizations") ||
763                                                    streq(opt, "common")                  ||
764                                                    streq(opt, "PIC")                     ||
765                                                    streq(opt, "align-loops")             ||
766                                                    streq(opt, "align-jumps")             ||
767                                                    streq(opt, "align-functions")) {
768                                                 fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt);
769                                         } else {
770                                                 int res = firm_option(orig_opt);
771                                                 if (res == 0) {
772                                                         fprintf(stderr, "error: unknown Firm option '-f%s'\n",
773                                                                 orig_opt);
774                                                         argument_errors = true;
775                                                         continue;
776                                                 } else if (res == -1) {
777                                                         help_displayed = true;
778                                                 }
779                                         }
780                                 }
781                         } else if (option[0] == 'b') {
782                                 const char *opt;
783                                 GET_ARG_AFTER(opt, "-b");
784                                 int res = firm_be_option(opt);
785                                 if (res == 0) {
786                                         fprintf(stderr, "error: unknown Firm backend option '-b %s'\n",
787                                                 opt);
788                                         argument_errors = true;
789                                 } else if (res == -1) {
790                                         help_displayed = true;
791                                 } else if (strstart(opt, "isa=")) {
792                                         strncpy(cpu_arch, opt, sizeof(cpu_arch));
793                                 }
794                         } else if (option[0] == 'W') {
795                                 if (strstart(option + 1, "l,")) // a gcc-style linker option
796                                 {
797                                         const char *opt;
798                                         GET_ARG_AFTER(opt, "-Wl,");
799                                         add_flag(&ldflags_obst, "-Wl,%s", opt);
800                                 }
801                                 else set_warning_opt(&option[1]);
802                         } else if(option[0] == 'm') {
803                                 /* -m options */
804                                 const char *opt;
805                                 char arch_opt[64];
806
807                                 GET_ARG_AFTER(opt, "-m");
808                                 if (strstart(opt, "arch=")) {
809                                         GET_ARG_AFTER(opt, "-march=");
810                                         snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt);
811                                         int res = firm_be_option(arch_opt);
812                                         if (res == 0)
813                                                 argument_errors = true;
814                                         else {
815                                                 snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt);
816                                                 int res = firm_be_option(arch_opt);
817                                                 if (res == 0)
818                                                         argument_errors = true;
819                                         }
820                                 } else if (strstart(opt, "tune=")) {
821                                         GET_ARG_AFTER(opt, "-mtune=");
822                                         snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt);
823                                         int res = firm_be_option(arch_opt);
824                                         if (res == 0)
825                                                 argument_errors = true;
826                                 } else if (strstart(opt, "cpu=")) {
827                                         GET_ARG_AFTER(opt, "-mcpu=");
828                                         snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt);
829                                         int res = firm_be_option(arch_opt);
830                                         if (res == 0)
831                                                 argument_errors = true;
832                                 } else if (strstart(opt, "fpmath=")) {
833                                         GET_ARG_AFTER(opt, "-mfpmath=");
834                                         if (streq(opt, "387"))
835                                                 opt = "x87";
836                                         else if (streq(opt, "sse"))
837                                                 opt = "sse2";
838                                         else {
839                                                 fprintf(stderr, "error: option -mfpumath supports only 387 or sse\n");
840                                                 argument_errors = true;
841                                         }
842                                         if(!argument_errors) {
843                                                 snprintf(arch_opt, sizeof(arch_opt), "%s-fpunit=%s", cpu_arch, opt);
844                                                 int res = firm_be_option(arch_opt);
845                                                 if (res == 0)
846                                                         argument_errors = true;
847                                         }
848                                 } else if (strstart(opt, "preferred-stack-boundary=")) {
849                                         GET_ARG_AFTER(opt, "-mpreferred-stack-boundary=");
850                                         snprintf(arch_opt, sizeof(arch_opt), "%s-stackalign=%s", cpu_arch, opt);
851                                         int res = firm_be_option(arch_opt);
852                                         if (res == 0)
853                                                 argument_errors = true;
854                                 } else if (streq(opt, "omit-leaf-frame-pointer")) {
855                                         set_be_option("omitleaffp=1");
856                                 } else if (streq(opt, "no-omit-leaf-frame-pointer")) {
857                                         set_be_option("omitleaffp=0");
858                                 } else {
859                                         char *endptr;
860                                         long int value = strtol(opt, &endptr, 10);
861                                         if (*endptr != '\0') {
862                                                 fprintf(stderr, "error: wrong option '-m %s'\n",  opt);
863                                                 argument_errors = true;
864                                         }
865                                         if (value != 16 && value != 32 && value != 64) {
866                                                 fprintf(stderr, "error: option -m supports only 16, 32 or 64\n");
867                                                 argument_errors = true;
868                                         } else {
869                                                 machine_size = (unsigned int)value;
870                                         }
871                                 }
872                         } else if (streq(option, "pg")) {
873                                 set_be_option("gprof");
874                                 add_flag(&ldflags_obst, "-pg");
875                         } else if (streq(option, "pedantic") ||
876                                    streq(option, "ansi")) {
877                                 fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);
878                         } else if (streq(option, "shared")) {
879                                 add_flag(&ldflags_obst, "-shared");
880                         } else if (strstart(option, "std=")) {
881                                 const char *const o = &option[4];
882                                 standard =
883                                         streq(o, "c++")            ? STANDARD_CXX98   :
884                                         streq(o, "c++98")          ? STANDARD_CXX98   :
885                                         streq(o, "c89")            ? STANDARD_C89     :
886                                         streq(o, "c99")            ? STANDARD_C99     :
887                                         streq(o, "c9x")            ? STANDARD_C99     : // deprecated
888                                         streq(o, "gnu++98")        ? STANDARD_GNUXX98 :
889                                         streq(o, "gnu89")          ? STANDARD_GNU89   :
890                                         streq(o, "gnu99")          ? STANDARD_GNU99   :
891                                         streq(o, "gnu9x")          ? STANDARD_GNU99   : // deprecated
892                                         streq(o, "iso9899:1990")   ? STANDARD_C89     :
893                                         streq(o, "iso9899:199409") ? STANDARD_C90     :
894                                         streq(o, "iso9899:1999")   ? STANDARD_C99     :
895                                         streq(o, "iso9899:199x")   ? STANDARD_C99     : // deprecated
896                                         (fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg), standard);
897                         } else if (streq(option, "version")) {
898                                 print_cparser_version();
899                         } else if (option[0] == '-') {
900                                 /* double dash option */
901                                 ++option;
902                                 if (streq(option, "gcc")) {
903                                         features_on  |=  _GNUC;
904                                         features_off &= ~_GNUC;
905                                 } else if (streq(option, "no-gcc")) {
906                                         features_on  &= ~_GNUC;
907                                         features_off |=  _GNUC;
908                                 } else if (streq(option, "ms")) {
909                                         features_on  |=  _MS;
910                                         features_off &= ~_MS;
911                                 } else if (streq(option, "no-ms")) {
912                                         features_on  &= ~_MS;
913                                         features_off |=  _MS;
914                                 } else if (streq(option, "signed-chars")) {
915                                         char_is_signed = true;
916                                 } else if (streq(option, "unsigned-chars")) {
917                                         char_is_signed = false;
918                                 } else if (streq(option, "strict")) {
919                                         strict_mode = true;
920                                 } else if (streq(option, "lextest")) {
921                                         mode = LexTest;
922                                 } else if (streq(option, "benchmark")) {
923                                         mode = BenchmarkParser;
924                                 } else if (streq(option, "print-ast")) {
925                                         mode = PrintAst;
926                                 } else if (streq(option, "print-implicit-cast")) {
927                                         print_implicit_casts = true;
928                                 } else if (streq(option, "print-parenthesis")) {
929                                         print_parenthesis = true;
930                                 } else if (streq(option, "print-fluffy")) {
931                                         mode = PrintFluffy;
932                                 } else if (streq(option, "print-caml")) {
933                                         mode = PrintCaml;
934                                 } else if (streq(option, "version")) {
935                                         print_cparser_version();
936                                         exit(EXIT_SUCCESS);
937                                 } else if (streq(option, "dump-function")) {
938                                         ++i;
939                                         if(i >= argc) {
940                                                 fprintf(stderr, "error: "
941                                                         "expected argument after '--dump-function'\n");
942                                                 argument_errors = true;
943                                                 break;
944                                         }
945                                         dumpfunction = argv[i];
946                                         mode         = CompileDump;
947                                 } else {
948                                         fprintf(stderr, "error: unknown argument '%s'\n", arg);
949                                         argument_errors = true;
950                                 }
951                         } else {
952                                 fprintf(stderr, "error: unknown argument '%s'\n", arg);
953                                 argument_errors = true;
954                         }
955                 } else {
956                         filetype_t type = forced_filetype;
957                         if (type == FILETYPE_AUTODETECT) {
958                                 if (streq(arg, "-")) {
959                                         /* - implicitly means C source file */
960                                         type = FILETYPE_C;
961                                 } else {
962                                         const char *suffix = strrchr(arg, '.');
963                                         /* Ensure there is at least one char before the suffix */
964                                         if (suffix != NULL && suffix != arg) {
965                                                 ++suffix;
966                                                 type =
967                                                         streq(suffix, "S")   ? FILETYPE_ASSEMBLER              :
968                                                         streq(suffix, "a")   ? FILETYPE_OBJECT                 :
969                                                         streq(suffix, "c")   ? FILETYPE_C                      :
970                                                         streq(suffix, "cc")  ? FILETYPE_CXX                    :
971                                                         streq(suffix, "cpp") ? FILETYPE_CXX                    :
972                                                         streq(suffix, "cxx") ? FILETYPE_CXX                    :
973                                                         streq(suffix, "h")   ? FILETYPE_C                      :
974                                                         streq(suffix, "o")   ? FILETYPE_OBJECT                 :
975                                                         streq(suffix, "s")   ? FILETYPE_PREPROCESSED_ASSEMBLER :
976                                                         streq(suffix, "so")  ? FILETYPE_OBJECT                 :
977                                                         FILETYPE_AUTODETECT;
978                                         }
979                                 }
980
981                                 if (type == FILETYPE_AUTODETECT) {
982                                         fprintf(stderr, "'%s': file format not recognized\n", arg);
983                                         continue;
984                                 }
985                         }
986
987                         file_list_entry_t *entry
988                                 = obstack_alloc(&file_obst, sizeof(entry[0]));
989                         memset(entry, 0, sizeof(entry[0]));
990                         entry->name = arg;
991                         entry->type = type;
992
993                         if (last_file != NULL) {
994                                 last_file->next = entry;
995                         } else {
996                                 files = entry;
997                         }
998                         last_file = entry;
999                 }
1000         }
1001
1002         if (files == NULL) {
1003                 fprintf(stderr, "error: no input files specified\n");
1004                 argument_errors = true;
1005         }
1006
1007         if (help_displayed) {
1008                 return !argument_errors;
1009         }
1010         if (argument_errors) {
1011                 usage(argv[0]);
1012                 return 1;
1013         }
1014
1015         /* we do the lowering in ast2firm */
1016         firm_opt.lower_bitfields = FALSE;
1017
1018         gen_firm_init();
1019         init_symbol_table();
1020         init_types();
1021         init_typehash();
1022         init_basic_types();
1023         init_lexer();
1024         init_ast();
1025         init_parser();
1026         init_ast2firm();
1027
1028         if (construct_dep_target) {
1029                 if (outname != 0 && strlen(outname) >= 2) {
1030                         get_output_name(dep_target, sizeof(dep_target), outname, ".d");
1031                 } else {
1032                         get_output_name(dep_target, sizeof(dep_target), files->name, ".d");
1033                 }
1034         } else {
1035                 dep_target[0] = '\0';
1036         }
1037
1038         char outnamebuf[4096];
1039         if (outname == NULL) {
1040                 const char *filename = files->name;
1041
1042                 switch(mode) {
1043                 case BenchmarkParser:
1044                 case PrintAst:
1045                 case PrintFluffy:
1046                 case PrintCaml:
1047                 case LexTest:
1048                 case PreprocessOnly:
1049                 case ParseOnly:
1050                         outname = "-";
1051                         break;
1052                 case Compile:
1053                         get_output_name(outnamebuf, sizeof(outnamebuf), filename, ".s");
1054                         outname = outnamebuf;
1055                         break;
1056                 case CompileAssemble:
1057                         get_output_name(outnamebuf, sizeof(outnamebuf), filename, ".o");
1058                         outname = outnamebuf;
1059                         break;
1060                 case CompileDump:
1061                         get_output_name(outnamebuf, sizeof(outnamebuf), dumpfunction,
1062                                         ".vcg");
1063                         outname = outnamebuf;
1064                         break;
1065                 case CompileAssembleLink:
1066 #ifdef _WIN32
1067                         outname = "a.exe";
1068 #else
1069                         outname = "a.out";
1070 #endif
1071                         break;
1072                 }
1073         }
1074
1075         assert(outname != NULL);
1076
1077         FILE *out;
1078         if (streq(outname, "-")) {
1079                 out = stdout;
1080         } else {
1081                 out = fopen(outname, "w");
1082                 if(out == NULL) {
1083                         fprintf(stderr, "Couldn't open '%s' for writing: %s\n", outname,
1084                                         strerror(errno));
1085                         return 1;
1086                 }
1087         }
1088
1089         file_list_entry_t *file;
1090         for (file = files; file != NULL; file = file->next) {
1091                 char        asm_tempfile[1024];
1092                 const char *filename = file->name;
1093                 filetype_t  filetype = file->type;
1094
1095                 if (filetype == FILETYPE_OBJECT)
1096                         continue;
1097
1098                 FILE *in = NULL;
1099                 if (mode == LexTest) {
1100                         if (in == NULL)
1101                                 in = open_file(filename);
1102                         lextest(in, filename);
1103                         fclose(in);
1104                         exit(EXIT_SUCCESS);
1105                 }
1106
1107                 FILE *preprocessed_in = NULL;
1108                 switch (filetype) {
1109                         case FILETYPE_C:         filetype = FILETYPE_PREPROCESSED_C;         goto preprocess;
1110                         case FILETYPE_CXX:       filetype = FILETYPE_PREPROCESSED_CXX;       goto preprocess;
1111                         case FILETYPE_ASSEMBLER: filetype = FILETYPE_PREPROCESSED_ASSEMBLER; goto preprocess;
1112 preprocess:
1113                                 /* no support for input on FILE* yet */
1114                                 if (in != NULL)
1115                                         panic("internal compiler error: in for preprocessor != NULL");
1116
1117                                 preprocessed_in = preprocess(filename);
1118                                 if (mode == PreprocessOnly) {
1119                                         copy_file(out, preprocessed_in);
1120                                         int result = pclose(preprocessed_in);
1121                                         fclose(out);
1122                                         return result;
1123                                 }
1124
1125                                 in = preprocessed_in;
1126                                 break;
1127
1128                         default:
1129                                 break;
1130                 }
1131
1132                 FILE *asm_out;
1133                 if(mode == Compile) {
1134                         asm_out = out;
1135                 } else {
1136                         asm_out = make_temp_file(asm_tempfile, sizeof(asm_tempfile), "ccs");
1137                 }
1138
1139                 if (in == NULL)
1140                         in = open_file(filename);
1141
1142                 /* preprocess and compile */
1143                 if (filetype == FILETYPE_PREPROCESSED_C) {
1144                         char const* invalid_mode;
1145                         switch (standard) {
1146                                 case STANDARD_ANSI:
1147                                 case STANDARD_C89:   c_mode = _C89;                break;
1148                                 /* TODO ^v determine difference between these two */
1149                                 case STANDARD_C90:   c_mode = _C89;                break;
1150                                 case STANDARD_C99:   c_mode = _C89 | _C99;         break;
1151                                 case STANDARD_GNU89: c_mode = _C89 |        _GNUC; break;
1152
1153 default_c_warn:
1154                                         fprintf(stderr,
1155                                                         "warning: command line option \"-std=%s\" is not valid for C\n",
1156                                                         invalid_mode);
1157                                         /* FALLTHROUGH */
1158                                 case STANDARD_DEFAULT:
1159                                 case STANDARD_GNU99:   c_mode = _C89 | _C99 | _GNUC; break;
1160
1161                                 case STANDARD_CXX98:   invalid_mode = "c++98"; goto default_c_warn;
1162                                 case STANDARD_GNUXX98: invalid_mode = "gnu98"; goto default_c_warn;
1163                         }
1164                         goto do_parsing;
1165                 } else if (filetype == FILETYPE_PREPROCESSED_CXX) {
1166                         char const* invalid_mode;
1167                         switch (standard) {
1168                                 case STANDARD_C89:   invalid_mode = "c89";   goto default_cxx_warn;
1169                                 case STANDARD_C90:   invalid_mode = "c90";   goto default_cxx_warn;
1170                                 case STANDARD_C99:   invalid_mode = "c99";   goto default_cxx_warn;
1171                                 case STANDARD_GNU89: invalid_mode = "gnu89"; goto default_cxx_warn;
1172                                 case STANDARD_GNU99: invalid_mode = "gnu99"; goto default_cxx_warn;
1173
1174                                 case STANDARD_ANSI:
1175                                 case STANDARD_CXX98: c_mode = _CXX; break;
1176
1177 default_cxx_warn:
1178                                         fprintf(stderr,
1179                                                         "warning: command line option \"-std=%s\" is not valid for C++\n",
1180                                                         invalid_mode);
1181                                 case STANDARD_DEFAULT:
1182                                 case STANDARD_GNUXX98: c_mode = _CXX | _GNUC; break;
1183                         }
1184
1185 do_parsing:
1186                         c_mode |= features_on;
1187                         c_mode &= ~features_off;
1188                         init_tokens();
1189                         translation_unit_t *const unit = do_parsing(in, filename);
1190
1191                         /* prints the AST even if errors occurred */
1192                         if (mode == PrintAst) {
1193                                 type_set_output(out);
1194                                 ast_set_output(out);
1195                                 print_ast(unit);
1196                         }
1197
1198                         if(error_count > 0) {
1199                                 /* parsing failed because of errors */
1200                                 fprintf(stderr, "%u error(s), %u warning(s)\n", error_count,
1201                                         warning_count);
1202                                 result = EXIT_FAILURE;
1203                                 continue;
1204                         } else if(warning_count > 0) {
1205                                 fprintf(stderr, "%u warning(s)\n", warning_count);
1206                         }
1207
1208                         if (in == preprocessed_in) {
1209                                 int pp_result = pclose(preprocessed_in);
1210                                 if (pp_result != EXIT_SUCCESS) {
1211                                         exit(EXIT_FAILURE);
1212                                 }
1213                         }
1214
1215                         if(mode == BenchmarkParser) {
1216                                 return result;
1217                         } else if(mode == PrintFluffy) {
1218                                 write_fluffy_decls(out, unit);
1219                                 continue;
1220                         } else if (mode == PrintCaml) {
1221                                 write_caml_decls(out, unit);
1222                                 continue;
1223                         }
1224
1225                         translation_unit_to_firm(unit);
1226
1227                         if (mode == ParseOnly) {
1228                                 continue;
1229                         }
1230
1231                         if (mode == CompileDump) {
1232                                 /* find irg */
1233                                 ident    *id     = new_id_from_str(dumpfunction);
1234                                 ir_graph *irg    = NULL;
1235                                 int       n_irgs = get_irp_n_irgs();
1236                                 for(int i = 0; i < n_irgs; ++i) {
1237                                         ir_graph *tirg   = get_irp_irg(i);
1238                                         ident    *irg_id = get_entity_ident(get_irg_entity(tirg));
1239                                         if(irg_id == id) {
1240                                                 irg = tirg;
1241                                                 break;
1242                                         }
1243                                 }
1244
1245                                 if(irg == NULL) {
1246                                         fprintf(stderr, "No graph for function '%s' found\n",
1247                                                 dumpfunction);
1248                                         exit(1);
1249                                 }
1250
1251                                 dump_ir_block_graph_file(irg, out);
1252                                 fclose(out);
1253                                 exit(0);
1254                         }
1255
1256                         gen_firm_finish(asm_out, filename, /*c_mode=*/1,
1257                                         have_const_functions);
1258                         if (asm_out != out) {
1259                                 fclose(asm_out);
1260                         }
1261                 } else if (filetype == FILETYPE_PREPROCESSED_ASSEMBLER) {
1262                         copy_file(asm_out, in);
1263                         if (in == preprocessed_in) {
1264                                 int pp_result = pclose(preprocessed_in);
1265                                 if (pp_result != EXIT_SUCCESS) {
1266                                         return pp_result;
1267                                 }
1268                         }
1269                         if(asm_out != out) {
1270                                 fclose(asm_out);
1271                         }
1272                 }
1273
1274                 if (mode == Compile)
1275                         continue;
1276
1277                 /* if we're here then we have preprocessed assembly */
1278                 filename = asm_tempfile;
1279                 filetype = FILETYPE_PREPROCESSED_ASSEMBLER;
1280
1281                 /* assemble */
1282                 if (filetype == FILETYPE_PREPROCESSED_ASSEMBLER) {
1283                         char        temp[1024];
1284                         const char *filename_o;
1285                         if(mode == CompileAssemble) {
1286                                 fclose(out);
1287                                 filename_o = outname;
1288                         } else {
1289                                 FILE *tempf = make_temp_file(temp, sizeof(temp), "cco");
1290                                 fclose(tempf);
1291                                 filename_o = temp;
1292                         }
1293
1294                         assemble(filename_o, filename);
1295
1296                         size_t len = strlen(filename_o) + 1;
1297                         filename = obstack_copy(&file_obst, filename_o, len);
1298                         filetype = FILETYPE_OBJECT;
1299                 }
1300
1301                 /* ok we're done here, process next file */
1302                 file->name = filename;
1303                 file->type = filetype;
1304         }
1305
1306         if (result != EXIT_SUCCESS)
1307                 return result;
1308
1309         /* link program file */
1310         if(mode == CompileAssembleLink) {
1311                 obstack_1grow(&ldflags_obst, '\0');
1312                 const char *flags = obstack_finish(&ldflags_obst);
1313
1314                 /* construct commandline */
1315                 obstack_printf(&file_obst, "%s", LINKER);
1316                 for (file_list_entry_t *entry = files; entry != NULL;
1317                                 entry = entry->next) {
1318                         if (entry->type != FILETYPE_OBJECT)
1319                                 continue;
1320
1321                         add_flag(&file_obst, "%s", entry->name);
1322                 }
1323
1324                 add_flag(&file_obst, "-o");
1325                 add_flag(&file_obst, outname);
1326                 obstack_printf(&file_obst, "%s", flags);
1327                 obstack_1grow(&file_obst, '\0');
1328
1329                 char *commandline = obstack_finish(&file_obst);
1330
1331                 if(verbose) {
1332                         puts(commandline);
1333                 }
1334                 int err = system(commandline);
1335                 if(err != EXIT_SUCCESS) {
1336                         fprintf(stderr, "linker reported an error\n");
1337                         exit(1);
1338                 }
1339         }
1340
1341         obstack_free(&cppflags_obst, NULL);
1342         obstack_free(&ldflags_obst, NULL);
1343         obstack_free(&file_obst, NULL);
1344
1345         exit_ast2firm();
1346         exit_parser();
1347         exit_ast();
1348         exit_lexer();
1349         exit_typehash();
1350         exit_types();
1351         exit_tokens();
1352         exit_symbol_table();
1353         return 0;
1354 }