#endif
#endif
-/** The current c mode/dialect. */
-unsigned int c_mode = _C89 | _ANSI | _C99 | _GNUC;
-
-/** The 'machine size', 16, 32 or 64 bit, 32bit is the default. */
-unsigned int machine_size = 32;
-
-/** true if the char type is signed. */
-bool char_is_signed = true;
-
-/** true for strict language checking. */
-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;
-
-atomic_type_kind_t wchar_atomic_kind = ATOMIC_TYPE_INT;
+unsigned int c_mode = _C89 | _ANSI | _C99 | _GNUC;
+unsigned int machine_size = 32;
+bool byte_order_big_endian = false;
+bool char_is_signed = true;
+bool strict_mode = false;
+bool use_builtins = false;
+bool have_const_functions = false;
+atomic_type_kind_t wchar_atomic_kind = ATOMIC_TYPE_INT;
/* to switch on printing of implicit casts */
extern bool print_implicit_casts;
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,
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, ' ');
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)
"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);
}
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")) {
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);
} 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);
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,");
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=")) {
}
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")) {
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);
} 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) {
streq(suffix, "o") ? FILETYPE_OBJECT :
streq(suffix, "s") ? FILETYPE_PREPROCESSED_ASSEMBLER :
streq(suffix, "so") ? FILETYPE_OBJECT :
- FILETYPE_AUTODETECT;
+ FILETYPE_OBJECT; /* gcc behavior: unknown file extension means object file */
}
}
-
- if (type == FILETYPE_AUTODETECT) {
- fprintf(stderr, "'%s': file format not recognized\n", arg);
- continue;
- }
}
file_list_entry_t *entry
}
}
+ 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;
c_mode &= ~features_off;
gen_firm_init();
+ byte_order_big_endian = be_get_backend_param()->byte_order_big_endian;
init_symbol_table();
init_types();
init_typehash();
}
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;
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:
exit(1);
}
- dump_ir_block_graph_file(irg, out);
+ dump_ir_graph_file(out, irg);
fclose(out);
exit(0);
}
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);
}