added the --add-info compile switch: it adds a global const string named version to the 'reserved' namespace, ie ends up named 'reserved:version', containing the --version string

This commit is contained in:
Wolfgang Bumiller 2013-01-11 19:18:51 +01:00
parent 6df3c625b0
commit 3436fa7d89
3 changed files with 42 additions and 0 deletions

20
gmqcc.h
View file

@ -48,6 +48,25 @@
/* Undefine the following on a release-tag: */
#define GMQCC_VERSION_TYPE_DEVEL
/* Full version string in case we need it */
#ifdef GMQCC_GITINFO
# define GMQCC_DEV_VERSION_STRING "git build: " GMQCC_GITINFO "\n"
#elif defined(GMQCC_VERSION_TYPE_DEVEL
# define GMQCC_DEV_VERSION_STRING "development build\n"
#else
# define GMQCC_DEV_VERSION_STRING
#endif
#define GMQCC_STRINGIFY(x) #x
#define GMQCC_IND_STRING(x) GMQCC_STRINGIFY(x)
#define GMQCC_FULL_VERSION_STRING \
"GMQCC " \
GMQCC_IND_STRING(GMQCC_VERSION_MAJOR) "." \
GMQCC_IND_STRING(GMQCC_VERSION_MINOR) "." \
GMQCC_IND_STRING(GMQCC_VERSION_PATCH) \
" Built " __DATE__ " " __TIME__ \
"\n" GMQCC_DEV_VERSION_STRING
/*
* We cannot rely on C99 at all, since compilers like MSVC
* simply don't support it. We define our own boolean type
@ -1129,6 +1148,7 @@ typedef struct {
uint16_t forced_crc; /* --force-crc= */
bool pp_only; /* -E */
size_t max_array_size; /* --max-array= */
bool add_info; /* --add-info */
uint32_t flags [1 + (COUNT_FLAGS / 32)];
uint32_t warn [1 + (COUNT_WARNINGS / 32)];

4
main.c
View file

@ -465,6 +465,10 @@ static bool options_parse(int argc, char **argv) {
opts.quiet = true;
break;
}
else if (!strcmp(argv[0]+2, "add-info")) {
opts.add_info = true;
break;
}
else {
/* All long options with arguments */
if (options_long_witharg("output", &argc, &argv, &argarg)) {

View file

@ -54,6 +54,7 @@ typedef struct {
ast_value *imm_float_one;
ast_value *imm_vector_zero;
ast_value *nil;
ast_value *reserved_version;
size_t crc_globals;
size_t crc_fields;
@ -5447,6 +5448,16 @@ bool parser_init()
parser->const_vec[0] = ast_value_new(empty_ctx, "<vector.x>", TYPE_NOEXPR);
parser->const_vec[1] = ast_value_new(empty_ctx, "<vector.y>", TYPE_NOEXPR);
parser->const_vec[2] = ast_value_new(empty_ctx, "<vector.z>", TYPE_NOEXPR);
if (opts.add_info) {
parser->reserved_version = ast_value_new(empty_ctx, "reserved:version", TYPE_STRING);
parser->reserved_version->cvq = CV_CONST;
parser->reserved_version->hasvalue = true;
parser->reserved_version->expression.flags |= AST_FLAG_INCLUDE_DEF;
parser->reserved_version->constval.vstring = util_strdup(GMQCC_FULL_VERSION_STRING);
} else {
parser->reserved_version = NULL;
}
return true;
}
@ -5632,6 +5643,13 @@ bool parser_finish(const char *output)
return false;
}
}
if (parser->reserved_version &&
!ast_global_codegen(parser->reserved_version, ir, false))
{
con_out("failed to generate reserved::version");
ir_builder_delete(ir);
return false;
}
for (i = 0; i < vec_size(parser->imm_float); ++i) {
if (!ast_global_codegen(parser->imm_float[i], ir, false)) {
con_out("failed to generate global %s\n", parser->imm_float[i]->name);