/*
* This file is part of cparser.
- * Copyright (C) 2007-2008 Matthias Braun <matze@braunis.de>
+ * Copyright (C) 2007-2009 Matthias Braun <matze@braunis.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
FILETYPE_ASSEMBLER,
FILETYPE_PREPROCESSED_ASSEMBLER,
FILETYPE_OBJECT,
+ FILETYPE_IR,
FILETYPE_UNKNOWN
} filetype_t;
static void add_flag(struct obstack *obst, const char *format, ...)
{
- char buf[4096];
+ char buf[65536];
va_list ap;
va_start(ap, format);
}
}
if (flags[0] != '\0') {
- obstack_printf(&cppflags_obst, " %s", flags);
+ size_t len = strlen(flags);
+ obstack_1grow(&cppflags_obst, ' ');
+ obstack_grow(&cppflags_obst, flags, len);
}
add_flag(&cppflags_obst, fname);
static void assemble(const char *out, const char *in)
{
- char buf[4096];
+ char buf[65536];
snprintf(buf, sizeof(buf), "%s %s -o %s", ASSEMBLER, in, out);
if (verbose) {
ParseOnly,
Compile,
CompileDump,
+ CompileExportIR,
CompileAssemble,
CompileAssembleLink,
LexTest,
putchar(' ');
fputs(build, stdout);
}
- puts(")\n");
+ puts(")");
+ puts("This is free software; see the source for copying conditions. There is NO\n"
+ "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n");
}
static void set_be_option(const char *arg)
set_be_option("omitleaffp=1");
} else if (streq(opt, "no-omit-leaf-frame-pointer")) {
set_be_option("omitleaffp=0");
+ } else if (streq(opt, "rtd")) {
+ default_calling_convention = CC_STDCALL;
} else {
char *endptr;
long int value = strtol(opt, &endptr, 10);
}
dumpfunction = argv[i];
mode = CompileDump;
+ } else if (streq(option, "export-ir")) {
+ mode = CompileExportIR;
} else {
fprintf(stderr, "error: unknown argument '%s'\n", arg);
argument_errors = true;
streq(suffix, "cpp") ? FILETYPE_CXX :
streq(suffix, "cxx") ? FILETYPE_CXX :
streq(suffix, "h") ? FILETYPE_C :
+ streq(suffix, "ir") ? FILETYPE_IR :
streq(suffix, "o") ? FILETYPE_OBJECT :
streq(suffix, "s") ? FILETYPE_PREPROCESSED_ASSEMBLER :
streq(suffix, "so") ? FILETYPE_OBJECT :
/* we do the lowering in ast2firm */
firm_opt.lower_bitfields = FALSE;
+ /* set the c_mode here, types depends on it */
+ c_mode |= features_on;
+ c_mode &= ~features_off;
+
gen_firm_init();
init_symbol_table();
init_types();
".vcg");
outname = outnamebuf;
break;
+ case CompileExportIR:
+ get_output_name(outnamebuf, sizeof(outnamebuf), filename, ".ir");
+ outname = outnamebuf;
+ break;
case CompileAssembleLink:
#ifdef _WIN32
outname = "a.exe";
switch (standard) {
case STANDARD_ANSI:
case STANDARD_C89: c_mode = _C89; break;
- /* TODO ^v determine difference between these two */
+ /* TODO determine difference between these two */
case STANDARD_C90: c_mode = _C89; break;
case STANDARD_C99: c_mode = _C89 | _C99; break;
case STANDARD_GNU89: c_mode = _C89 | _GNUC; break;
do_parsing:
c_mode |= features_on;
c_mode &= ~features_off;
+
init_tokens();
translation_unit_t *const unit = do_parsing(in, filename);
translation_unit_to_firm(unit);
+graph_built:
if (mode == ParseOnly) {
continue;
}
exit(0);
}
+ if (mode == CompileExportIR) {
+ fclose(out);
+ ir_export(outname);
+ exit(0);
+ }
+
gen_firm_finish(asm_out, filename, /*c_mode=*/1,
have_const_functions);
if (asm_out != out) {
fclose(asm_out);
}
+ } else if (filetype == FILETYPE_IR) {
+ fclose(in);
+ ir_import(filename);
+ goto graph_built;
} else if (filetype == FILETYPE_PREPROCESSED_ASSEMBLER) {
copy_file(asm_out, in);
if (in == preprocessed_in) {