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 typedef enum filetype_t {
122 FILETYPE_PREPROCESSED_C,
124 FILETYPE_PREPROCESSED_ASSEMBLER,
129 struct file_list_entry_t {
130 const char *name; /**< filename or NULL for stdin */
132 file_list_entry_t *next;
135 #if defined(_DEBUG) || defined(FIRM_DEBUG)
137 * Debug printf implementation.
139 * @param fmt printf style format parameter
141 void dbg_printf(const char *fmt, ...)
145 if (firm_dump.debug_print) {
151 #endif /* defined(_DEBUG) || defined(FIRM_DEBUG) */
153 static void initialize_firm(void)
157 dump_consts_local(1);
158 dump_keepalive_edges(1);
161 static void get_output_name(char *buf, size_t buflen, const char *inputname,
164 size_t last_dot = 0xffffffff;
167 if(inputname == NULL) {
168 snprintf(buf, buflen, "a%s", newext);
172 for(const char *c = inputname; *c != 0; ++c) {
177 if(last_dot == 0xffffffff)
180 if(last_dot >= buflen)
181 panic("filename too long");
182 memcpy(buf, inputname, last_dot);
184 size_t extlen = strlen(newext) + 1;
185 if(extlen + last_dot >= buflen)
186 panic("filename too long");
187 memcpy(buf+last_dot, newext, extlen);
190 #include "builtins.h"
192 static translation_unit_t *do_parsing(FILE *const in, const char *const input_name)
197 lexer_open_buffer(builtins, sizeof(builtins)-1, "<builtin>");
201 lexer_open_stream(in, input_name);
204 translation_unit_t *unit = finish_parsing();
208 static void lextest(FILE *in, const char *fname)
210 lexer_open_stream(in, fname);
213 lexer_next_preprocessing_token();
214 print_token(stdout, &lexer_token);
216 } while(lexer_token.type != T_EOF);
219 static void add_flag(struct obstack *obst, const char *format, ...)
222 va_start(ap, format);
225 vsnprintf(buf, sizeof(buf), format, ap);
227 /* escape stuff... */
228 obstack_1grow(obst, ' ');
229 for (char *c = buf; *c != '\0'; ++c) {
242 obstack_1grow(obst, '\\');
245 obstack_1grow(obst, *c);
253 static FILE *preprocess(const char *fname)
256 obstack_1grow(&cppflags_obst, '\0');
257 const char *flags = obstack_finish(&cppflags_obst);
259 snprintf(buf, sizeof(buf), PREPROCESSOR " %s %s", flags, fname);
264 FILE *f = popen(buf, "r");
266 fprintf(stderr, "invoking preprocessor failed\n");
272 static void assemble(const char *out, const char *in)
276 snprintf(buf, sizeof(buf), "%s %s -o %s", ASSEMBLER, in, out);
281 int err = system(buf);
283 fprintf(stderr, "assembler reported an error\n");
288 static const char *try_dir(const char *dir)
292 if(access(dir, R_OK | W_OK | X_OK) == 0)
297 static const char *get_tempdir(void)
299 static const char *tmpdir = NULL;
305 tmpdir = try_dir(getenv("TMPDIR"));
307 tmpdir = try_dir(getenv("TMP"));
309 tmpdir = try_dir(getenv("TEMP"));
313 tmpdir = try_dir(P_tmpdir);
317 tmpdir = try_dir("/var/tmp");
319 tmpdir = try_dir("/usr/tmp");
321 tmpdir = try_dir("/tmp");
330 /* cheap and nasty mkstemp replacement */
331 static int mkstemp(char *templ)
334 return open(templ, O_RDWR|O_CREAT|O_EXCL|O_BINARY, 0600);
339 * an own version of tmpnam, which: writes in a buffer, emits no warnings
340 * during linking (like glibc/gnu ld do for tmpnam)...
342 static FILE *make_temp_file(char *buffer, size_t buflen, const char *prefix)
344 const char *tempdir = get_tempdir();
346 snprintf(buffer, buflen, "%s/%sXXXXXX", tempdir, prefix);
348 int fd = mkstemp(buffer);
350 fprintf(stderr, "couldn't create temporary file: %s\n",
354 FILE *out = fdopen(fd, "w");
356 fprintf(stderr, "couldn't create temporary file FILE*\n");
364 * Do the necessary lowering for compound parameters.
366 void lower_compound_params(void)
368 lower_params_t params;
370 params.def_ptr_alignment = 4;
371 params.flags = LF_COMPOUND_RETURN | LF_RETURN_HIDDEN;
372 params.hidden_params = ADD_HIDDEN_ALWAYS_IN_FRONT;
373 params.find_pointer_type = NULL;
374 params.ret_compound_in_regs = NULL;
375 lower_calls_with_compounds(¶ms);
378 typedef enum compile_mode_t {
392 static void usage(const char *argv0)
394 fprintf(stderr, "Usage %s input [-o output] [-c]\n", argv0);
397 static void print_cparser_version(void) {
399 firm_get_version(&ver);
401 printf("cparser (%s) using libFirm (%u.%u",
402 cparser_REVISION, ver.major, ver.minor);
403 if(ver.revision[0] != 0) {
405 fputs(ver.revision, stdout);
407 if(ver.build[0] != 0) {
409 fputs(ver.build, stdout);
414 static void set_be_option(const char *arg)
416 int res = firm_be_option(arg);
421 static void set_option(const char *arg)
423 int res = firm_option(arg);
428 static void copy_file(FILE *dest, FILE *input)
432 while (!feof(input) && !ferror(dest)) {
433 size_t read = fread(buf, 1, sizeof(buf), input);
434 if(fwrite(buf, 1, read, dest) != read) {
435 perror("couldn't write output");
440 static FILE *open_file(const char *filename)
442 if (strcmp(filename, "-") == 0) {
446 FILE *in = fopen(filename, "r");
448 fprintf(stderr, "Couldn't open '%s': %s\n", filename,
456 int main(int argc, char **argv)
460 const char *outname = NULL;
461 const char *dumpfunction = NULL;
462 compile_mode_t mode = CompileAssembleLink;
464 int result = EXIT_SUCCESS;
465 char cpu_arch[16] = "ia32";
466 file_list_entry_t *files = NULL;
467 file_list_entry_t *last_file = NULL;
468 struct obstack file_obst;
470 obstack_init(&cppflags_obst);
471 obstack_init(&ldflags_obst);
472 obstack_init(&file_obst);
474 #define GET_ARG_AFTER(def, args) \
475 def = &arg[sizeof(args)-1]; \
476 if(def[0] == '\0') { \
479 fprintf(stderr, "error: expected argument after '" args "'\n"); \
480 argument_errors = true; \
484 if(def[0] == '-' && def[1] != '\0') { \
485 fprintf(stderr, "error: expected argument after '" args "'\n"); \
486 argument_errors = true; \
491 #define SINGLE_OPTION(ch) (option[0] == (ch) && option[1] == '\0')
493 /* early options parsing (find out optimisation level) */
494 for(int i = 1; i < argc; ++i) {
495 const char *arg = argv[i];
499 const char *option = &arg[1];
500 if(option[0] == 'O') {
501 sscanf(&option[1], "%d", &opt_level);
505 /* apply optimisation level */
508 set_option("no-opt");
511 set_option("no-inline");
515 set_option("strict-aliasing");
518 set_option("cond-eval");
519 set_option("if-conv");
523 set_option("inline");
524 set_option("deconv");
525 set_be_option("omitfp");
529 /* parse rest of options */
530 bool help_displayed = false;
531 bool argument_errors = false;
532 for(int i = 1; i < argc; ++i) {
533 const char *arg = argv[i];
534 if(arg[0] == '-' && arg[1] != 0) {
536 const char *option = &arg[1];
537 if(option[0] == 'o') {
538 GET_ARG_AFTER(outname, "-o");
539 } else if(option[0] == 'g') {
540 set_be_option("debuginfo=stabs");
541 set_be_option("omitfp=no");
542 set_be_option("ia32-nooptcc=yes");
543 } else if(SINGLE_OPTION('c')) {
544 mode = CompileAssemble;
545 } else if(SINGLE_OPTION('E')) {
546 mode = PreprocessOnly;
547 } else if(SINGLE_OPTION('S')) {
549 } else if(option[0] == 'O') {
551 } else if(option[0] == 'I') {
553 GET_ARG_AFTER(opt, "-I");
554 add_flag(&cppflags_obst, "-I%s", opt);
555 } else if(option[0] == 'D') {
557 GET_ARG_AFTER(opt, "-D");
558 add_flag(&cppflags_obst, "-D%s", opt);
559 } else if(option[0] == 'U') {
561 GET_ARG_AFTER(opt, "-U");
562 add_flag(&cppflags_obst, "-U%s", opt);
563 } else if(option[0] == 'l') {
565 GET_ARG_AFTER(opt, "-l");
566 add_flag(&ldflags_obst, "-l%s", opt);
567 } else if(option[0] == 'L') {
569 GET_ARG_AFTER(opt, "-L");
570 add_flag(&ldflags_obst, "-L%s", opt);
571 } else if(SINGLE_OPTION('v')) {
573 } else if(SINGLE_OPTION('w')) {
574 inhibit_all_warnings = true;
575 } else if(strcmp(option, "M") == 0) {
576 mode = PreprocessOnly;
577 add_flag(&cppflags_obst, "-M");
578 } else if(strcmp(option, "MMD") == 0
579 || strcmp(option, "MD") == 0
580 || strcmp(option, "MM") == 0) {
581 add_flag(&cppflags_obst, "-%s", option);
582 } else if(strcmp(option, "MT") == 0
583 || strcmp(option, "MQ") == 0
584 || strcmp(option, "MF") == 0) {
586 GET_ARG_AFTER(opt, "-MT");
587 add_flag(&cppflags_obst, "-%s", option);
588 add_flag(&cppflags_obst, "%s", opt);
589 } else if(strcmp(option, "pipe") == 0) {
590 /* here for gcc compatibility */
591 } else if(option[0] == 'f') {
593 GET_ARG_AFTER(opt, "-f");
595 if(strcmp(opt, "syntax-only") == 0) {
597 } else if(strcmp(opt, "omit-frame-pointer") == 0) {
598 set_be_option("omitfp");
599 } else if(strcmp(opt, "no-omit-frame-pointer") == 0) {
600 set_be_option("omitfp=no");
601 } else if(strcmp(opt, "strength-reduce") == 0) {
602 firm_option("strength-red");
603 } else if(strcmp(opt, "fast-math") == 0
604 || strcmp(opt, "unroll-loops") == 0
605 || strcmp(opt, "expensive-optimizations") == 0
606 || strcmp(opt, "no-common") == 0
607 || strncmp(opt, "align-loops=", sizeof("align-loops=")-1) == 0
608 || strncmp(opt, "align-jumps=", sizeof("align-jumps=")-1) == 0
609 || strncmp(opt, "align-functions=", sizeof("align-functions=")-1) == 0) {
610 fprintf(stderr, "ignoring gcc option '-f %s'\n", opt);
612 int res = firm_option(opt);
614 fprintf(stderr, "error: unknown Firm option '-f %s'\n",
616 argument_errors = true;
618 } else if (res == -1) {
619 help_displayed = true;
622 } else if(option[0] == 'b') {
624 GET_ARG_AFTER(opt, "-b");
625 int res = firm_be_option(opt);
627 fprintf(stderr, "error: unknown Firm backend option '-b %s'\n",
629 argument_errors = true;
630 } else if (res == -1) {
631 help_displayed = true;
633 if (strncmp(opt, "isa=", 4) == 0)
634 strncpy(cpu_arch, opt, sizeof(cpu_arch));
636 } else if(option[0] == 'W') {
637 set_warning_opt(&option[1]);
638 } else if(option[0] == 'm') {
643 GET_ARG_AFTER(opt, "-m");
644 if(strncmp(opt, "arch=", 5) == 0) {
645 GET_ARG_AFTER(opt, "-march=");
646 snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt);
647 int res = firm_be_option(arch_opt);
649 argument_errors = true;
651 snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt);
652 int res = firm_be_option(arch_opt);
654 argument_errors = true;
656 } else if(strncmp(opt, "tune=", 5) == 0) {
657 GET_ARG_AFTER(opt, "-mtune=");
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;
662 } else if(strncmp(opt, "cpu=", 4) == 0) {
663 GET_ARG_AFTER(opt, "-mcpu=");
664 snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt);
665 int res = firm_be_option(arch_opt);
667 argument_errors = true;
668 } else if(strncmp(opt, "fpmath=", 7) == 0) {
669 GET_ARG_AFTER(opt, "-mfpmath=");
670 if(strcmp(opt, "387") == 0)
672 else if(strcmp(opt, "sse") == 0)
675 fprintf(stderr, "error: option -mfpumath supports only 387 or sse\n");
676 argument_errors = true;
678 if(!argument_errors) {
679 snprintf(arch_opt, sizeof(arch_opt), "%s-fpunit=%s", cpu_arch, opt);
680 int res = firm_be_option(arch_opt);
682 argument_errors = true;
684 } else if(strncmp(opt, "preferred-stack-boundary=", 25) == 0) {
685 GET_ARG_AFTER(opt, "-mpreferred-stack-boundary=");
686 snprintf(arch_opt, sizeof(arch_opt), "%s-stackalign=%s", cpu_arch, opt);
687 int res = firm_be_option(arch_opt);
689 argument_errors = true;
690 } else if(strcmp(opt, "omit-leaf-frame-pointer") == 0) {
691 set_be_option("omitleaffp=1");
692 } else if(strcmp(opt, "no-omit-leaf-frame-pointer") == 0) {
693 set_be_option("omitleaffp=0");
696 long int value = strtol(opt, &endptr, 10);
697 if (*endptr != '\0') {
698 fprintf(stderr, "error: wrong option '-m %s'\n", opt);
699 argument_errors = true;
701 if (value != 16 && value != 32 && value != 64) {
702 fprintf(stderr, "error: option -m supports only 16, 32 or 64\n");
703 argument_errors = true;
705 machine_size = (unsigned int)value;
708 } else if(strcmp(option, "pg") == 0) {
709 set_be_option("gprof");
710 add_flag(&ldflags_obst, "-pg");
711 } else if(strcmp(option, "pedantic") == 0) {
712 fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);
713 } else if(strcmp(option, "shared") == 0) {
714 add_flag(&ldflags_obst, "-shared");
715 } else if(strncmp(option, "std=", 4) == 0) {
716 if(strcmp(&option[4], "c99") == 0) {
718 } else if(strcmp(&option[4], "c89") == 0) {
720 } else if(strcmp(&option[4], "gnu99") == 0) {
721 c_mode = _C89|_C99|_GNUC;
722 } else if(strcmp(&option[4], "microsoft") == 0) {
723 c_mode = _C89|_C99|_MS;
725 fprintf(stderr, "warning: ignoring gcc option '%s'\n", arg);
726 } else if(strcmp(option, "version") == 0) {
727 print_cparser_version();
728 } else if (option[0] == '-') {
729 /* double dash option */
731 if(strcmp(option, "gcc") == 0) {
733 } else if(strcmp(option, "no-gcc") == 0) {
735 } else if(strcmp(option, "ms") == 0) {
737 } else if(strcmp(option, "no-ms") == 0) {
739 } else if(strcmp(option, "signed-chars") == 0) {
740 char_is_signed = true;
741 } else if(strcmp(option, "unsigned-chars") == 0) {
742 char_is_signed = false;
743 } else if(strcmp(option, "strict") == 0) {
745 } else if(strcmp(option, "lextest") == 0) {
747 } else if(strcmp(option, "benchmark") == 0) {
748 mode = BenchmarkParser;
749 } else if(strcmp(option, "print-ast") == 0) {
751 } else if(strcmp(option, "print-implicit-cast") == 0) {
752 print_implicit_casts = true;
753 } else if(strcmp(option, "print-parenthesis") == 0) {
754 print_parenthesis = true;
755 } else if(strcmp(option, "print-fluffy") == 0) {
757 } else if(strcmp(option, "print-caml") == 0) {
759 } else if(strcmp(option, "version") == 0) {
760 print_cparser_version();
762 } else if(strcmp(option, "dump-function") == 0) {
765 fprintf(stderr, "error: "
766 "expected argument after '--dump-function'\n");
767 argument_errors = true;
770 dumpfunction = argv[i];
773 fprintf(stderr, "error: unknown argument '%s'\n", arg);
774 argument_errors = true;
777 fprintf(stderr, "error: unknown argument '%s'\n", arg);
778 argument_errors = true;
781 filetype_t type = FILETYPE_UNKNOWN;
782 size_t len = strlen(arg);
783 const char *filename = arg;
784 if (len < 2 && arg[0] == '-') {
785 /* - implicitely means C source file */
788 } else if (len > 2 && arg[len-2] == '.') {
790 case 'c': type = FILETYPE_C; break;
791 case 'h': type = FILETYPE_C; break;
792 case 's': type = FILETYPE_PREPROCESSED_ASSEMBLER; break;
793 case 'S': type = FILETYPE_ASSEMBLER; break;
794 case 'o': type = FILETYPE_OBJECT; break;
798 if (type == FILETYPE_UNKNOWN) {
799 fprintf(stderr, "'%s': file format not recognized\n", arg);
801 file_list_entry_t *entry
802 = obstack_alloc(&file_obst, sizeof(entry[0]));
803 memset(entry, 0, sizeof(entry[0]));
807 if (last_file != NULL) {
808 last_file->next = entry;
818 fprintf(stderr, "error: no input files specified\n");
819 argument_errors = true;
822 if (help_displayed) {
823 return !argument_errors;
825 if (argument_errors) {
830 /* we do the lowering in ast2firm */
831 firm_opt.lower_bitfields = FALSE;
844 char outnamebuf[4096];
845 if (outname == NULL) {
846 const char *filename = files->name;
849 case BenchmarkParser:
860 get_output_name(outnamebuf, sizeof(outnamebuf), filename, ".s");
861 outname = outnamebuf;
863 case CompileAssemble:
864 get_output_name(outnamebuf, sizeof(outnamebuf), filename, ".o");
865 outname = outnamebuf;
868 get_output_name(outnamebuf, sizeof(outnamebuf), dumpfunction,
870 outname = outnamebuf;
872 case CompileAssembleLink:
882 assert(outname != NULL);
885 if(strcmp(outname, "-") == 0) {
888 out = fopen(outname, "w");
890 fprintf(stderr, "Couldn't open '%s' for writing: %s\n", outname,
896 file_list_entry_t *file;
897 for (file = files; file != NULL; file = file->next) {
898 char asm_tempfile[1024];
899 const char *filename = file->name;
900 filetype_t filetype = file->type;
902 if (file->type == FILETYPE_OBJECT)
906 if (mode == LexTest) {
908 in = open_file(filename);
909 lextest(in, filename);
914 FILE *preprocessed_in = NULL;
915 if (filetype == FILETYPE_C || filetype == FILETYPE_ASSEMBLER) {
916 /* no support for input on FILE* yet */
918 panic("internal compiler error: in for preprocessor != NULL");
920 preprocessed_in = preprocess(filename);
921 if (mode == PreprocessOnly) {
922 copy_file(out, preprocessed_in);
923 int result = pclose(preprocessed_in);
928 if (filetype == FILETYPE_C) {
929 filetype = FILETYPE_PREPROCESSED_C;
930 } else if (filetype == FILETYPE_ASSEMBLER) {
931 filetype = FILETYPE_PREPROCESSED_ASSEMBLER;
933 panic("internal compiler error: unknown filetype at preproc");
936 in = preprocessed_in;
940 if(mode == Compile) {
943 asm_out = make_temp_file(asm_tempfile, sizeof(asm_tempfile),
948 in = open_file(filename);
950 /* preprocess and compile */
951 if (filetype == FILETYPE_PREPROCESSED_C) {
952 translation_unit_t *const unit = do_parsing(in, filename);
953 if (in == preprocessed_in) {
954 int pp_result = pclose(preprocessed_in);
955 if (pp_result != EXIT_SUCCESS) {
960 /* prints the AST even if errors occurred */
961 if (mode == PrintAst) {
962 type_set_output(out);
967 if(error_count > 0) {
968 /* parsing failed because of errors */
969 fprintf(stderr, "%u error(s), %u warning(s)\n", error_count,
971 result = EXIT_FAILURE;
973 } else if(warning_count > 0) {
974 fprintf(stderr, "%u warning(s)\n", warning_count);
977 if(mode == BenchmarkParser) {
979 } else if(mode == PrintFluffy) {
980 write_fluffy_decls(out, unit);
982 } else if (mode == PrintCaml) {
983 write_caml_decls(out, unit);
987 translation_unit_to_firm(unit);
989 if (mode == ParseOnly) {
993 if (mode == CompileDump) {
995 ident *id = new_id_from_str(dumpfunction);
996 ir_graph *irg = NULL;
997 int n_irgs = get_irp_n_irgs();
998 for(int i = 0; i < n_irgs; ++i) {
999 ir_graph *tirg = get_irp_irg(i);
1000 ident *irg_id = get_entity_ident(get_irg_entity(tirg));
1008 fprintf(stderr, "No graph for function '%s' found\n",
1013 dump_ir_block_graph_file(irg, out);
1018 gen_firm_finish(asm_out, filename, /*c_mode=*/1,
1019 /*firm_const_exists=*/0);
1020 if (asm_out != out) {
1024 } else if (filetype == FILETYPE_PREPROCESSED_ASSEMBLER) {
1025 copy_file(asm_out, in);
1026 if (in == preprocessed_in) {
1027 int pp_result = pclose(preprocessed_in);
1028 if (pp_result != EXIT_SUCCESS) {
1034 if (mode == Compile)
1037 /* if we're here then we have preprocessed assembly */
1038 filename = asm_tempfile;
1039 filetype = FILETYPE_PREPROCESSED_ASSEMBLER;
1042 if (filetype == FILETYPE_PREPROCESSED_ASSEMBLER) {
1044 const char *filename_o;
1045 if(mode == CompileAssemble) {
1047 filename_o = outname;
1049 FILE *tempf = make_temp_file(temp, sizeof(temp), "cco");
1054 assemble(filename_o, filename);
1056 size_t len = strlen(filename_o) + 1;
1057 filename = obstack_copy(&file_obst, filename_o, len);
1058 filetype = FILETYPE_OBJECT;
1061 /* ok we're done here, process next file */
1062 file->name = filename;
1063 file->type = filetype;
1066 /* link program file */
1067 if(mode == CompileAssembleLink) {
1068 obstack_1grow(&ldflags_obst, '\0');
1069 const char *flags = obstack_finish(&ldflags_obst);
1071 /* construct commandline */
1072 obstack_printf(&file_obst, "%s", LINKER);
1073 for (file_list_entry_t *entry = files; entry != NULL;
1074 entry = entry->next) {
1075 if (entry->type != FILETYPE_OBJECT)
1078 add_flag(&file_obst, "%s", entry->name);
1081 add_flag(&file_obst, "-o");
1082 add_flag(&file_obst, outname);
1083 obstack_printf(&file_obst, "%s", flags);
1084 obstack_1grow(&file_obst, '\0');
1086 char *commandline = obstack_finish(&file_obst);
1091 int err = system(commandline);
1092 if(err != EXIT_SUCCESS) {
1093 fprintf(stderr, "linker reported an error\n");
1098 obstack_free(&cppflags_obst, NULL);
1099 obstack_free(&ldflags_obst, NULL);
1100 obstack_free(&file_obst, NULL);
1109 exit_symbol_table();