X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=main.c;h=57ef4615915911fad2deb5f5a074175fa73bc980;hb=bb0b3e3a3b5a6fdc78b9b36317b0a99e7a109d84;hp=8eae0207a229efbf5b2e086599917def67ff557c;hpb=000608f5e58c8d423daf26574200f84f795cd868;p=cparser diff --git a/main.c b/main.c index 8eae020..57ef461 100644 --- a/main.c +++ b/main.c @@ -79,6 +79,7 @@ #include "revision.h" #include "warning.h" #include "mangle.h" +#include "printer.h" #ifndef PREPROCESSOR #ifndef __WIN32__ @@ -94,7 +95,7 @@ #ifndef ASSEMBLER #ifdef __APPLE__ -#define ASSEMBLER "gcc -c -xassembler" +#define ASSEMBLER "gcc -m32 -c -xassembler" #else #define ASSEMBLER "as --32" #endif @@ -168,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, @@ -217,7 +197,7 @@ static void get_output_name(char *buf, size_t buflen, const char *inputname, panic("filename too long"); } -#include "builtins.h" +#include "gen_builtins.h" static translation_unit_t *do_parsing(FILE *const in, const char *const input_name) { @@ -316,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, ' '); @@ -569,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) @@ -594,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); } @@ -768,7 +745,7 @@ int main(int argc, char **argv) /* fallthrough */ case 3: set_option("thread-jumps"); - set_option("if-conv"); + set_option("if-conversion"); /* fallthrough */ case 2: set_option("strict-aliasing"); @@ -873,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")) { @@ -907,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); @@ -931,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); @@ -942,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,"); @@ -967,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=")) { @@ -1001,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")) { @@ -1017,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); @@ -1098,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) { @@ -1166,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; @@ -1272,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; @@ -1383,15 +1379,17 @@ do_parsing: c_mode |= features_on; c_mode &= ~features_off; - timer_push(TV_PARSING); + /* do the actual parsing */ + ir_timer_t *t_parsing = ir_timer_new(); + timer_register(t_parsing, "Frontend: Parsing"); + timer_push(t_parsing); init_tokens(); translation_unit_t *const unit = do_parsing(in, filename); - timer_pop(); + timer_pop(t_parsing); /* prints the AST even if errors occurred */ if (mode == PrintAst) { - type_set_output(out); - ast_set_output(out); + print_to_file(out); print_ast(unit); } @@ -1428,9 +1426,16 @@ do_parsing: continue; } - timer_push(TV_CONSTRUCT); + /* build the firm graph */ + 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); - timer_pop(); + already_constructed_firm = true; + timer_pop(t_construct); graph_built: if (mode == ParseOnly) { @@ -1457,7 +1462,7 @@ graph_built: exit(1); } - dump_ir_block_graph_file(irg, out); + dump_ir_graph_file(out, irg); fclose(out); exit(0); } @@ -1468,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); }