mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-19 06:40:49 +00:00
flags.def and warns.def containing defined flags and warnings
This commit is contained in:
parent
17643c9940
commit
25e49a669d
4 changed files with 80 additions and 30 deletions
7
flags.def
Normal file
7
flags.def
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#ifndef GMQCC_DEFINE_FLAG
|
||||||
|
#define GMQCC_DEFINE_FLAG(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
GMQCC_DEFINE_FLAG(OVERLAP_LOCALS)
|
||||||
|
GMQCC_DEFINE_FLAG(DARKPLACES_STRING_TABLE_BUG)
|
||||||
|
GMQCC_DEFINE_FLAG(OMIT_NULL_BYTES)
|
35
gmqcc.h
35
gmqcc.h
|
@ -987,29 +987,30 @@ typedef struct {
|
||||||
/*===================================================================*/
|
/*===================================================================*/
|
||||||
/* list of -f flags, like -fdarkplaces-string-table-bug */
|
/* list of -f flags, like -fdarkplaces-string-table-bug */
|
||||||
enum {
|
enum {
|
||||||
OVERLAP_LOCALS,
|
# define GMQCC_DEFINE_FLAG(X) X,
|
||||||
DP_STRING_TABLE_BUG,
|
# include "flags.def"
|
||||||
OMIT_NULLBYTES,
|
# undef GMQCC_DEFINE_FLAG
|
||||||
|
COUNT_FLAGS
|
||||||
NUM_F_FLAGS
|
|
||||||
};
|
};
|
||||||
static const opt_flag_def opt_flag_list[] = {
|
static const opt_flag_def opt_flag_list[] = {
|
||||||
{ "overlap-locals", LONGBIT(OVERLAP_LOCALS) },
|
# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) },
|
||||||
{ "darkplaces-string-table-bug", LONGBIT(DP_STRING_TABLE_BUG) },
|
# include "flags.def"
|
||||||
{ "omit-nullbytes", LONGBIT(OMIT_NULLBYTES) }
|
# undef GMQCC_DEFINE_FLAG
|
||||||
|
{ NULL, LONGBIT(0) }
|
||||||
};
|
};
|
||||||
static const size_t opt_flag_list_count = sizeof(opt_flag_list) / sizeof(opt_flag_list[0]);
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
WARN_UNUSED_VARIABLE,
|
# define GMQCC_DEFINE_FLAG(X) X,
|
||||||
|
# include "warns.def"
|
||||||
NUM_W_FLAGS
|
# undef GMQCC_DEFINE_FLAG
|
||||||
|
COUNT_WARNINGS
|
||||||
};
|
};
|
||||||
static const opt_flag_def opt_warn_list[] = {
|
static const opt_flag_def opt_warn_list[] = {
|
||||||
/* only contains single flags, no groups like 'all' */
|
# define GMQCC_DEFINE_FLAG(X) { #X, LONGBIT(X) },
|
||||||
{ "unused-variable", LONGBIT(WARN_UNUSED_VARIABLE) }
|
# include "warns.def"
|
||||||
|
# undef GMQCC_DEFINE_FLAG
|
||||||
|
{ NULL, LONGBIT(0) }
|
||||||
};
|
};
|
||||||
static const size_t opt_warn_list_count = sizeof(opt_warn_list) / sizeof(opt_warn_list[0]);
|
|
||||||
|
|
||||||
/* other options: */
|
/* other options: */
|
||||||
extern uint32_t opt_O; /* -Ox */
|
extern uint32_t opt_O; /* -Ox */
|
||||||
|
@ -1024,8 +1025,8 @@ enum {
|
||||||
|
|
||||||
/*===================================================================*/
|
/*===================================================================*/
|
||||||
#define OPT_FLAG(i) (!! (opt_flags[(i)/32] & (1<< ((i)%32))))
|
#define OPT_FLAG(i) (!! (opt_flags[(i)/32] & (1<< ((i)%32))))
|
||||||
extern uint32_t opt_flags[1 + (NUM_F_FLAGS / 32)];
|
extern uint32_t opt_flags[1 + (COUNT_FLAGS / 32)];
|
||||||
#define OPT_WARN(i) (!! (opt_warn[(i)/32] & (1<< ((i)%32))))
|
#define OPT_WARN(i) (!! (opt_warn[(i)/32] & (1<< ((i)%32))))
|
||||||
extern uint32_t opt_warn[1 + (NUM_W_FLAGS / 32)];
|
extern uint32_t opt_warn[1 + (COUNT_WARNINGS / 32)];
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
63
main.c
63
main.c
|
@ -22,8 +22,8 @@
|
||||||
*/
|
*/
|
||||||
#include "gmqcc.h"
|
#include "gmqcc.h"
|
||||||
|
|
||||||
uint32_t opt_flags[1 + (NUM_F_FLAGS / 32)];
|
uint32_t opt_flags[1 + (COUNT_FLAGS / 32)];
|
||||||
uint32_t opt_warn [1 + (NUM_W_FLAGS / 32)];
|
uint32_t opt_warn [1 + (COUNT_WARNINGS / 32)];
|
||||||
|
|
||||||
uint32_t opt_O = 1;
|
uint32_t opt_O = 1;
|
||||||
const char *opt_output = "progs.dat";
|
const char *opt_output = "progs.dat";
|
||||||
|
@ -64,6 +64,36 @@ static int usage() {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void strtocmd(char *str)
|
||||||
|
{
|
||||||
|
for(; *str; ++str) {
|
||||||
|
if (*str == '-') {
|
||||||
|
*str = '_';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isalpha(*str) && !isupper(*str)) {
|
||||||
|
*str += 'A' - 'a';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void strtononcmd(char *buf, const char *str)
|
||||||
|
{
|
||||||
|
for(; *str; ++buf, ++str) {
|
||||||
|
if (*str == '_') {
|
||||||
|
*buf = '-';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (isalpha(*str) && isupper(*str)) {
|
||||||
|
*buf = *str + 'a' - 'A';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
*buf = *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 opt_flag_def *list, size_t listsize) {
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
@ -87,10 +117,10 @@ static bool options_setflag_all(const char *name, bool on, uint32_t *flags, cons
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
static bool options_setflag(const char *name, bool on) {
|
static bool options_setflag(const char *name, bool on) {
|
||||||
return options_setflag_all(name, on, opt_flags, opt_flag_list, opt_flag_list_count);
|
return options_setflag_all(name, on, opt_flags, opt_flag_list, COUNT_FLAGS);
|
||||||
}
|
}
|
||||||
static bool options_setwarn(const char *name, bool on) {
|
static bool options_setwarn(const char *name, bool on) {
|
||||||
return options_setflag_all(name, on, opt_warn, opt_warn_list, opt_warn_list_count);
|
return options_setflag_all(name, on, opt_warn, opt_warn_list, COUNT_WARNINGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool options_witharg(int *argc_, char ***argv_, char **out) {
|
static bool options_witharg(int *argc_, char ***argv_, char **out) {
|
||||||
|
@ -146,6 +176,7 @@ static bool options_long_gcc(const char *optname, int *argc_, char ***argv_, cha
|
||||||
static bool options_parse(int argc, char **argv) {
|
static bool options_parse(int argc, char **argv) {
|
||||||
bool argend = false;
|
bool argend = false;
|
||||||
size_t itr;
|
size_t itr;
|
||||||
|
char buffer[1024];
|
||||||
while (!argend && argc > 1) {
|
while (!argend && argc > 1) {
|
||||||
char *argarg;
|
char *argarg;
|
||||||
argitem item;
|
argitem item;
|
||||||
|
@ -178,13 +209,16 @@ static bool options_parse(int argc, char **argv) {
|
||||||
|
|
||||||
/* handle all -fflags */
|
/* handle all -fflags */
|
||||||
case 'f':
|
case 'f':
|
||||||
if (!strcmp(argv[0]+2, "help")) {
|
strtocmd(argv[0]+2);
|
||||||
|
if (!strcmp(argv[0]+2, "HELP")) {
|
||||||
printf("Possible flags:\n");
|
printf("Possible flags:\n");
|
||||||
for (itr = 0; itr < opt_flag_list_count; ++itr)
|
for (itr = 0; itr < COUNT_FLAGS; ++itr) {
|
||||||
printf(" -f%s\n", opt_flag_list[itr].name);
|
strtononcmd(buffer, opt_flag_list[itr].name);
|
||||||
|
printf(" -f%s\n", buffer);
|
||||||
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
else if (!strncmp(argv[0]+2, "no-", 3)) {
|
else if (!strncmp(argv[0]+2, "NO-", 3)) {
|
||||||
if (!options_setflag(argv[0]+5, false)) {
|
if (!options_setflag(argv[0]+5, false)) {
|
||||||
printf("unknown flag: %s\n", argv[0]+2);
|
printf("unknown flag: %s\n", argv[0]+2);
|
||||||
return false;
|
return false;
|
||||||
|
@ -196,10 +230,13 @@ static bool options_parse(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'W':
|
case 'W':
|
||||||
if (!strcmp(argv[0]+2, "help")) {
|
strtocmd(argv[0]+2);
|
||||||
|
if (!strcmp(argv[0]+2, "HELP")) {
|
||||||
printf("Possible warnings:\n");
|
printf("Possible warnings:\n");
|
||||||
for (itr = 0; itr < opt_warn_list_count; ++itr)
|
for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
|
||||||
printf(" -W%s\n", opt_warn_list[itr].name);
|
strtononcmd(buffer, opt_warn_list[itr].name);
|
||||||
|
printf(" -W%s\n", buffer);
|
||||||
|
}
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[0]+2, "all")) {
|
else if (!strcmp(argv[0]+2, "all")) {
|
||||||
|
@ -295,10 +332,10 @@ int main(int argc, char **argv) {
|
||||||
return usage();
|
return usage();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (itr = 0; itr < opt_flag_list_count; ++itr) {
|
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", opt_flag_list[itr].name, OPT_FLAG(itr));
|
||||||
}
|
}
|
||||||
for (itr = 0; itr < opt_warn_list_count; ++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", opt_warn_list[itr].name, OPT_WARN(itr));
|
||||||
}
|
}
|
||||||
printf("output = %s\n", opt_output);
|
printf("output = %s\n", opt_output);
|
||||||
|
|
5
warns.def
Normal file
5
warns.def
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#ifndef GMQCC_DEFINE_FLAG
|
||||||
|
#define GMQCC_DEFINE_FLAG(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
GMQCC_DEFINE_FLAG(UNUSED_VARIABLE)
|
Loading…
Reference in a new issue