From: Wolfgang Bumiller Date: Sat, 28 Jul 2012 17:20:19 +0000 (+0200) Subject: reuse old opts_, renamed all opt_ to opts_ to be consistent, making code.c use OPTS_F... X-Git-Tag: 0.1-rc1~366^2~4 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=c81eb57480ccb652bf990abc7cd2cd8671187e32;p=xonotic%2Fgmqcc.git reuse old opts_, renamed all opt_ to opts_ to be consistent, making code.c use OPTS_FLAG() for OMIT_NULL_BYTES and DARKPLACES_STRING_TABLE_BUG --- diff --git a/code.c b/code.c index d11db04..0cb373b 100644 --- a/code.c +++ b/code.c @@ -69,7 +69,7 @@ void code_init() { int i = 0; /* omit creation of null code */ - if (opts_omit_nullcode) + if (OPTS_FLAG(OMIT_NULL_BYTES)) return; /* @@ -158,7 +158,7 @@ bool code_write(const char *filename) { size_t it = 2; /* see proposal.txt */ - if (opts_omit_nullcode) {} + if (OPTS_FLAG(OMIT_NULL_BYTES)) {} code_header.statements.offset = sizeof(prog_header); code_header.statements.length = code_statements_elements; code_header.defs.offset = code_header.statements.offset + (sizeof(prog_section_statement) * code_statements_elements); @@ -175,7 +175,7 @@ bool code_write(const char *filename) { code_header.crc16 = 0; /* TODO: */ code_header.entfield = 0; /* TODO: */ - if (opts_darkplaces_stringtablebug) { + if (OPTS_FLAG(DARKPLACES_STRING_TABLE_BUG)) { util_debug("GEN", "Patching stringtable for -fdarkplaces-stringtablebug\n"); /* >= + P */ diff --git a/gmqcc.h b/gmqcc.h index c52db8a..3910159 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -671,20 +671,6 @@ void asm_init (const char *, FILE **); void asm_close(FILE *); void asm_parse(FILE *); /*===================================================================*/ -/*============================= main.c ==============================*/ -/*===================================================================*/ -enum { - COMPILER_QCC, /* circa QuakeC */ - COMPILER_FTEQCC, /* fteqcc QuakeC */ - COMPILER_QCCX, /* qccx QuakeC */ - COMPILER_GMQCC /* this QuakeC */ -}; -extern bool opts_debug; -extern bool opts_memchk; -extern bool opts_darkplaces_stringtablebug; -extern bool opts_omit_nullcode; -extern int opts_compiler; -/*===================================================================*/ /*============================= ast.c ===============================*/ /*===================================================================*/ #define MEM_VECTOR_PROTO(Towner, Tmem, mem) \ @@ -982,7 +968,7 @@ typedef uint32_t longbit; typedef struct { const char *name; longbit bit; -} opt_flag_def; +} opts_flag_def; /*===================================================================*/ /* list of -f flags, like -fdarkplaces-string-table-bug */ @@ -992,7 +978,7 @@ enum { # undef GMQCC_DEFINE_FLAG COUNT_FLAGS }; -static const opt_flag_def opt_flag_list[] = { +static const opts_flag_def opts_flag_list[] = { # define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) }, # include "flags.def" # undef GMQCC_DEFINE_FLAG @@ -1005,7 +991,7 @@ enum { # undef GMQCC_DEFINE_FLAG COUNT_WARNINGS }; -static const opt_flag_def opt_warn_list[] = { +static const opts_flag_def opts_warn_list[] = { # define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) }, # include "warns.def" # undef GMQCC_DEFINE_FLAG @@ -1013,20 +999,22 @@ static const opt_flag_def opt_warn_list[] = { }; /* other options: */ -extern uint32_t opt_O; /* -Ox */ -extern const char *opt_output; /* -o file */ -extern int opt_standard; - enum { - STD_DEF, - STD_QCC, - STD_FTE + COMPILER_QCC, /* circa QuakeC */ + COMPILER_FTEQCC, /* fteqcc QuakeC */ + COMPILER_QCCX, /* qccx QuakeC */ + COMPILER_GMQCC /* this QuakeC */ }; +extern uint32_t opts_O; /* -Ox */ +extern const char *opts_output; /* -o file */ +extern int opts_standard; +extern bool opts_debug; +extern bool opts_memchk; /*===================================================================*/ -#define OPT_FLAG(i) (!! (opt_flags[(i)/32] & (1<< ((i)%32)))) -extern uint32_t opt_flags[1 + (COUNT_FLAGS / 32)]; -#define OPT_WARN(i) (!! (opt_warn[(i)/32] & (1<< ((i)%32)))) -extern uint32_t opt_warn[1 + (COUNT_WARNINGS / 32)]; +#define OPTS_FLAG(i) (!! (opts_flags[(i)/32] & (1<< ((i)%32)))) +extern uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; +#define OPTS_WARN(i) (!! (opts_warn[(i)/32] & (1<< ((i)%32)))) +extern uint32_t opts_warn[1 + (COUNT_WARNINGS / 32)]; #endif diff --git a/main.c b/main.c index cf78b1e..ca404f9 100644 --- a/main.c +++ b/main.c @@ -22,12 +22,14 @@ */ #include "gmqcc.h" -uint32_t opt_flags[1 + (COUNT_FLAGS / 32)]; -uint32_t opt_warn [1 + (COUNT_WARNINGS / 32)]; +uint32_t opts_flags[1 + (COUNT_FLAGS / 32)]; +uint32_t opts_warn [1 + (COUNT_WARNINGS / 32)]; -uint32_t opt_O = 1; -const char *opt_output = "progs.dat"; -int opt_standard = STD_DEF; +uint32_t opts_O = 1; +const char *opts_output = "progs.dat"; +int opts_standard = COMPILER_GMQCC; +bool opts_debug = false; +bool opts_memchk = false; typedef struct { char *filename; int type; } argitem; VECTOR_MAKE(argitem, items); @@ -42,7 +44,9 @@ static int usage() { printf("usage: %s [options] [files...]", app_name); printf("options:\n" " -h, --help show this help message\n" - " -o, --output=file output file, defaults to progs.dat\n" + " -debug turns on compiler debug messages\n" + " -memchk turns on compiler memory leak check\n"); + printf(" -o, --output=file output file, defaults to progs.dat\n" " -a filename add an asm file to be assembled\n" " -s filename add a progs.src file to be used\n"); printf(" -f enable a flag\n" @@ -94,7 +98,7 @@ static void strtononcmd(char *buf, const char *str) *buf = 0; } -static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opt_flag_def *list, size_t listsize) { +static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) { size_t i; for (i = 0; i < listsize; ++i) { @@ -117,10 +121,10 @@ static bool options_setflag_all(const char *name, bool on, uint32_t *flags, cons return false; } static bool options_setflag(const char *name, bool on) { - return options_setflag_all(name, on, opt_flags, opt_flag_list, COUNT_FLAGS); + return options_setflag_all(name, on, opts_flags, opts_flag_list, COUNT_FLAGS); } static bool options_setwarn(const char *name, bool on) { - return options_setflag_all(name, on, opt_warn, opt_warn_list, COUNT_WARNINGS); + return options_setflag_all(name, on, opts_warn, opts_warn_list, COUNT_WARNINGS); } static bool options_witharg(int *argc_, char ***argv_, char **out) { @@ -188,17 +192,27 @@ static bool options_parse(int argc, char **argv) { /* All gcc-type long options */ if (options_long_gcc("std", &argc, &argv, &argarg)) { if (!strcmp(argarg, "gmqcc") || !strcmp(argarg, "default")) - opt_standard = STD_DEF; + opts_standard = COMPILER_GMQCC; else if (!strcmp(argarg, "qcc")) - opt_standard = STD_QCC; + opts_standard = COMPILER_QCC; else if (!strcmp(argarg, "fte") || !strcmp(argarg, "fteqcc")) - opt_standard = STD_FTE; + opts_standard = COMPILER_FTEQCC; + else if (!strcmp(argarg, "qccx")) + opts_standard = COMPILER_QCCX; else { printf("Unknown standard: %s\n", argarg); return false; } continue; } + if (!strcmp(argv[0]+1, "debug")) { + opts_debug = true; + continue; + } + if (!strcmp(argv[0]+1, "memchk")) { + opts_memchk = true; + continue; + } switch (argv[0][1]) { /* -h, show usage but exit with 0 */ @@ -213,7 +227,7 @@ static bool options_parse(int argc, char **argv) { if (!strcmp(argv[0]+2, "HELP")) { printf("Possible flags:\n"); for (itr = 0; itr < COUNT_FLAGS; ++itr) { - strtononcmd(buffer, opt_flag_list[itr].name); + strtononcmd(buffer, opts_flag_list[itr].name); printf(" -f%s\n", buffer); } exit(0); @@ -234,14 +248,14 @@ static bool options_parse(int argc, char **argv) { if (!strcmp(argv[0]+2, "HELP")) { printf("Possible warnings:\n"); for (itr = 0; itr < COUNT_WARNINGS; ++itr) { - strtononcmd(buffer, opt_warn_list[itr].name); + strtononcmd(buffer, opts_warn_list[itr].name); printf(" -W%s\n", buffer); } exit(0); } else if (!strcmp(argv[0]+2, "all")) { - for (itr = 0; itr < sizeof(opt_warn)/sizeof(opt_warn[0]); ++itr) - opt_warn[itr] = 0xFFFFFFFFL; + for (itr = 0; itr < sizeof(opts_warn)/sizeof(opts_warn[0]); ++itr) + opts_warn[itr] = 0xFFFFFFFFL; break; } if (!strncmp(argv[0]+2, "no-", 3)) { @@ -261,7 +275,7 @@ static bool options_parse(int argc, char **argv) { printf("option -O requires a numerical argument\n"); return false; } - opt_O = atoi(argarg); + opts_O = atoi(argarg); break; case 'o': @@ -269,7 +283,7 @@ static bool options_parse(int argc, char **argv) { printf("option -o requires an argument: the output file name\n"); return false; } - opt_output = argarg; + opts_output = argarg; break; case 'a': @@ -298,7 +312,7 @@ static bool options_parse(int argc, char **argv) { else { /* All long options with arguments */ if (options_long_witharg("output", &argc, &argv, &argarg)) - opt_output = argarg; + opts_output = argarg; else { printf("Unknown parameter: %s\n", argv[0]); @@ -333,14 +347,14 @@ int main(int argc, char **argv) { } for (itr = 0; itr < COUNT_FLAGS; ++itr) { - printf("Flag %s = %i\n", opt_flag_list[itr].name, OPT_FLAG(itr)); + printf("Flag %s = %i\n", opts_flag_list[itr].name, OPTS_FLAG(itr)); } for (itr = 0; itr < COUNT_WARNINGS; ++itr) { - printf("Warning %s = %i\n", opt_warn_list[itr].name, OPT_WARN(itr)); + printf("Warning %s = %i\n", opts_warn_list[itr].name, OPTS_WARN(itr)); } - printf("output = %s\n", opt_output); - printf("optimization level = %i\n", (int)opt_O); - printf("standard = %i\n", opt_standard); + printf("output = %s\n", opts_output); + printf("optimization level = %i\n", (int)opts_O); + printf("standard = %i\n", opts_standard); if (items_elements) { printf("Mode: manual\n"); diff --git a/util.c b/util.c index 3275ad8..3a347b4 100644 --- a/util.c +++ b/util.c @@ -370,11 +370,3 @@ int util_getline(char **lineptr, size_t *n, FILE *stream) { *pos = '\0'; return (ret = pos - *lineptr); } - -/* TODO: opts.c? when it gets large enugh */ -/* global options */ -bool opts_debug = false; -bool opts_memchk = false; -bool opts_darkplaces_stringtablebug = false; -bool opts_omit_nullcode = false; -int opts_compiler = COMPILER_GMQCC;