]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
added the --add-info compile switch: it adds a global const string named version...
authorWolfgang Bumiller <blub@speed.at>
Fri, 11 Jan 2013 18:18:51 +0000 (19:18 +0100)
committerWolfgang Bumiller <blub@speed.at>
Fri, 11 Jan 2013 18:18:51 +0000 (19:18 +0100)
gmqcc.h
main.c
parser.c

diff --git a/gmqcc.h b/gmqcc.h
index 1f0e066815a06655587e2240b10c320cabcf45b8..f0d5c99c0f544e4019382b432223a73711362e86 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
 /* 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)];
diff --git a/main.c b/main.c
index d14acf0b828024c7c2af0a1902d69d5d36fae0f7..ff67262186a0c87c65c650585c2c05ea12020d33 100644 (file)
--- a/main.c
+++ b/main.c
@@ -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)) {
index e38cedae42fe4624d009ab404a42c2bc13d77cb2..5fa0d899f201d9948e2f971eb3126a8c33841582 100644 (file)
--- a/parser.c
+++ b/parser.c
@@ -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);