X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=main.c;h=1dd4976e27a1b474c19fb071cb8c8bf1dc857ed8;hb=27f4ce3da8d78ff0e70afde834793e0ebd81a42a;hp=5328e65e8a3fbaa3e4225237b1e6d8ea75a1f74f;hpb=6e07bbe94f952214c2880bad0d239a53aa48153d;p=cparser diff --git a/main.c b/main.c index 5328e65..1dd4976 100644 --- a/main.c +++ b/main.c @@ -80,7 +80,11 @@ #include "warning.h" #ifndef PREPROCESSOR -#define PREPROCESSOR "cpp -std=c99 -U__WCHAR_TYPE__ -D__WCHAR_TYPE__=int -U__SIZE_TYPE__ -D__SIZE_TYPE__=__SIZE_TYPE__ -m32 -U__STRICT_ANSI__" +#ifdef __APPLE__ +#define PREPROCESSOR "gcc -E -std=c99 -U__WCHAR_TYPE__ -D__WCHAR_TYPE__=int -U__SIZE_TYPE__ -D__SIZE_TYPE__=unsigned\\ long -m32 -U__STRICT_ANSI__" +#else +#define PREPROCESSOR "cpp -std=c99 -U__WCHAR_TYPE__ -D__WCHAR_TYPE__=int -U__SIZE_TYPE__ -D__SIZE_TYPE__=unsigned\\ long -m32 -U__STRICT_ANSI__" +#endif #endif #ifndef LINKER @@ -88,8 +92,12 @@ #endif #ifndef ASSEMBLER +#ifdef __APPLE__ +#define ASSEMBLER "gcc -c -xassembler" +#else #define ASSEMBLER "as --32" #endif +#endif /** The current c mode/dialect. */ unsigned int c_mode = _C89|_C99|_GNUC; @@ -106,14 +114,19 @@ bool strict_mode = false; /** use builtins for some libc functions */ bool use_builtins = false; +/** we have extern function with const attribute. */ +bool have_const_functions = false; + /* to switch on printing of implicit casts */ extern bool print_implicit_casts; /* to switch on printing of parenthesis to indicate operator precedence */ extern bool print_parenthesis; -static int verbose; -static struct obstack cppflags_obst, ldflags_obst; +static int verbose; +static struct obstack cppflags_obst, ldflags_obst; +static char dep_target[1024]; +static const char *outname; typedef struct file_list_entry_t file_list_entry_t; @@ -253,11 +266,25 @@ static void add_flag(struct obstack *obst, const char *format, ...) static FILE *preprocess(const char *fname) { - char buf[4096]; obstack_1grow(&cppflags_obst, '\0'); const char *flags = obstack_finish(&cppflags_obst); - snprintf(buf, sizeof(buf), PREPROCESSOR " %s %s", flags, fname); + obstack_printf(&cppflags_obst, "%s", PREPROCESSOR); + if (dep_target[0] != '\0') { + add_flag(&cppflags_obst, "-MF"); + add_flag(&cppflags_obst, "%s", dep_target); + if (outname != NULL) { + add_flag(&cppflags_obst, "-MQ"); + add_flag(&cppflags_obst, "%s", outname); + } + } + if (flags[0] != '\0') { + obstack_printf(&cppflags_obst, " %s", flags); + } + add_flag(&cppflags_obst, "%s", fname); + + obstack_1grow(&cppflags_obst, '\0'); + const char *buf = obstack_finish(&cppflags_obst); if(verbose) { puts(buf); } @@ -267,6 +294,7 @@ static FILE *preprocess(const char *fname) fprintf(stderr, "invoking preprocessor failed\n"); exit(1); } + return f; } @@ -486,14 +514,14 @@ int main(int argc, char **argv) { initialize_firm(); - const char *outname = NULL; - const char *dumpfunction = NULL; - compile_mode_t mode = CompileAssembleLink; - int opt_level = 1; - int result = EXIT_SUCCESS; - char cpu_arch[16] = "ia32"; - file_list_entry_t *files = NULL; - file_list_entry_t *last_file = NULL; + const char *dumpfunction = NULL; + compile_mode_t mode = CompileAssembleLink; + int opt_level = 1; + int result = EXIT_SUCCESS; + char cpu_arch[16] = "ia32"; + file_list_entry_t *files = NULL; + file_list_entry_t *last_file = NULL; + bool construct_dep_target = false; struct obstack file_obst; obstack_init(&cppflags_obst); @@ -542,11 +570,11 @@ int main(int argc, char **argv) default: case 4: set_option("strict-aliasing"); + /* use_builtins = true; */ /* fallthrough */ case 3: set_option("cond-eval"); set_option("if-conv"); - use_builtins = true; /* fallthrough */ case 2: set_option("inline"); @@ -555,6 +583,11 @@ int main(int argc, char **argv) break; } +#ifdef __APPLE__ + /* Darwin expects the stack to be aligned to 16byte boundary */ + firm_be_option("ia32-stackalign=4"); +#endif + /* parse rest of options */ filetype_t forced_filetype = FILETYPE_AUTODETECT; bool help_displayed = false; @@ -614,8 +647,10 @@ int main(int argc, char **argv) mode = PreprocessOnly; add_flag(&cppflags_obst, "-M"); } else if (streq(option, "MMD") || - streq(option, "MD") || - streq(option, "MM") || + streq(option, "MD")) { + construct_dep_target = true; + add_flag(&cppflags_obst, "-%s", option); + } else if(streq(option, "MM") || streq(option, "MP")) { add_flag(&cppflags_obst, "-%s", option); } else if (streq(option, "MT") || @@ -631,42 +666,50 @@ int main(int argc, char **argv) char const *orig_opt; GET_ARG_AFTER(orig_opt, "-f"); - char const *opt = orig_opt; - bool truth_value = true; - if (opt[0] == 'n' && opt[1] == 'o' && opt[2] == '-') { - truth_value = false; - opt += 3; - } - - if (streq(opt, "dollars-in-identifiers")) { - allow_dollar_in_symbol = truth_value; - } else if (streq(opt, "short-wchar")) { - opt_short_wchar_t = truth_value; - } else if (streq(opt, "syntax-only")) { - mode = ParseOnly; - } else if (streq(opt, "omit-frame-pointer")) { - set_be_option(truth_value ? "omitfp" : "omitfp=no"); - } else if (streq(opt, "strength-reduce")) { - firm_option("strength-red"); - } else if (streq(opt, "fast-math") || - streq(opt, "jump-tables") || - streq(opt, "unroll-loops") || - streq(opt, "expensive-optimizations") || - streq(opt, "common") || - streq(opt, "PIC") || - strstart(opt, "align-loops=") || - strstart(opt, "align-jumps=") || - strstart(opt, "align-functions=")) { + 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 { - int res = firm_option(orig_opt); - if (res == 0) { - fprintf(stderr, "error: unknown Firm option '-f%s'\n", - orig_opt); - argument_errors = true; - continue; - } else if (res == -1) { - help_displayed = true; + char const *opt = orig_opt; + bool truth_value = true; + if (opt[0] == 'n' && opt[1] == 'o' && opt[2] == '-') { + truth_value = false; + opt += 3; + } + + if (streq(opt, "dollars-in-identifiers")) { + allow_dollar_in_symbol = truth_value; + } if (streq(opt, "builtins")) { + use_builtins = truth_value; + } else if (streq(opt, "short-wchar")) { + opt_short_wchar_t = truth_value; + } else if (streq(opt, "syntax-only")) { + mode = truth_value ? ParseOnly : CompileAssembleLink; + } else if (streq(opt, "omit-frame-pointer")) { + set_be_option(truth_value ? "omitfp" : "omitfp=no"); + } else if (streq(opt, "strength-reduce")) { + firm_option(truth_value ? "strength-red" : "no-strength-red"); + } else if (streq(opt, "fast-math") || + streq(opt, "jump-tables") || + streq(opt, "unroll-loops") || + streq(opt, "expensive-optimizations") || + streq(opt, "common") || + streq(opt, "PIC") || + streq(opt, "align-loops") || + streq(opt, "align-jumps") || + streq(opt, "align-functions")) { + fprintf(stderr, "ignoring gcc option '-f%s'\n", orig_opt); + } else { + int res = firm_option(orig_opt); + if (res == 0) { + fprintf(stderr, "error: unknown Firm option '-f%s'\n", + orig_opt); + argument_errors = true; + continue; + } else if (res == -1) { + help_displayed = true; + } } } } else if (option[0] == 'b') { @@ -906,6 +949,16 @@ int main(int argc, char **argv) init_parser(); init_ast2firm(); + if (construct_dep_target) { + if (outname != 0 && strlen(outname) >= 2) { + get_output_name(dep_target, sizeof(dep_target), outname, ".d"); + } else { + get_output_name(dep_target, sizeof(dep_target), files->name, ".d"); + } + } else { + dep_target[0] = '\0'; + } + char outnamebuf[4096]; if (outname == NULL) { const char *filename = files->name; @@ -1081,7 +1134,7 @@ int main(int argc, char **argv) } gen_firm_finish(asm_out, filename, /*c_mode=*/1, - /*firm_const_exists=*/0); + have_const_functions); if (asm_out != out) { fclose(asm_out); }