#include "lexer.h"
uint32_t opts_flags[1 + (COUNT_FLAGS / 32)];
-uint32_t opts_warn [1 + (COUNT_WARNINGS / 32)];
+uint32_t opts_optimization[1 + (COUNT_OPTIMIZATIONS / 32)];
+
+/* counter increased in ir.c */
+unsigned int optimization_count[COUNT_OPTIMIZATIONS];
uint32_t opts_O = 1;
const char *opts_output = "progs.dat";
int opts_standard = COMPILER_GMQCC;
bool opts_debug = false;
bool opts_memchk = false;
+bool opts_dumpfin = false;
bool opts_dump = false;
-bool opts_werror = false;
bool opts_forcecrc = false;
bool opts_pp_only = false;
size_t opts_max_array_size = 1024;
static bool options_setwarn(const char *name, bool on) {
return options_setflag_all(name, on, opts_warn, opts_warn_list, COUNT_WARNINGS);
}
+static bool options_setoptim(const char *name, bool on) {
+ return options_setflag_all(name, on, opts_optimization, opts_opt_list, COUNT_OPTIMIZATIONS);
+}
static bool options_witharg(int *argc_, char ***argv_, char **out) {
int argc = *argc_;
#endif
}
+static void set_optimizations(unsigned int level)
+{
+ size_t i;
+ for (i = 0; i < COUNT_OPTIMIZATIONS; ++i)
+ options_set(opts_optimization, i, level >= opts_opt_oflag[i]);
+}
+
static bool options_parse(int argc, char **argv) {
bool argend = false;
size_t itr;
opts_standard = COMPILER_GMQCC;
} else if (!strcmp(argarg, "qcc")) {
options_set(opts_flags, ADJUST_VECTOR_FIELDS, false);
+ options_set(opts_flags, ASSIGN_FUNCTION_TYPES, true);
opts_standard = COMPILER_QCC;
} else if (!strcmp(argarg, "fte") || !strcmp(argarg, "fteqcc")) {
options_set(opts_flags, FTEPP, true);
+ options_set(opts_flags, TRANSLATABLE_STRINGS, true);
options_set(opts_flags, ADJUST_VECTOR_FIELDS, false);
+ options_set(opts_flags, ASSIGN_FUNCTION_TYPES, true);
opts_standard = COMPILER_FTEQCC;
} else if (!strcmp(argarg, "qccx")) {
options_set(opts_flags, ADJUST_VECTOR_FIELDS, false);
continue;
}
if (options_long_gcc("redirout", &argc, &argv, &redirout)) {
+ con_change(redirout, redirerr);
continue;
}
if (options_long_gcc("redirerr", &argc, &argv, &redirerr)) {
+ con_change(redirout, redirerr);
continue;
}
-
- con_change(redirout, redirerr);
+
+ /* show defaults (like pathscale) */
+ if (!strcmp(argv[0]+1, "show-defaults")) {
+ size_t itr;
+ char buffer[1024];
+ for (itr = 0; itr < COUNT_FLAGS; ++itr) {
+ if (!OPTS_FLAG(itr))
+ continue;
+
+ memset(buffer, 0, sizeof(buffer));
+ util_strtononcmd(opts_flag_list[itr].name, buffer, strlen(opts_flag_list[itr].name) + 1);
+
+ con_out("-f%s ", buffer);
+ }
+ for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
+ if (!OPTS_WARN(itr))
+ continue;
+
+ memset(buffer, 0, sizeof(buffer));
+ util_strtononcmd(opts_warn_list[itr].name, buffer, strlen(opts_warn_list[itr].name) + 1);
+ con_out("-W%s ", buffer);
+ }
+ con_out("\n");
+ exit(0);
+ }
if (!strcmp(argv[0]+1, "debug")) {
opts_debug = true;
opts_dump = true;
continue;
}
+ if (!strcmp(argv[0]+1, "dumpfin")) {
+ opts_dumpfin = true;
+ continue;
+ }
if (!strcmp(argv[0]+1, "memchk")) {
opts_memchk = true;
continue;
case 'h':
usage();
exit(0);
- break;
+ /* break; never reached because of exit(0) */
case 'E':
opts_pp_only = true;
/* handle all -fflags */
case 'f':
util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
- if (!strcmp(argv[0]+2, "HELP")) {
+ if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
con_out("Possible flags:\n");
for (itr = 0; itr < COUNT_FLAGS; ++itr) {
util_strtononcmd(opts_flag_list[itr].name, buffer, sizeof(buffer));
break;
case 'W':
util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
- if (!strcmp(argv[0]+2, "HELP")) {
+ if (!strcmp(argv[0]+2, "HELP") || *(argv[0]+2) == '?') {
con_out("Possible warnings:\n");
for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
util_strtononcmd(opts_warn_list[itr].name, buffer, sizeof(buffer));
case 'O':
if (!options_witharg(&argc, &argv, &argarg)) {
- con_out("option -O requires a numerical argument\n");
+ con_out("option -O requires a numerical argument, or optimization name with an optional 'no-' prefix\n");
return false;
}
- opts_O = atoi(argarg);
+ if (isdigit(argarg[0])) {
+ opts_O = atoi(argarg);
+ set_optimizations(opts_O);
+ } else {
+ util_strtocmd(argarg, argarg, strlen(argarg)+1);
+ if (!strcmp(argarg, "HELP")) {
+ con_out("Possible optimizations:\n");
+ for (itr = 0; itr < COUNT_OPTIMIZATIONS; ++itr) {
+ util_strtononcmd(opts_opt_list[itr].name, buffer, sizeof(buffer));
+ con_out(" -O%s\n", buffer);
+ }
+ exit(0);
+ }
+ else if (!strcmp(argarg, "ALL"))
+ set_optimizations(opts_O = 9999);
+ else if (!strncmp(argarg, "NO_", 3)) {
+ if (!options_setoptim(argarg+3, false)) {
+ con_out("unknown optimization: %s\n", argarg+3);
+ return false;
+ }
+ }
+ else {
+ if (!options_setoptim(argarg, true)) {
+ con_out("unknown optimization: %s\n", argarg);
+ return false;
+ }
+ }
+ }
break;
case 'o':
else
{
/* it's a QC filename */
- argitem item;
item.filename = argv[0];
item.type = TYPE_QC;
vec_push(items, item);
options_set(opts_warn, WARN_ASSIGN_FUNCTION_TYPES, true);
options_set(opts_warn, WARN_PREPROCESSOR, true);
options_set(opts_warn, WARN_MULTIFILE_IF, true);
+ options_set(opts_warn, WARN_DOUBLE_DECLARATION, true);
+ options_set(opts_warn, WARN_CONST_VAR, true);
+ options_set(opts_warn, WARN_MULTIBYTE_CHARACTER, true);
options_set(opts_flags, ADJUST_VECTOR_FIELDS, true);
options_set(opts_flags, FTEPP, false);
if (opts_standard == COMPILER_GMQCC) {
operators = c_operators;
operator_count = c_operator_count;
+ } else if (opts_standard == COMPILER_FTEQCC) {
+ operators = fte_operators;
+ operator_count = fte_operator_count;
} else {
operators = qcc_operators;
operator_count = qcc_operator_count;
}
if (opts_pp_only) {
+ const char *out;
if (!ftepp_preprocess_file(items[itr].filename)) {
retval = 1;
goto cleanup;
}
- fprintf(outfile, "%s", ftepp_get());
+ out = ftepp_get();
+ if (out)
+ fprintf(outfile, "%s", out);
ftepp_flush();
}
else {