crude -g implementation
[cparser] / main.c
1 #include <config.h>
2
3 #define _GNU_SOURCE
4
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdbool.h>
8 #include <errno.h>
9 #include <string.h>
10 #include <assert.h>
11
12 #ifdef _WIN32
13
14 #include <fcntl.h>
15 #include <io.h>
16
17 /* no eXecute on Win32 */
18 #define X_OK 0
19 #define W_OK 2
20 #define R_OK 4
21
22 #define O_RDWR          _O_RDWR
23 #define O_CREAT         _O_CREAT
24 #define O_EXCL          _O_EXCL
25 #define O_BINARY        _O_BINARY
26
27 /* remap some names, we are not in the POSIX world */
28 #define access(fname, mode)      _access(fname, mode)
29 #define mktemp(tmpl)             _mktemp(tmpl)
30 #define open(fname, oflag, mode) _open(fname, oflag, mode)
31 #define fdopen(fd, mode)         _fdopen(fd, mode)
32 #define popen(cmd, mode)         _popen(cmd, mode)
33 #define pclose(file)             _pclose(file)
34
35 #else
36 #include <unistd.h>
37 #define HAVE_MKSTEMP
38 #endif
39
40 #ifndef WITH_LIBCORE
41 #define WITH_LIBCORE
42 #endif
43
44 #include <libfirm/firm.h>
45 #include <libfirm/be.h>
46
47 #include "lexer.h"
48 #include "token_t.h"
49 #include "types.h"
50 #include "type_hash.h"
51 #include "parser.h"
52 #include "ast2firm.h"
53 #include "diagnostic.h"
54 #include "lang_features.h"
55 #include "driver/firm_opt.h"
56 #include "driver/firm_cmdline.h"
57 #include "adt/error.h"
58 #include "write_fluffy.h"
59 #include "revision.h"
60 #include "warning.h"
61
62 #ifndef PREPROCESSOR
63 #define PREPROCESSOR "cpp -std=c99 -U__WCHAR_TYPE__ -D__WCHAR_TYPE__=int"
64 #endif
65
66 #ifndef LINKER
67 #define LINKER    "gcc -m32"
68 #endif
69
70 #ifndef ASSEMBLER
71 #define ASSEMBLER "as --32"
72 #endif
73
74 /** The current c mode/dialect. */
75 unsigned int c_mode = _C89|_C99|_GNUC;
76
77 /** The 'machine size', 16, 32 or 64 bit, 32bit is the default. */
78 unsigned int machine_size = 32;
79
80 /** true if the char type is signed. */
81 bool char_is_signed = true;
82
83 /** true for strict language checking. */
84 bool strict_mode = false;
85
86 /* to switch on printing of implicit casts */
87 extern bool print_implicit_casts;
88
89 /* to switch on printing of  srenthesis to indicate operator precedence */
90 extern bool print_parenthesis;
91
92 static int            verbose;
93 static struct obstack cppflags_obst, ldflags_obst;
94
95 #if defined(_DEBUG) || defined(FIRM_DEBUG)
96 /**
97  * Debug printf implementation.
98  *
99  * @param fmt  printf style format parameter
100  */
101 void dbg_printf(const char *fmt, ...)
102 {
103         va_list list;
104
105         if (firm_dump.debug_print) {
106                 va_start(list, fmt);
107                 vprintf(fmt, list);
108                 va_end(list);
109         }  /* if */
110 }
111 #endif /* defined(_DEBUG) || defined(FIRM_DEBUG) */
112
113 static void initialize_firm(void)
114 {
115         firm_early_init();
116
117         dump_consts_local(1);
118         dump_keepalive_edges(1);
119 }
120
121 static void get_output_name(char *buf, size_t buflen, const char *inputname,
122                             const char *newext)
123 {
124         size_t last_dot = 0xffffffff;
125         size_t i = 0;
126
127         if(inputname == NULL) {
128                 snprintf(buf, buflen, "a%s", newext);
129                 return;
130         }
131
132         for(const char *c = inputname; *c != 0; ++c) {
133                 if(*c == '.')
134                         last_dot = i;
135                 ++i;
136         }
137         if(last_dot == 0xffffffff)
138                 last_dot = i;
139
140         if(last_dot >= buflen)
141                 panic("filename too long");
142         memcpy(buf, inputname, last_dot);
143
144         size_t extlen = strlen(newext) + 1;
145         if(extlen + last_dot >= buflen)
146                 panic("filename too long");
147         memcpy(buf+last_dot, newext, extlen);
148 }
149
150 static translation_unit_t *do_parsing(FILE *const in, const char *const input)
151 {
152         lexer_open_stream(in, input);
153         translation_unit_t *unit = parse();
154         return unit;
155 }
156
157 static void lextest(FILE *in, const char *fname)
158 {
159         lexer_open_stream(in, fname);
160
161         do {
162                 lexer_next_preprocessing_token();
163                 print_token(stdout, &lexer_token);
164                 puts("");
165         } while(lexer_token.type != T_EOF);
166 }
167
168 static FILE* preprocess(FILE* in, const char *fname)
169 {
170         char buf[4096];
171         obstack_1grow(&cppflags_obst, '\0');
172         const char *flags = obstack_finish(&cppflags_obst);
173
174         if(in != stdin) {
175                 snprintf(buf, sizeof(buf), PREPROCESSOR " %s %s", flags, fname);
176         } else {
177                 /* read from stdin */
178                 snprintf(buf, sizeof(buf), PREPROCESSOR " %s -", flags);
179         }
180
181         if(verbose) {
182                 puts(buf);
183         }
184         FILE* f = popen(buf, "r");
185         if (f == NULL) {
186                 fprintf(stderr, "invoking preprocessor failed\n");
187                 exit(1);
188         }
189         return f;
190 }
191
192 static void do_link(const char *out, const char *in)
193 {
194         char buf[4096];
195         obstack_1grow(&ldflags_obst, '\0');
196         const char *flags = obstack_finish(&ldflags_obst);
197
198         snprintf(buf, sizeof(buf), LINKER " %s -o %s %s", flags, out, in);
199         if(verbose) {
200                 puts(buf);
201         }
202         int err = system(buf);
203         if(err != 0) {
204                 fprintf(stderr, "linker reported an error\n");
205                 exit(1);
206         }
207 }
208
209 static void assemble(const char *out, const char *in)
210 {
211         char buf[4096];
212
213         snprintf(buf, sizeof(buf), "%s %s -o %s", ASSEMBLER, in, out);
214         if(verbose) {
215                 puts(buf);
216         }
217
218         int err = system(buf);
219         if(err != 0) {
220                 fprintf(stderr, "assembler reported an error\n");
221                 exit(1);
222         }
223 }
224
225 static const char *try_dir(const char *dir)
226 {
227         if(dir == NULL)
228                 return dir;
229         if(access(dir, R_OK | W_OK | X_OK) == 0)
230                 return dir;
231         return NULL;
232 }
233
234 static const char *get_tempdir(void)
235 {
236         static const char *tmpdir = NULL;
237
238         if(tmpdir != NULL)
239                 return tmpdir;
240
241         if(tmpdir == NULL)
242                 tmpdir = try_dir(getenv("TMPDIR"));
243         if(tmpdir == NULL)
244                 tmpdir = try_dir(getenv("TMP"));
245         if(tmpdir == NULL)
246                 tmpdir = try_dir(getenv("TEMP"));
247
248 #ifdef P_tmpdir
249         if(tmpdir == NULL)
250                 tmpdir = try_dir(P_tmpdir);
251 #endif
252
253         if(tmpdir == NULL)
254                 tmpdir = try_dir("/var/tmp");
255         if(tmpdir == NULL)
256                 tmpdir = try_dir("/usr/tmp");
257         if(tmpdir == NULL)
258                 tmpdir = try_dir("/tmp");
259
260         if(tmpdir == NULL)
261                 tmpdir = ".";
262
263         return tmpdir;
264 }
265
266 #ifndef HAVE_MKSTEMP
267 /* cheap and nasty mkstemp replacement */
268 static int mkstemp(char *templ)
269 {
270         mktemp(templ);
271         return open(templ, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600);
272 }
273 #endif
274
275 /**
276  * an own version of tmpnam, which: writes in a buffer, appends a user specified
277  * suffix, emits no warnings during linking (like glibc/gnu ld do for tmpnam)...
278  */
279 static FILE *make_temp_file(char *buffer, size_t buflen,
280                             const char *prefix, const char *suffix)
281 {
282         const char *tempdir = get_tempdir();
283
284         /* oh well... mkstemp doesn't accept a suffix after XXXXXX... */
285         (void) suffix;
286         suffix = "";
287
288         snprintf(buffer, buflen, "%s/%sXXXXXX%s", tempdir, prefix, suffix);
289
290         int fd = mkstemp(buffer);
291         if(fd == -1) {
292                 fprintf(stderr, "couldn't create temporary file: %s\n",
293                         strerror(errno));
294                 exit(1);
295         }
296         FILE *out = fdopen(fd, "w");
297         if(out == NULL) {
298                 fprintf(stderr, "couldn't create temporary file FILE*\n");
299                 exit(1);
300         }
301
302         return out;
303 }
304
305 /**
306  * Do the necessary lowering for compound parameters.
307  */
308 void lower_compound_params(void)
309 {
310         lower_params_t params;
311
312         params.def_ptr_alignment    = 4;
313         params.flags                = LF_COMPOUND_RETURN | LF_RETURN_HIDDEN;
314         params.hidden_params        = ADD_HIDDEN_ALWAYS_IN_FRONT;
315         params.find_pointer_type    = NULL;
316         params.ret_compound_in_regs = NULL;
317         lower_calls_with_compounds(&params);
318 }
319
320 typedef enum compile_mode_t {
321         BenchmarkParser,
322         ParseOnly,
323         Compile,
324         CompileDump,
325         CompileAssemble,
326         CompileAssembleLink,
327         LexTest,
328         PrintAst,
329         PrintFluffy
330 } compile_mode_t;
331
332 static void usage(const char *argv0)
333 {
334         fprintf(stderr, "Usage %s input [-o output] [-c]\n", argv0);
335 }
336
337 int main(int argc, char **argv)
338 {
339         initialize_firm();
340
341         const char     *input        = NULL;
342         const char     *outname      = NULL;
343         const char     *dumpfunction = NULL;
344         compile_mode_t  mode         = CompileAssembleLink;
345         int             opt_level    = 1;
346
347         obstack_init(&cppflags_obst);
348         obstack_init(&ldflags_obst);
349
350 #define GET_ARG_AFTER(def, args)                                             \
351         def = &arg[sizeof(args)-1];                                              \
352         if(def[0] == '\0') {                                                     \
353                 ++i;                                                                 \
354                 if(i >= argc) {                                                      \
355                         fprintf(stderr, "error: expected argument after '" args "'\n");  \
356                         argument_errors = true;                                          \
357                         break;                                                           \
358                 }                                                                    \
359                 def = argv[i];                                                       \
360                 if(def[0] == '-' && def[1] != '\0') {                                \
361                         fprintf(stderr, "error: expected argument after '" args "'\n");  \
362                         argument_errors = true;                                          \
363                         continue;                                                        \
364                 }                                                                    \
365         }
366
367 #define SINGLE_OPTION(ch) (option[0] == (ch) && option[1] == '\0')
368
369         /* early options parsing (find out optimisation level) */
370         for(int i = 1; i < argc; ++i) {
371                 const char *arg = argv[i];
372                 if(arg[0] != '-')
373                         continue;
374
375                 const char *option = &arg[1];
376                 if(option[0] == 'O') {
377                         sscanf(&option[1], "%d", &opt_level);
378                 }
379         }
380
381         /* apply optimisation level */
382         switch(opt_level) {
383         case 0:
384                 firm_option("no-opt");
385                 break;
386         case 1:
387                 firm_option("no-inline");
388                 break;
389         default:
390         case 4:
391                 firm_option("strict-aliasing");
392                 /* fallthrough */
393         case 3:
394                 firm_option("cond-eval");
395                 firm_option("if-conv");
396                 /* fallthrough */
397         case 2:
398                 firm_option("inline");
399                 firm_option("no-strength-red");
400                 firm_option("deconv");
401                 firm_be_option("omitfp");
402                 break;
403         }
404
405         /* parse rest of options */
406         bool help_displayed  = false;
407         bool argument_errors = false;
408         for(int i = 1; i < argc; ++i) {
409                 const char *arg = argv[i];
410                 if(arg[0] == '-') {
411                         /* an option */
412                         const char *option = &arg[1];
413                         if(option[0] == 'o') {
414                                 GET_ARG_AFTER(outname, "-o");
415                         } else if(option[0] == 'g') {
416                                 firm_be_option("stabs=yes");
417                         } else if(SINGLE_OPTION('c')) {
418                                 mode = CompileAssemble;
419                         } else if(SINGLE_OPTION('S')) {
420                                 mode = Compile;
421                         } else if(option[0] == 'O') {
422                                 continue;
423                         } else if(option[0] == 'I') {
424                                 const char *opt;
425                                 GET_ARG_AFTER(opt, "-I");
426                                 obstack_printf(&cppflags_obst, " -I%s", opt);
427                         } else if(option[0] == 'D') {
428                                 const char *opt;
429                                 GET_ARG_AFTER(opt, "-D");
430                                 obstack_printf(&cppflags_obst, " -D%s", opt);
431                         } else if(option[0] == 'U') {
432                                 const char *opt;
433                                 GET_ARG_AFTER(opt, "-U");
434                                 obstack_printf(&cppflags_obst, " -U%s", opt);
435                         } else if(option[0] == 'l') {
436                                 const char *opt;
437                                 GET_ARG_AFTER(opt, "-l");
438                                 obstack_printf(&ldflags_obst, " -l%s", opt);
439                         } else if(option[0] == 'L') {
440                                 const char *opt;
441                                 GET_ARG_AFTER(opt, "-L");
442                                 obstack_printf(&ldflags_obst, " -L%s", opt);
443                         } else if(SINGLE_OPTION('v')) {
444                                 verbose = 1;
445                         } else if(SINGLE_OPTION('w')) {
446                                 inhibit_all_warnings = true;
447                         } else if(option[0] == 'f') {
448                                 const char *opt;
449                                 GET_ARG_AFTER(opt, "-f");
450
451                                 if(strcmp(opt, "syntax-only") == 0) {
452                                         mode = ParseOnly;
453                                 } else if(strcmp(opt, "omit-frame-pointer") == 0) {
454                                         firm_be_option("omitfp");
455                                 } else if(strcmp(opt, "no-omit-frame-pointer") == 0) {
456                                         firm_be_option("omitfp=no");
457                                 } else {
458                                         int res = firm_option(opt);
459                                         if (res == 0) {
460                                                 fprintf(stderr, "error: unknown Firm option '-f %s'\n",
461                                                         opt);
462                                                 argument_errors = true;
463                                                 continue;
464                                         } else if (res == -1) {
465                                                 help_displayed = true;
466                                         }
467                                 }
468                         } else if(option[0] == 'b') {
469                                 const char *opt;
470                                 GET_ARG_AFTER(opt, "-b");
471                                 int res = firm_be_option(opt);
472                                 if (res == 0) {
473                                         fprintf(stderr, "error: unknown Firm backend option '-b %s'\n",
474                                                 opt);
475                                         argument_errors = true;
476                                 } else if (res == -1) {
477                                         help_displayed = true;
478                                 }
479                         } else if(option[0] == 'W') {
480                                 set_warning_opt(&option[1]);
481                         } else if(option[0] == 'm') {
482                                 const char *opt;
483                                 GET_ARG_AFTER(opt, "-m");
484                                 char *endptr;
485                                 long int value = strtol(opt, &endptr, 10);
486                                 if (*endptr != '\0') {
487                                         fprintf(stderr, "error: wrong option '-m %s'\n",  opt);
488                                         argument_errors = true;
489                                 }
490                                 if (value != 16 && value != 32 && value != 64) {
491                                         fprintf(stderr, "error: option -m supports only 16, 32 or 64\n");
492                                         argument_errors = true;
493                                 } else {
494                                         machine_size = (unsigned int)value;
495                                 }
496                         } else if (option[0] == '\0') {
497                                 if(input != NULL) {
498                                         fprintf(stderr, "error: multiple input files specified\n");
499                                         argument_errors = true;
500                                 } else {
501                                         input = arg;
502                                 }
503                         } else if(strcmp(option, "pedantic") == 0) {
504                                 fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);
505                         } else if(strncmp(option, "std=", 4) == 0) {
506                                 fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);
507                         } else if (option[0] == '-') {
508                                 /* double dash option */
509                                 ++option;
510                                 if(strcmp(option, "gcc") == 0) {
511                                         c_mode |= _GNUC;
512                                 } else if(strcmp(option, "no-gcc") == 0) {
513                                         c_mode &= ~_GNUC;
514                                 } else if(strcmp(option, "ms") == 0) {
515                                         c_mode |= _MS;
516                                 } else if(strcmp(option, "no-ms") == 0) {
517                                         c_mode &= ~_MS;
518                                 } else if(strcmp(option, "signed-chars") == 0) {
519                                         char_is_signed = true;
520                                 } else if(strcmp(option, "unsigned-chars") == 0) {
521                                         char_is_signed = false;
522                                 } else if(strcmp(option, "strict") == 0) {
523                                         strict_mode = true;
524                                 } else if(strcmp(option, "lextest") == 0) {
525                                         mode = LexTest;
526                                 } else if(strcmp(option, "benchmark") == 0) {
527                                         mode = BenchmarkParser;
528                                 } else if(strcmp(option, "print-ast") == 0) {
529                                         mode = PrintAst;
530                                 } else if(strcmp(option, "print-implicit-cast") == 0) {
531                                         print_implicit_casts = true;
532                                 } else if(strcmp(option, "print-parenthesis") == 0) {
533                                         print_parenthesis = true;
534                                 } else if(strcmp(option, "print-fluffy") == 0) {
535                                         mode = PrintFluffy;
536                                 } else if(strcmp(option, "version") == 0) {
537                                         firm_version_t ver;
538                                         firm_get_version(&ver);
539                                         printf("cparser (%d.%d %s) using libFirm (%u.%u", 0, 1, cparser_REVISION, ver.major, ver.minor);
540                                         if(ver.revision[0] != 0) {
541                                                 putchar(' ');
542                                                 fputs(ver.revision, stdout);
543                                         }
544                                         if(ver.build[0] != 0) {
545                                                 putchar(' ');
546                                                 fputs(ver.build, stdout);
547                                         }
548                                         puts(")\n");
549                                         exit(EXIT_SUCCESS);
550                                 } else if(strcmp(option, "dump-function") == 0) {
551                                         ++i;
552                                         if(i >= argc) {
553                                                 fprintf(stderr, "error: "
554                                                         "expected argument after '--dump-function'\n");
555                                                 argument_errors = true;
556                                                 break;
557                                         }
558                                         dumpfunction = argv[i];
559                                         mode         = CompileDump;
560                                 } else {
561                                         fprintf(stderr, "error: unknown argument '%s'\n", arg);
562                                         argument_errors = true;
563                                 }
564                         } else {
565                                 fprintf(stderr, "error: unknown argument '%s'\n", arg);
566                                 argument_errors = true;
567                         }
568                 } else {
569                         if(input != NULL) {
570                                 fprintf(stderr, "error: multiple input files specified\n");
571                                 argument_errors = true;
572                         } else {
573                                 input = arg;
574                         }
575                 }
576         }
577
578         /* we do the lowering in ast2firm */
579         firm_opt.lower_bitfields = FALSE;
580
581         if(help_displayed) {
582                 return !argument_errors;
583         }
584         if(argument_errors) {
585                 usage(argv[0]);
586                 return 1;
587         }
588
589         gen_firm_init();
590         init_symbol_table();
591         init_tokens();
592         init_types();
593         init_typehash();
594         init_basic_types();
595         init_lexer();
596         init_ast();
597         init_parser();
598         init_ast2firm();
599
600         FILE *out = NULL;
601         char  outnamebuf[4096];
602         if(outname == NULL) {
603                 switch(mode) {
604                 case BenchmarkParser:
605                 case PrintAst:
606                 case PrintFluffy:
607                 case LexTest:
608                         if(outname == NULL)
609                                 outname = "-";
610                         break;
611                 case ParseOnly:
612                         break;
613                 case Compile:
614                         get_output_name(outnamebuf, sizeof(outnamebuf), input, ".s");
615                         outname = outnamebuf;
616                         break;
617                 case CompileAssemble:
618                         get_output_name(outnamebuf, sizeof(outnamebuf), input, ".o");
619                         outname = outnamebuf;
620                         break;
621                 case CompileDump:
622                         get_output_name(outnamebuf, sizeof(outnamebuf), dumpfunction,
623                                         ".vcg");
624                         outname = outnamebuf;
625                         break;
626                 case CompileAssembleLink:
627                         outname = "a.out";
628                         break;
629                 }
630         }
631
632         if(outname != NULL) {
633                 if(strcmp(outname, "-") == 0) {
634                         out = stdout;
635                 } else {
636                         out = fopen(outname, "w");
637                         if(out == NULL) {
638                                 fprintf(stderr, "Couldn't open '%s' for writing: %s\n", outname,
639                                         strerror(errno));
640                                 return 1;
641                         }
642                 }
643         }
644
645         FILE *in;
646         if(input == NULL) {
647                 fprintf(stderr, "%s: no input files\n", argv[0]);
648                 return 1;
649         } else if(strcmp(input, "-") == 0) {
650                 in    = stdin;
651                 input = "<stdin>";
652         } else {
653                 in = fopen(input, "r");
654                 if(in == NULL) {
655                         fprintf(stderr, "Couldn't open '%s': %s\n", input, strerror(errno));
656                         return 1;
657                 }
658         }
659
660         if(mode == LexTest) {
661                 lextest(in, input);
662                 fclose(in);
663                 return 0;
664         }
665
666         FILE *preprocessed_in = preprocess(in, input);
667         translation_unit_t *const unit = do_parsing(preprocessed_in, input);
668         int result = pclose(preprocessed_in);
669         if(result != 0) {
670                 return result;
671         }
672         if(unit == NULL) {
673                 /* parsing failed because of errors */
674                 fprintf(stderr, "%u error(s), %u warning(s)\n", error_count, warning_count);
675                 return EXIT_FAILURE;
676         }
677         if (warning_count > 0) {
678                 fprintf(stderr, "%u warning(s)\n", warning_count);
679         }
680
681         if(mode == BenchmarkParser) {
682                 return 0;
683         }
684
685         if(mode == PrintAst) {
686                 type_set_output(out);
687                 ast_set_output(out);
688                 print_ast(unit);
689                 return 0;
690         }
691         if(mode == PrintFluffy) {
692                 type_set_output(out);
693                 ast_set_output(out);
694                 write_fluffy_decls(out, unit);
695         }
696
697         translation_unit_to_firm(unit);
698
699         if(mode == ParseOnly) {
700                 return 0;
701         }
702
703         FILE *asm_out;
704         char  asm_tempfile[1024];
705         if(mode == CompileDump) {
706                 asm_out = NULL;
707                 firm_be_opt.selection = BE_NONE;
708         } else if(mode == Compile) {
709                 asm_out = out;
710         } else {
711                 asm_out
712                         = make_temp_file(asm_tempfile, sizeof(asm_tempfile), "cc", ".s");
713         }
714         gen_firm_finish(asm_out, input, /*c_mode=*/1, /*firm_const_exists=*/0);
715
716         if(mode == CompileDump) {
717                 /* find irg */
718                 ident    *id     = new_id_from_str(dumpfunction);
719                 ir_graph *irg    = NULL;
720                 int       n_irgs = get_irp_n_irgs();
721                 for(int i = 0; i < n_irgs; ++i) {
722                         ir_graph *tirg   = get_irp_irg(i);
723                         ident    *irg_id = get_entity_ident(get_irg_entity(tirg));
724                         if(irg_id == id) {
725                                 irg = tirg;
726                                 break;
727                         }
728                 }
729
730                 if(irg == NULL) {
731                         fprintf(stderr, "No graph for function '%s' found\n", dumpfunction);
732                         return 1;
733                 }
734
735                 dump_ir_block_graph_file(irg, out);
736                 fclose(out);
737                 return 0;
738         }
739
740         fclose(asm_out);
741
742         /* assemble assembler and create object file */
743         char obj_tfile[1024];
744         if(mode == CompileAssemble || mode == CompileAssembleLink) {
745                 const char *obj_outfile;
746                 if(mode == CompileAssemble) {
747                         fclose(out);
748                         obj_outfile = outname;
749                 } else {
750                         FILE *tempf
751                                 = make_temp_file(obj_tfile, sizeof(obj_tfile), "cc", ".o");
752                         fclose(tempf);
753                         obj_outfile = obj_tfile;
754                 }
755
756                 assemble(obj_outfile, asm_tempfile);
757         }
758
759         /* link object file */
760         if(mode == CompileAssembleLink) {
761                 do_link(outname, obj_tfile);
762         }
763
764         obstack_free(&cppflags_obst, NULL);
765         obstack_free(&ldflags_obst, NULL);
766
767         exit_ast2firm();
768         exit_parser();
769         exit_ast();
770         exit_lexer();
771         exit_typehash();
772         exit_types();
773         exit_tokens();
774         exit_symbol_table();
775         return 0;
776 }