mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 03:50:36 +00:00
Added handler for -W
This commit is contained in:
parent
d06cc6c2d1
commit
3072ce7eba
3 changed files with 61 additions and 11 deletions
|
@ -35,6 +35,12 @@ Append the specified file which is to be interpreted as a \fIprogs.src\fR file.
|
|||
Use the specified standard for parsing QC code. The following standards are available:
|
||||
.IR gmqcc , qcc , fteqcc
|
||||
.TP
|
||||
.BI -W warning "\fR, " "" -Wno- warning
|
||||
Enable or disable a warning.
|
||||
.TP
|
||||
.B -Wall
|
||||
Enable all warnings. Overrides preceding -W parameters.
|
||||
.TP
|
||||
.B -fdarkplaces-string-table-bug
|
||||
Patch the output file to work around a string-table bug in certain darkplaces versions.
|
||||
.TP
|
||||
|
|
15
gmqcc.h
15
gmqcc.h
|
@ -994,10 +994,21 @@ enum {
|
|||
};
|
||||
static const opt_flag_def opt_flag_list[] = {
|
||||
{ "darkplaces-string-table-bug", LONGBIT(DP_STRING_TABLE_BUG) },
|
||||
{ "omit-nullbytes", LONGBIT(OMIT_NULLBYTES) },
|
||||
{ "omit-nullbytes", LONGBIT(OMIT_NULLBYTES) }
|
||||
};
|
||||
static const size_t opt_flag_list_count = sizeof(opt_flag_list) / sizeof(opt_flag_list[0]);
|
||||
|
||||
enum {
|
||||
WARN_UNUSED_VARIABLE,
|
||||
|
||||
NUM_W_FLAGS
|
||||
};
|
||||
static const opt_flag_def opt_warn_list[] = {
|
||||
/* only contains single flags, no groups like 'all' */
|
||||
{ "unused-variable", LONGBIT(WARN_UNUSED_VARIABLE) }
|
||||
};
|
||||
static const size_t opt_warn_list_count = sizeof(opt_warn_list) / sizeof(opt_warn_list[0]);
|
||||
|
||||
/* other options: */
|
||||
extern uint32_t opt_O; /* -Ox */
|
||||
extern const char *opt_output; /* -o file */
|
||||
|
@ -1012,5 +1023,7 @@ enum {
|
|||
/*===================================================================*/
|
||||
#define OPT_FLAG(i) (!! (opt_flags[(i)/32] & (1<< ((i)%32))))
|
||||
extern uint32_t opt_flags[1 + (NUM_F_FLAGS / 32)];
|
||||
#define OPT_WARN(i) (!! (opt_warn[(i)/32] & (1<< ((i)%32))))
|
||||
extern uint32_t opt_warn[1 + (NUM_W_FLAGS / 32)];
|
||||
|
||||
#endif
|
||||
|
|
51
main.c
51
main.c
|
@ -23,6 +23,7 @@
|
|||
#include "gmqcc.h"
|
||||
|
||||
uint32_t opt_flags[1 + (NUM_F_FLAGS / 32)];
|
||||
uint32_t opt_warn [1 + (NUM_W_FLAGS / 32)];
|
||||
|
||||
uint32_t opt_O = 1;
|
||||
const char *opt_output = "progs.dat";
|
||||
|
@ -44,12 +45,15 @@ static int usage() {
|
|||
" -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(" -fflag enable a flag\n"
|
||||
" -fno-flag disable a flag\n"
|
||||
printf(" -f<flag> enable a flag\n"
|
||||
" -fno-<flag> disable a flag\n"
|
||||
" -std standard select one of the following standards\n"
|
||||
" -std=qcc original QuakeC\n"
|
||||
" -std=fteqcc fteqcc QuakeC\n"
|
||||
" -std=gmqcc this compiler (default)\n");
|
||||
printf(" -W <warning> enable a warning\n"
|
||||
" -W no-<warning> disable a warning\n"
|
||||
" -Wall enable all warnings\n");
|
||||
printf("\n");
|
||||
printf("flags:\n"
|
||||
" -fdarkplaces-string-table-bug\n"
|
||||
|
@ -60,28 +64,34 @@ static int usage() {
|
|||
return -1;
|
||||
}
|
||||
|
||||
static bool options_setflag(const char *name, bool on) {
|
||||
static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opt_flag_def *list, size_t listsize) {
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < opt_flag_list_count; ++i) {
|
||||
if (!strcmp(name, opt_flag_list[i].name)) {
|
||||
longbit lb = opt_flag_list[i].bit;
|
||||
for (i = 0; i < listsize; ++i) {
|
||||
if (!strcmp(name, list[i].name)) {
|
||||
longbit lb = list[i].bit;
|
||||
#if 0
|
||||
if (on)
|
||||
opt_flags[lb.idx] |= (1<<(lb.bit));
|
||||
flags[lb.idx] |= (1<<(lb.bit));
|
||||
else
|
||||
opt_flags[lb.idx] &= ~(1<<(lb.bit));
|
||||
flags[lb.idx] &= ~(1<<(lb.bit));
|
||||
#else
|
||||
if (on)
|
||||
opt_flags[0] |= (1<<lb);
|
||||
flags[0] |= (1<<lb);
|
||||
else
|
||||
opt_flags[0] &= ~(1<<(lb));
|
||||
flags[0] &= ~(1<<(lb));
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
static bool options_setflag(const char *name, bool on) {
|
||||
return options_setflag_all(name, on, opt_flags, opt_flag_list, opt_flag_list_count);
|
||||
}
|
||||
static bool options_setwarn(const char *name, bool on) {
|
||||
return options_setflag_all(name, on, opt_warn, opt_warn_list, opt_warn_list_count);
|
||||
}
|
||||
|
||||
static bool options_witharg(int *argc_, char ***argv_, char **out) {
|
||||
int argc = *argc_;
|
||||
|
@ -135,6 +145,7 @@ static bool options_long_gcc(const char *optname, int *argc_, char ***argv_, cha
|
|||
|
||||
static bool options_parse(int argc, char **argv) {
|
||||
bool argend = false;
|
||||
size_t itr;
|
||||
while (!argend && argc > 1) {
|
||||
char *argarg;
|
||||
argitem item;
|
||||
|
@ -178,6 +189,23 @@ static bool options_parse(int argc, char **argv) {
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
case 'W':
|
||||
if (!strcmp(argv[0]+2, "all")) {
|
||||
for (itr = 0; itr < sizeof(opt_warn)/sizeof(opt_warn[0]); ++itr)
|
||||
opt_warn[itr] = 0xFFFFFFFFL;
|
||||
break;
|
||||
}
|
||||
if (!strncmp(argv[0]+2, "no-", 3)) {
|
||||
if (!options_setwarn(argv[0]+5, false)) {
|
||||
printf("unknown warning: %s\n", argv[0]+2);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!options_setwarn(argv[0]+2, true)) {
|
||||
printf("unknown warning: %s\n", argv[0]+2);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
if (!options_witharg(&argc, &argv, &argarg)) {
|
||||
|
@ -258,6 +286,9 @@ int main(int argc, char **argv) {
|
|||
for (itr = 0; itr < opt_flag_list_count; ++itr) {
|
||||
printf("Flag %s = %i\n", opt_flag_list[itr].name, OPT_FLAG(itr));
|
||||
}
|
||||
for (itr = 0; itr < opt_warn_list_count; ++itr) {
|
||||
printf("Warning %s = %i\n", opt_warn_list[itr].name, OPT_WARN(itr));
|
||||
}
|
||||
printf("output = %s\n", opt_output);
|
||||
printf("optimization level = %i\n", (int)opt_O);
|
||||
printf("standard = %i\n", opt_standard);
|
||||
|
|
Loading…
Reference in a new issue