2 * This file is part of cparser.
3 * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
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.
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.
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
36 /* no eXecute on Win32 */
41 #define O_RDWR _O_RDWR
42 #define O_CREAT _O_CREAT
43 #define O_EXCL _O_EXCL
44 #define O_BINARY _O_BINARY
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)
63 #include <libfirm/firm.h>
64 #include <libfirm/be.h>
69 #include "type_hash.h"
72 #include "diagnostic.h"
73 #include "lang_features.h"
74 #include "driver/firm_opt.h"
75 #include "driver/firm_cmdline.h"
76 #include "adt/error.h"
77 #include "write_fluffy.h"
78 #include "write_caml.h"
83 #define PREPROCESSOR "cpp -std=c99 -U__WCHAR_TYPE__ -D__WCHAR_TYPE__=int -U__SIZE_TYPE__ -D__SIZE_TYPE__=__SIZE_TYPE__ -m32"
87 #define LINKER "gcc -m32"
91 #define ASSEMBLER "as --32"
94 /** The current c mode/dialect. */
95 unsigned int c_mode = _C89|_C99|_GNUC;
97 /** The 'machine size', 16, 32 or 64 bit, 32bit is the default. */
98 unsigned int machine_size = 32;
100 /** true if the char type is signed. */
101 bool char_is_signed = true;
103 /** true for strict language checking. */
104 bool strict_mode = false;
106 /** use builtins for some libc functions */
107 bool use_builtins = false;
109 /* to switch on printing of implicit casts */
110 extern bool print_implicit_casts;
112 /* to switch on printing of parenthesis to indicate operator precedence */
113 extern bool print_parenthesis;
116 static struct obstack cppflags_obst, ldflags_obst;
118 typedef struct file_list_entry_t file_list_entry_t;
120 struct file_list_entry_t {
121 const char *filename;
122 file_list_entry_t *next;
125 #if defined(_DEBUG) || defined(FIRM_DEBUG)
127 * Debug printf implementation.
129 * @param fmt printf style format parameter
131 void dbg_printf(const char *fmt, ...)
135 if (firm_dump.debug_print) {
141 #endif /* defined(_DEBUG) || defined(FIRM_DEBUG) */
143 static void initialize_firm(void)
147 dump_consts_local(1);
148 dump_keepalive_edges(1);
151 static void get_output_name(char *buf, size_t buflen, const char *inputname,
154 size_t last_dot = 0xffffffff;
157 if(inputname == NULL) {
158 snprintf(buf, buflen, "a%s", newext);
162 for(const char *c = inputname; *c != 0; ++c) {
167 if(last_dot == 0xffffffff)
170 if(last_dot >= buflen)
171 panic("filename too long");
172 memcpy(buf, inputname, last_dot);
174 size_t extlen = strlen(newext) + 1;
175 if(extlen + last_dot >= buflen)
176 panic("filename too long");
177 memcpy(buf+last_dot, newext, extlen);
180 #include "builtins.h"
182 static translation_unit_t *do_parsing(FILE *const in, const char *const input_name)
187 lexer_open_buffer(builtins, sizeof(builtins)-1, "<builtin>");
191 lexer_open_stream(in, input_name);
194 translation_unit_t *unit = finish_parsing();
198 static void lextest(FILE *in, const char *fname)
200 lexer_open_stream(in, fname);
203 lexer_next_preprocessing_token();
204 print_token(stdout, &lexer_token);
206 } while(lexer_token.type != T_EOF);
209 static void add_flag(struct obstack *obst, const char *format, ...)
212 va_start(ap, format);
215 vsnprintf(buf, sizeof(buf), format, ap);
217 /* escape stuff... */
218 obstack_1grow(obst, ' ');
219 for (char *c = buf; *c != '\0'; ++c) {
232 obstack_1grow(obst, '\\');
235 obstack_1grow(obst, *c);
243 static FILE *preprocess(FILE *in, const char *fname)
246 obstack_1grow(&cppflags_obst, '\0');
247 const char *flags = obstack_finish(&cppflags_obst);
250 snprintf(buf, sizeof(buf), PREPROCESSOR " %s %s", flags, fname);
252 /* read from stdin */
253 snprintf(buf, sizeof(buf), PREPROCESSOR " %s -", flags);
260 FILE *f = popen(buf, "r");
262 fprintf(stderr, "invoking preprocessor failed\n");
268 static void do_link(const char *out, const char *in)
271 obstack_1grow(&ldflags_obst, '\0');
272 const char *flags = obstack_finish(&ldflags_obst);
274 snprintf(buf, sizeof(buf), LINKER " %s -o %s %s", flags, out, in);
278 int err = system(buf);
280 fprintf(stderr, "linker reported an error\n");
285 static void assemble(const char *out, const char *in)
289 snprintf(buf, sizeof(buf), "%s %s -o %s", ASSEMBLER, in, out);
294 int err = system(buf);
296 fprintf(stderr, "assembler reported an error\n");
301 static const char *try_dir(const char *dir)
305 if(access(dir, R_OK | W_OK | X_OK) == 0)
310 static const char *get_tempdir(void)
312 static const char *tmpdir = NULL;
318 tmpdir = try_dir(getenv("TMPDIR"));
320 tmpdir = try_dir(getenv("TMP"));
322 tmpdir = try_dir(getenv("TEMP"));
326 tmpdir = try_dir(P_tmpdir);
330 tmpdir = try_dir("/var/tmp");
332 tmpdir = try_dir("/usr/tmp");
334 tmpdir = try_dir("/tmp");
343 /* cheap and nasty mkstemp replacement */
344 static int mkstemp(char *templ)
347 return open(templ, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600);
352 * an own version of tmpnam, which: writes in a buffer, appends a user specified
353 * suffix, emits no warnings during linking (like glibc/gnu ld do for tmpnam)...
355 static FILE *make_temp_file(char *buffer, size_t buflen,
356 const char *prefix, const char *suffix)
358 const char *tempdir = get_tempdir();
360 /* oh well... mkstemp doesn't accept a suffix after XXXXXX... */
364 snprintf(buffer, buflen, "%s/%sXXXXXX%s", tempdir, prefix, suffix);
366 int fd = mkstemp(buffer);
368 fprintf(stderr, "couldn't create temporary file: %s\n",
372 FILE *out = fdopen(fd, "w");
374 fprintf(stderr, "couldn't create temporary file FILE*\n");
382 * Do the necessary lowering for compound parameters.
384 void lower_compound_params(void)
386 lower_params_t params;
388 params.def_ptr_alignment = 4;
389 params.flags = LF_COMPOUND_RETURN | LF_RETURN_HIDDEN;
390 params.hidden_params = ADD_HIDDEN_ALWAYS_IN_FRONT;
391 params.find_pointer_type = NULL;
392 params.ret_compound_in_regs = NULL;
393 lower_calls_with_compounds(¶ms);
396 typedef enum compile_mode_t {
410 AssemblePreprocessed,
413 static void usage(const char *argv0)
415 fprintf(stderr, "Usage %s input [-o output] [-c]\n", argv0);
418 static void print_cparser_version(void) {
420 firm_get_version(&ver);
422 printf("cparser (%s) using libFirm (%u.%u",
423 cparser_REVISION, ver.major, ver.minor);
424 if(ver.revision[0] != 0) {
426 fputs(ver.revision, stdout);
428 if(ver.build[0] != 0) {
430 fputs(ver.build, stdout);
435 static void set_be_option(const char *arg)
437 int res = firm_be_option(arg);
442 static void set_option(const char *arg)
444 int res = firm_option(arg);
449 static void copy_file(FILE *dest, FILE *input)
453 while (!feof(input) && !ferror(dest)) {
454 size_t read = fread(buf, 1, sizeof(buf), input);
455 if(fwrite(buf, 1, read, dest) != read) {
456 perror("couldn't write output");
461 int main(int argc, char **argv)
465 const char *input = NULL;
466 const char *outname = NULL;
467 const char *dumpfunction = NULL;
468 compile_mode_t mode = CompileAssembleLink;
470 int result = EXIT_SUCCESS;
471 char cpu_arch[16] = "ia32";
472 file_list_entry_t *c_files = NULL;
473 file_list_entry_t *s_files = NULL;
474 file_list_entry_t *o_files = NULL;
475 struct obstack file_obst;
477 obstack_init(&cppflags_obst);
478 obstack_init(&ldflags_obst);
479 obstack_init(&file_obst);
481 #define GET_ARG_AFTER(def, args) \
482 def = &arg[sizeof(args)-1]; \
483 if(def[0] == '\0') { \
486 fprintf(stderr, "error: expected argument after '" args "'\n"); \
487 argument_errors = true; \
491 if(def[0] == '-' && def[1] != '\0') { \
492 fprintf(stderr, "error: expected argument after '" args "'\n"); \
493 argument_errors = true; \
498 #define SINGLE_OPTION(ch) (option[0] == (ch) && option[1] == '\0')
500 /* early options parsing (find out optimisation level) */
501 for(int i = 1; i < argc; ++i) {
502 const char *arg = argv[i];
506 const char *option = &arg[1];
507 if(option[0] == 'O') {
508 sscanf(&option[1], "%d", &opt_level);
512 /* apply optimisation level */
515 set_option("no-opt");
518 set_option("no-inline");
522 set_option("strict-aliasing");
525 set_option("cond-eval");
526 set_option("if-conv");
530 set_option("inline");
531 set_option("deconv");
532 set_be_option("omitfp");
536 /* parse rest of options */
537 bool help_displayed = false;
538 bool argument_errors = false;
539 for(int i = 1; i < argc; ++i) {
540 const char *arg = argv[i];
541 if(arg[0] == '-' && arg[1] != 0) {
543 const char *option = &arg[1];
544 if(option[0] == 'o') {
545 GET_ARG_AFTER(outname, "-o");
546 } else if(option[0] == 'g') {
547 set_be_option("debuginfo=stabs");
548 set_be_option("omitfp=no");
549 set_be_option("ia32-nooptcc=yes");
550 } else if(SINGLE_OPTION('c')) {
551 mode = CompileAssemble;
552 } else if(SINGLE_OPTION('E')) {
553 mode = PreprocessOnly;
554 } else if(SINGLE_OPTION('S')) {
556 } else if(option[0] == 'O') {
558 } else if(option[0] == 'I') {
560 GET_ARG_AFTER(opt, "-I");
561 add_flag(&cppflags_obst, "-I%s", opt);
562 } else if(option[0] == 'D') {
564 GET_ARG_AFTER(opt, "-D");
565 add_flag(&cppflags_obst, "-D%s", opt);
566 } else if(option[0] == 'U') {
568 GET_ARG_AFTER(opt, "-U");
569 add_flag(&cppflags_obst, "-U%s", opt);
570 } else if(option[0] == 'l') {
572 GET_ARG_AFTER(opt, "-l");
573 add_flag(&ldflags_obst, "-l%s", opt);
574 } else if(option[0] == 'L') {
576 GET_ARG_AFTER(opt, "-L");
577 add_flag(&ldflags_obst, "-L%s", opt);
578 } else if(SINGLE_OPTION('v')) {
580 } else if(SINGLE_OPTION('w')) {
581 inhibit_all_warnings = true;
582 } else if(strcmp(option, "M") == 0) {
583 mode = PreprocessOnly;
584 add_flag(&cppflags_obst, "-M");
585 } else if(strcmp(option, "MMD") == 0
586 || strcmp(option, "MD") == 0
587 || strcmp(option, "MM") == 0) {
588 add_flag(&cppflags_obst, "-%s", option);
589 } else if(strcmp(option, "MT") == 0
590 || strcmp(option, "MQ") == 0
591 || strcmp(option, "MF") == 0) {
593 GET_ARG_AFTER(opt, "-MT");
594 add_flag(&cppflags_obst, "-%s", option);
595 add_flag(&cppflags_obst, "%s", opt);
596 } else if(strcmp(option, "pipe") == 0) {
597 /* here for gcc compatibility */
598 } else if(option[0] == 'f') {
600 GET_ARG_AFTER(opt, "-f");
602 if(strcmp(opt, "syntax-only") == 0) {
604 } else if(strcmp(opt, "omit-frame-pointer") == 0) {
605 set_be_option("omitfp");
606 } else if(strcmp(opt, "no-omit-frame-pointer") == 0) {
607 set_be_option("omitfp=no");
608 } else if(strcmp(opt, "strength-reduce") == 0) {
609 firm_option("strength-red");
610 } else if(strcmp(opt, "fast-math") == 0
611 || strcmp(opt, "unroll-loops") == 0
612 || strcmp(opt, "expensive-optimizations") == 0
613 || strcmp(opt, "no-common") == 0
614 || strncmp(opt, "align-loops=", sizeof("align-loops=")-1) == 0
615 || strncmp(opt, "align-jumps=", sizeof("align-jumps=")-1) == 0
616 || strncmp(opt, "align-functions=", sizeof("align-functions=")-1) == 0) {
617 fprintf(stderr, "ignoring gcc option '-f %s'\n", opt);
619 int res = firm_option(opt);
621 fprintf(stderr, "error: unknown Firm option '-f %s'\n",
623 argument_errors = true;
625 } else if (res == -1) {
626 help_displayed = true;
629 } else if(option[0] == 'b') {
631 GET_ARG_AFTER(opt, "-b");
632 int res = firm_be_option(opt);
634 fprintf(stderr, "error: unknown Firm backend option '-b %s'\n",
636 argument_errors = true;
637 } else if (res == -1) {
638 help_displayed = true;
640 if (strncmp(opt, "isa=", 4) == 0)
641 strncpy(cpu_arch, opt, sizeof(cpu_arch));
643 } else if(option[0] == 'W') {
644 set_warning_opt(&option[1]);
645 } else if(option[0] == 'm') {
650 GET_ARG_AFTER(opt, "-m");
651 if(strncmp(opt, "arch=", 5) == 0) {
652 GET_ARG_AFTER(opt, "-march=");
653 snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt);
654 int res = firm_be_option(arch_opt);
656 argument_errors = true;
658 snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt);
659 int res = firm_be_option(arch_opt);
661 argument_errors = true;
663 } else if(strncmp(opt, "tune=", 5) == 0) {
664 GET_ARG_AFTER(opt, "-mtune=");
665 snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt);
666 int res = firm_be_option(arch_opt);
668 argument_errors = true;
669 } else if(strncmp(opt, "cpu=", 4) == 0) {
670 GET_ARG_AFTER(opt, "-mcpu=");
671 snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt);
672 int res = firm_be_option(arch_opt);
674 argument_errors = true;
675 } else if(strncmp(opt, "fpmath=", 7) == 0) {
676 GET_ARG_AFTER(opt, "-mfpmath=");
677 if(strcmp(opt, "387") == 0)
679 else if(strcmp(opt, "sse") == 0)
682 fprintf(stderr, "error: option -mfpumath supports only 387 or sse\n");
683 argument_errors = true;
685 if(!argument_errors) {
686 snprintf(arch_opt, sizeof(arch_opt), "%s-fpunit=%s", cpu_arch, opt);
687 int res = firm_be_option(arch_opt);
689 argument_errors = true;
691 } else if(strncmp(opt, "preferred-stack-boundary=", 25) == 0) {
692 GET_ARG_AFTER(opt, "-mpreferred-stack-boundary=");
693 snprintf(arch_opt, sizeof(arch_opt), "%s-stackalign=%s", cpu_arch, opt);
694 int res = firm_be_option(arch_opt);
696 argument_errors = true;
697 } else if(strcmp(opt, "omit-leaf-frame-pointer") == 0) {
698 set_be_option("omitleaffp=1");
699 } else if(strcmp(opt, "no-omit-leaf-frame-pointer") == 0) {
700 set_be_option("omitleaffp=0");
703 long int value = strtol(opt, &endptr, 10);
704 if (*endptr != '\0') {
705 fprintf(stderr, "error: wrong option '-m %s'\n", opt);
706 argument_errors = true;
708 if (value != 16 && value != 32 && value != 64) {
709 fprintf(stderr, "error: option -m supports only 16, 32 or 64\n");
710 argument_errors = true;
712 machine_size = (unsigned int)value;
715 } else if (option[0] == '\0') {
717 fprintf(stderr, "error: multiple input files specified\n");
718 argument_errors = true;
722 } else if(strcmp(option, "pg") == 0) {
723 set_be_option("gprof");
724 add_flag(&ldflags_obst, "-pg");
725 } else if(strcmp(option, "pedantic") == 0) {
726 fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);
727 } else if(strcmp(option, "shared") == 0) {
728 add_flag(&ldflags_obst, "-shared");
729 } else if(strncmp(option, "std=", 4) == 0) {
730 if(strcmp(&option[4], "c99") == 0) {
732 } else if(strcmp(&option[4], "c89") == 0) {
734 } else if(strcmp(&option[4], "gnu99") == 0) {
735 c_mode = _C89|_C99|_GNUC;
736 } else if(strcmp(&option[4], "microsoft") == 0) {
737 c_mode = _C89|_C99|_MS;
739 fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);
740 } else if(strcmp(option, "version") == 0) {
741 print_cparser_version();
742 } else if (option[0] == '-') {
743 /* double dash option */
745 if(strcmp(option, "gcc") == 0) {
747 } else if(strcmp(option, "no-gcc") == 0) {
749 } else if(strcmp(option, "ms") == 0) {
751 } else if(strcmp(option, "no-ms") == 0) {
753 } else if(strcmp(option, "signed-chars") == 0) {
754 char_is_signed = true;
755 } else if(strcmp(option, "unsigned-chars") == 0) {
756 char_is_signed = false;
757 } else if(strcmp(option, "strict") == 0) {
759 } else if(strcmp(option, "lextest") == 0) {
761 } else if(strcmp(option, "benchmark") == 0) {
762 mode = BenchmarkParser;
763 } else if(strcmp(option, "print-ast") == 0) {
765 } else if(strcmp(option, "print-implicit-cast") == 0) {
766 print_implicit_casts = true;
767 } else if(strcmp(option, "print-parenthesis") == 0) {
768 print_parenthesis = true;
769 } else if(strcmp(option, "print-fluffy") == 0) {
771 } else if(strcmp(option, "print-caml") == 0) {
773 } else if(strcmp(option, "version") == 0) {
774 print_cparser_version();
776 } else if(strcmp(option, "dump-function") == 0) {
779 fprintf(stderr, "error: "
780 "expected argument after '--dump-function'\n");
781 argument_errors = true;
784 dumpfunction = argv[i];
787 fprintf(stderr, "error: unknown argument '%s'\n", arg);
788 argument_errors = true;
791 fprintf(stderr, "error: unknown argument '%s'\n", arg);
792 argument_errors = true;
796 file_list_entry_t *entry
797 = obstack_alloc(&file_obst, sizeof(entry[0]));
798 entry->filename = arg;
800 size_t len = strlen(arg);
803 /* exception: '-' as name reads C from stdin */
804 entry->next = c_files;
808 fprintf(stderr, "'%s': file format not recognized\n", input);
812 if (strcmp(arg+len-2, ".c") == 0
813 || strcmp(arg+len-2, ".h") == 0) {
814 entry->next = c_files;
816 } else if (strcmp(arg+len-2, ".s") == 0 || strcmp(arg+len-2, ".S") == 0) {
817 entry->next = s_files;
819 } else if (strcmp(arg+len-2, ".o") == 0) {
820 entry->next = o_files;
823 fprintf(stderr, "'%s': file format not recognized\n", input);
828 if (c_files == NULL && s_files == NULL && o_files != NULL) {
830 } else if (c_files != NULL && c_files->next == NULL) {
831 input = c_files->filename;
832 } else if (s_files != NULL && s_files->next == NULL) {
833 input = s_files->filename;
834 if(!strcmp(input + strlen(input) - 2, ".S"))
835 mode = AssemblePreprocessed;
839 if (c_files == NULL && s_files == NULL) {
840 fprintf(stderr, "error: no input files specified\n");
842 fprintf(stderr, "error: multiple input files specified\n");
844 argument_errors = true;
847 /* we do the lowering in ast2firm */
848 firm_opt.lower_bitfields = FALSE;
850 if (help_displayed) {
851 return !argument_errors;
853 if (argument_errors) {
870 char outnamebuf[4096];
871 if(outname == NULL) {
873 case BenchmarkParser:
884 get_output_name(outnamebuf, sizeof(outnamebuf), input, ".s");
885 outname = outnamebuf;
887 case CompileAssemble:
888 get_output_name(outnamebuf, sizeof(outnamebuf), input, ".o");
889 outname = outnamebuf;
892 get_output_name(outnamebuf, sizeof(outnamebuf), dumpfunction,
894 outname = outnamebuf;
897 case CompileAssembleLink:
899 /* Windows compiler typically derive the output name from
900 the first source file */
901 get_output_name(outnamebuf, sizeof(outnamebuf), input, ".exe");
902 outname = outnamebuf;
910 if (mode == Assemble) {
911 assemble(outname, input);
916 obstack_1grow(&ldflags_obst, '\0');
917 const char *flags = obstack_finish(&ldflags_obst);
919 obstack_printf(&file_obst, "%s", LINKER);
921 for (file_list_entry_t *entry = o_files; entry != NULL;
922 entry = entry->next) {
923 obstack_printf(&file_obst, " %s", entry->filename);
926 obstack_printf(&file_obst, " -o %s %s", outname, flags);
927 obstack_1grow(&file_obst, '\0');
929 char *buf = obstack_finish(&file_obst);
934 int err = system(buf);
936 fprintf(stderr, "linker reported an error\n");
942 if(outname != NULL) {
943 if(strcmp(outname, "-") == 0) {
946 out = fopen(outname, "w");
948 fprintf(stderr, "Couldn't open '%s' for writing: %s\n", outname,
957 fprintf(stderr, "%s: no input files\n", argv[0]);
959 } else if(strcmp(input, "-") == 0) {
963 in = fopen(input, "r");
965 fprintf(stderr, "Couldn't open '%s': %s\n", input, strerror(errno));
970 if(mode == LexTest) {
976 FILE *preprocessed_in = preprocess(in, input);
977 if (mode == PreprocessOnly) {
978 copy_file(out, preprocessed_in);
979 return pclose(preprocessed_in);
982 if (mode == AssemblePreprocessed) {
984 char asm_tempfile[1024];
986 /* write preprocessed assembler to a temporary file */
987 asm_pp = make_temp_file(asm_tempfile, sizeof(asm_tempfile), "cc", ".s");
988 copy_file(asm_pp, preprocessed_in);
990 int res = pclose(preprocessed_in);
994 /* and assemble it */
995 assemble(outname, asm_tempfile);
999 translation_unit_t *const unit = do_parsing(preprocessed_in, input);
1000 int res = pclose(preprocessed_in);
1005 if(error_count > 0) {
1006 /* parsing failed because of errors */
1007 fprintf(stderr, "%u error(s), %u warning(s)\n", error_count, warning_count);
1008 result = EXIT_FAILURE;
1009 } else if(warning_count > 0) {
1010 fprintf(stderr, "%u warning(s)\n", warning_count);
1013 if(mode == BenchmarkParser) {
1017 /* prints the AST even if errors occurred */
1018 if(mode == PrintAst) {
1019 type_set_output(out);
1020 ast_set_output(out);
1025 /* cannot handle other modes with errors */
1026 if(result != EXIT_SUCCESS)
1029 if(mode == PrintFluffy) {
1030 write_fluffy_decls(out, unit);
1032 if (mode == PrintCaml) {
1033 write_caml_decls(out, unit);
1036 translation_unit_to_firm(unit);
1038 if(mode == ParseOnly) {
1043 char asm_tempfile[1024];
1044 if(mode == CompileDump) {
1046 firm_be_opt.selection = BE_NONE;
1047 } else if(mode == Compile) {
1051 = make_temp_file(asm_tempfile, sizeof(asm_tempfile), "cc", ".s");
1053 gen_firm_finish(asm_out, input, /*c_mode=*/1, /*firm_const_exists=*/0);
1055 if(mode == CompileDump) {
1057 ident *id = new_id_from_str(dumpfunction);
1058 ir_graph *irg = NULL;
1059 int n_irgs = get_irp_n_irgs();
1060 for(int i = 0; i < n_irgs; ++i) {
1061 ir_graph *tirg = get_irp_irg(i);
1062 ident *irg_id = get_entity_ident(get_irg_entity(tirg));
1070 fprintf(stderr, "No graph for function '%s' found\n", dumpfunction);
1074 dump_ir_block_graph_file(irg, out);
1081 /* assemble assembler and create object file */
1082 char obj_tfile[1024];
1083 if(mode == CompileAssemble || mode == CompileAssembleLink) {
1084 const char *obj_outfile;
1085 if(mode == CompileAssemble) {
1087 obj_outfile = outname;
1090 = make_temp_file(obj_tfile, sizeof(obj_tfile), "cc", ".o");
1092 obj_outfile = obj_tfile;
1095 assemble(obj_outfile, asm_tempfile);
1098 /* link object file */
1099 if(mode == CompileAssembleLink) {
1100 do_link(outname, obj_tfile);
1103 obstack_free(&cppflags_obst, NULL);
1104 obstack_free(&ldflags_obst, NULL);
1105 obstack_free(&file_obst, NULL);
1114 exit_symbol_table();