modularize revision file updating and include cparser
[cparser] / main.c
diff --git a/main.c b/main.c
index bc0be10..7c85ee0 100644 (file)
--- a/main.c
+++ b/main.c
@@ -71,6 +71,7 @@
 #include "lang_features.h"
 #include "driver/firm_opt.h"
 #include "driver/firm_cmdline.h"
+#include "driver/firm_timing.h"
 #include "adt/error.h"
 #include "wrappergen/write_fluffy.h"
 #include "wrappergen/write_caml.h"
@@ -78,6 +79,7 @@
 #include "revision.h"
 #include "warning.h"
 #include "mangle.h"
+#include "printer.h"
 
 #ifndef PREPROCESSOR
 #ifndef __WIN32__
@@ -93,7 +95,7 @@
 
 #ifndef ASSEMBLER
 #ifdef __APPLE__
-#define ASSEMBLER "gcc -c -xassembler"
+#define ASSEMBLER "gcc -m32 -c -xassembler"
 #else
 #define ASSEMBLER "as --32"
 #endif
@@ -332,11 +334,17 @@ static FILE *preprocess(const char *fname, filetype_t filetype)
                        obstack_1grow(&cppflags_obst, ' ');
                        obstack_grow(&cppflags_obst, flags, len);
                }
+               obstack_1grow(&cppflags_obst, '\0');
                common_flags = obstack_finish(&cppflags_obst);
        }
 
        assert(obstack_object_size(&cppflags_obst) == 0);
-       obstack_printf(&cppflags_obst, "%s ", PREPROCESSOR);
+
+       const char *preprocessor = getenv("CPARSER_PP");
+       if (preprocessor == NULL)
+               preprocessor = PREPROCESSOR;
+
+       obstack_printf(&cppflags_obst, "%s ", preprocessor);
        switch (filetype) {
        case FILETYPE_C:
                add_flag(&cppflags_obst, "-std=c99");
@@ -386,7 +394,11 @@ static void assemble(const char *out, const char *in)
 {
        char buf[65536];
 
-       snprintf(buf, sizeof(buf), "%s %s -o %s", ASSEMBLER, in, out);
+       const char *assembler = getenv("CPARSER_AS");
+       if (assembler == NULL)
+               assembler = ASSEMBLER;
+
+       snprintf(buf, sizeof(buf), "%s %s -o %s", assembler, in, out);
        if (verbose) {
                puts(buf);
        }
@@ -406,7 +418,10 @@ static void print_file_name(const char *file)
        const char *flags = obstack_finish(&ldflags_obst);
 
        /* construct commandline */
-       obstack_printf(&ldflags_obst, "%s ", LINKER);
+       const char *linker = getenv("CPARSER_LINK");
+       if (linker == NULL)
+               linker = LINKER;
+       obstack_printf(&ldflags_obst, "%s ", linker);
        obstack_printf(&ldflags_obst, "%s", flags);
        obstack_1grow(&ldflags_obst, '\0');
 
@@ -684,6 +699,7 @@ int main(int argc, char **argv)
        file_list_entry_t *files                = NULL;
        file_list_entry_t *last_file            = NULL;
        bool               construct_dep_target = false;
+       bool               do_timing            = false;
        struct obstack     file_obst;
 
        atexit(free_temp_files);
@@ -752,8 +768,8 @@ int main(int argc, char **argv)
                /* use_builtins = true; */
                /* fallthrough */
        case 3:
-               set_option("cond-eval");
-               set_option("if-conv");
+               set_option("thread-jumps");
+               set_option("if-conversion");
                /* fallthrough */
        case 2:
                set_option("strict-aliasing");
@@ -894,7 +910,6 @@ int main(int argc, char **argv)
                                                char_is_signed = !truth_value;
                                        } else if (streq(opt, "fast-math")               ||
                                                   streq(opt, "jump-tables")             ||
-                                                  streq(opt, "unroll-loops")            ||
                                                   streq(opt, "expensive-optimizations") ||
                                                   streq(opt, "common")                  ||
                                                   streq(opt, "PIC")                     ||
@@ -954,9 +969,10 @@ int main(int argc, char **argv)
                                        GET_ARG_AFTER(opt, "-march=");
                                        snprintf(arch_opt, sizeof(arch_opt), "%s-arch=%s", cpu_arch, opt);
                                        int res = firm_be_option(arch_opt);
-                                       if (res == 0)
+                                       if (res == 0) {
+                                               fprintf(stderr, "Unknown architecture '%s'\n", arch_opt);
                                                argument_errors = true;
-                                       else {
+                                       else {
                                                snprintf(arch_opt, sizeof(arch_opt), "%s-opt=%s", cpu_arch, opt);
                                                int res = firm_be_option(arch_opt);
                                                if (res == 0)
@@ -1078,6 +1094,8 @@ int main(int argc, char **argv)
                                        mode = PrintCaml;
                                } else if (streq(option, "print-jna")) {
                                        mode = PrintJna;
+                               } else if (streq(option, "time")) {
+                                       do_timing = true;
                                } else if (streq(option, "version")) {
                                        print_cparser_version();
                                        exit(EXIT_SUCCESS);
@@ -1185,6 +1203,9 @@ int main(int argc, char **argv)
        init_ast2firm();
        init_mangle();
 
+       if (do_timing)
+               timer_init();
+
        if (construct_dep_target) {
                if (outname != 0 && strlen(outname) >= 2) {
                        get_output_name(dep_target, sizeof(dep_target), outname, ".d");
@@ -1363,13 +1384,17 @@ do_parsing:
                        c_mode |= features_on;
                        c_mode &= ~features_off;
 
+                       /* 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(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);
                        }
 
@@ -1406,7 +1431,12 @@ do_parsing:
                                continue;
                        }
 
+                       /* build the firm graph */
+                       ir_timer_t *t_construct = ir_timer_new();
+                       timer_register(t_construct, "Frontend: Graph construction");
+                       timer_push(t_construct);
                        translation_unit_to_firm(unit);
+                       timer_pop(t_construct);
 
 graph_built:
                        if (mode == ParseOnly) {
@@ -1513,7 +1543,10 @@ graph_built:
                const char *flags = obstack_finish(&ldflags_obst);
 
                /* construct commandline */
-               obstack_printf(&file_obst, "%s", LINKER);
+               const char *linker = getenv("CPARSER_LINK");
+               if (linker == NULL)
+                       linker = LINKER;
+               obstack_printf(&file_obst, "%s", linker);
                for (file_list_entry_t *entry = files; entry != NULL;
                                entry = entry->next) {
                        if (entry->type != FILETYPE_OBJECT)
@@ -1539,6 +1572,9 @@ graph_built:
                }
        }
 
+       if (do_timing)
+               timer_term(stderr);
+
        obstack_free(&cppflags_obst, NULL);
        obstack_free(&ldflags_obst, NULL);
        obstack_free(&file_obst, NULL);