X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=main.c;h=57ef4615915911fad2deb5f5a074175fa73bc980;hb=bb0b3e3a3b5a6fdc78b9b36317b0a99e7a109d84;hp=77bf0c620a627f3267c7d00d00ff7a8cd3bb52db;hpb=09a8bede94a4eae894820ceb9aaa556cec8455ef;p=cparser diff --git a/main.c b/main.c index 77bf0c6..57ef461 100644 --- a/main.c +++ b/main.c @@ -169,30 +169,9 @@ struct file_list_entry_t { static file_list_entry_t *temp_files; -#if defined(_DEBUG) || defined(FIRM_DEBUG) -/** - * Debug printf implementation. - * - * @param fmt printf style format parameter - */ -void dbg_printf(const char *fmt, ...) -{ - va_list list; - - if (firm_dump.debug_print) { - va_start(list, fmt); - vprintf(fmt, list); - va_end(list); - } /* if */ -} -#endif /* defined(_DEBUG) || defined(FIRM_DEBUG) */ - static void initialize_firm(void) { firm_early_init(); - - dump_consts_local(1); - dump_keepalive_edges(1); } static void get_output_name(char *buf, size_t buflen, const char *inputname, @@ -317,18 +296,6 @@ static FILE *preprocess(const char *fname, filetype_t filetype) add_flag(&cppflags_obst, "-U__VERSION__"); add_flag(&cppflags_obst, "-D__VERSION__=\"%s\"", cparser_REVISION); - /* TODO hack... */ - add_flag(&cppflags_obst, "-D__builtin_abort=abort"); - add_flag(&cppflags_obst, "-D__builtin_abs=abs"); - add_flag(&cppflags_obst, "-D__builtin_exit=exit"); - add_flag(&cppflags_obst, "-D__builtin_malloc=malloc"); - add_flag(&cppflags_obst, "-D__builtin_memcmp=memcmp"); - add_flag(&cppflags_obst, "-D__builtin_memcpy=memcpy"); - add_flag(&cppflags_obst, "-D__builtin_memset=memset"); - add_flag(&cppflags_obst, "-D__builtin_strlen=strlen"); - add_flag(&cppflags_obst, "-D__builtin_strcmp=strcmp"); - add_flag(&cppflags_obst, "-D__builtin_strcpy=strcpy"); - if (flags[0] != '\0') { size_t len = strlen(flags); obstack_1grow(&cppflags_obst, ' '); @@ -570,7 +537,7 @@ typedef enum compile_mode_t { static void usage(const char *argv0) { - fprintf(stderr, "Usage %s input [-o output] [-c]\n", argv0); + fprintf(stderr, "Usage %s [options] input [-o output]\n", argv0); } static void print_cparser_version(void) @@ -595,9 +562,18 @@ static void print_cparser_version(void) "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); } +static void print_help(const char *argv0) +{ + usage(argv0); + puts(""); + puts("\t-fhelp Display help about firm optimisation options"); + puts("\t-bhelp Display help about firm backend options"); + puts("A big number of gcc flags is also supported"); +} + static void set_be_option(const char *arg) { - int res = firm_be_option(arg); + int res = be_parse_arg(arg); (void) res; assert(res); } @@ -874,11 +850,7 @@ int main(int argc, char **argv) char const *orig_opt; GET_ARG_AFTER(orig_opt, "-f"); - if (strstart(orig_opt, "align-loops=") || - strstart(orig_opt, "align-jumps=") || - strstart(orig_opt, "align-functions=")) { - fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt); - } else if (strstart(orig_opt, "input-charset=")) { + if (strstart(orig_opt, "input-charset=")) { char const* const encoding = strchr(orig_opt, '=') + 1; select_input_encoding(encoding); } else if (streq(orig_opt, "verbose-asm")) { @@ -908,14 +880,25 @@ int main(int argc, char **argv) mode = truth_value ? ParseOnly : CompileAssembleLink; } else if (streq(opt, "unsigned-char")) { char_is_signed = !truth_value; + } else if (truth_value == false && + streq(opt, "asynchronous-unwind-tables")) { + /* nothing todo, a gcc feature which we don't support + * anyway was deactivated */ + } else if (strstart(orig_opt, "align-loops=") || + strstart(orig_opt, "align-jumps=") || + strstart(orig_opt, "align-functions=")) { + fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt); + } else if (strstart(orig_opt, "message-length=")) { + /* ignore: would only affect error message format */ } else if (streq(opt, "fast-math") || streq(opt, "jump-tables") || streq(opt, "expensive-optimizations") || streq(opt, "common") || - streq(opt, "PIC") || + streq(opt, "optimize-sibling-calls") || streq(opt, "align-loops") || streq(opt, "align-jumps") || - streq(opt, "align-functions")) { + streq(opt, "align-functions") || + streq(opt, "PIC")) { fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt); } else { int res = firm_option(orig_opt); @@ -932,7 +915,7 @@ int main(int argc, char **argv) } else if (option[0] == 'b') { const char *opt; GET_ARG_AFTER(opt, "-b"); - int res = firm_be_option(opt); + int res = be_parse_arg(opt); if (res == 0) { fprintf(stderr, "error: unknown Firm backend option '-b %s'\n", opt); @@ -943,7 +926,9 @@ int main(int argc, char **argv) strncpy(cpu_arch, opt, sizeof(cpu_arch)); } } else if (option[0] == 'W') { - if (strstart(option + 1, "p,")) { + if (option[1] == '\0') { + /* ignore -W, out defaults are already quiet verbose */ + } else if (strstart(option + 1, "p,")) { // pass options directly to the preprocessor const char *opt; GET_ARG_AFTER(opt, "-Wp,"); @@ -968,26 +953,26 @@ int main(int argc, char **argv) if (strstart(opt, "arch=")) { GET_ARG_AFTER(opt, "-march="); snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt); - int res = firm_be_option(arch_opt); + int res = be_parse_arg(arch_opt); if (res == 0) { fprintf(stderr, "Unknown architecture '%s'\n", arch_opt); argument_errors = true; } else { snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt); - int res = firm_be_option(arch_opt); + int res = be_parse_arg(arch_opt); if (res == 0) argument_errors = true; } } else if (strstart(opt, "tune=")) { GET_ARG_AFTER(opt, "-mtune="); snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt); - int res = firm_be_option(arch_opt); + int res = be_parse_arg(arch_opt); if (res == 0) argument_errors = true; } else if (strstart(opt, "cpu=")) { GET_ARG_AFTER(opt, "-mcpu="); snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt); - int res = firm_be_option(arch_opt); + int res = be_parse_arg(arch_opt); if (res == 0) argument_errors = true; } else if (strstart(opt, "fpmath=")) { @@ -1002,14 +987,14 @@ int main(int argc, char **argv) } if (!argument_errors) { snprintf(arch_opt, sizeof(arch_opt), "%s-fpunit=%s", cpu_arch, opt); - int res = firm_be_option(arch_opt); + int res = be_parse_arg(arch_opt); if (res == 0) argument_errors = true; } } else if (strstart(opt, "preferred-stack-boundary=")) { GET_ARG_AFTER(opt, "-mpreferred-stack-boundary="); snprintf(arch_opt, sizeof(arch_opt), "%s-stackalign=%s", cpu_arch, opt); - int res = firm_be_option(arch_opt); + int res = be_parse_arg(arch_opt); if (res == 0) argument_errors = true; } else if (streq(opt, "omit-leaf-frame-pointer")) { @@ -1018,6 +1003,12 @@ int main(int argc, char **argv) set_be_option("omitleaffp=0"); } else if (streq(opt, "rtd")) { default_calling_convention = CC_STDCALL; + } else if (strstart(opt, "regparm=")) { + fprintf(stderr, "error: regparm convention not supported yet\n"); + argument_errors = true; + } else if (streq(opt, "soft-float")) { + fprintf(stderr, "error: software floatingpoint not supported yet\n"); + argument_errors = true; } else { char *endptr; long int value = strtol(opt, &endptr, 10); @@ -1099,6 +1090,9 @@ int main(int argc, char **argv) } else if (streq(option, "version")) { print_cparser_version(); exit(EXIT_SUCCESS); + } else if (streq(option, "help")) { + print_help(argv[0]); + help_displayed = true; } else if (streq(option, "dump-function")) { ++i; if (i >= argc) { @@ -1167,19 +1161,19 @@ int main(int argc, char **argv) } } + if (help_displayed) { + return !argument_errors; + } + if (print_file_name_file != NULL) { print_file_name(print_file_name_file); return 0; } - if (files == NULL) { fprintf(stderr, "error: no input files specified\n"); argument_errors = true; } - if (help_displayed) { - return !argument_errors; - } if (argument_errors) { usage(argv[0]); return 1; @@ -1273,6 +1267,7 @@ int main(int argc, char **argv) } file_list_entry_t *file; + bool already_constructed_firm = false; for (file = files; file != NULL; file = file->next) { char asm_tempfile[1024]; const char *filename = file->name; @@ -1435,7 +1430,11 @@ do_parsing: ir_timer_t *t_construct = ir_timer_new(); timer_register(t_construct, "Frontend: Graph construction"); timer_push(t_construct); + if (already_constructed_firm) { + panic("compiling multiple files/translation units not possible"); + } translation_unit_to_firm(unit); + already_constructed_firm = true; timer_pop(t_construct); graph_built: @@ -1463,7 +1462,7 @@ graph_built: exit(1); } - dump_ir_block_graph_file(irg, out); + dump_ir_graph_file(out, irg); fclose(out); exit(0); } @@ -1474,8 +1473,7 @@ graph_built: exit(0); } - gen_firm_finish(asm_out, filename, /*c_mode=*/1, - have_const_functions); + gen_firm_finish(asm_out, filename, have_const_functions); if (asm_out != out) { fclose(asm_out); }