]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
adding opts_max_array_size with a default of 1024, adding some TODO errors for arrays...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 10:09:36 +0000 (11:09 +0100)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Sun, 11 Nov 2012 10:09:36 +0000 (11:09 +0100)
ast.c
gmqcc.h
main.c

diff --git a/ast.c b/ast.c
index f10dbb2f4f0688513a182a0d214e743f99cdc1e6..6417ae1bfbdcfe2788e678422f9bb71cb9d6ef49 100644 (file)
--- a/ast.c
+++ b/ast.c
@@ -909,14 +909,30 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
         return true;
     }
 
-    v = ir_builder_create_global(ir, self->name, self->expression.vtype);
-    if (!v) {
-        asterror(ast_ctx(self), "ir_builder_create_global failed");
-        return false;
+    if (self->expression.vtype == TYPE_ARRAY) {
+        size_t ai;
+        /* we are lame now - considering the way QC works we won't tolerate arrays > 1024 elements */
+        if (!self->expression.count || self->expression.count > opts_max_array_size) {
+            asterror(ast_ctx(self), "Invalid array of size %lu", (unsigned long)self->expression.count);
+        }
+        for (ai = 0; ai < self->expression.count; ++ai) {
+            asterror(ast_ctx(self), "TODO: array gen");
+        }
+    }
+    else
+    {
+        /* Arrays don't do this since there's no "array" value which spans across the
+         * whole thing.
+         */
+        v = ir_builder_create_global(ir, self->name, self->expression.vtype);
+        if (!v) {
+            asterror(ast_ctx(self), "ir_builder_create_global failed");
+            return false;
+        }
+        if (self->expression.vtype == TYPE_FIELD)
+            v->fieldtype = self->expression.next->expression.vtype;
+        v->context = ast_ctx(self);
     }
-    if (self->expression.vtype == TYPE_FIELD)
-        v->fieldtype = self->expression.next->expression.vtype;
-    v->context = ast_ctx(self);
 
     if (self->isconst) {
         switch (self->expression.vtype)
@@ -933,6 +949,9 @@ bool ast_global_codegen(ast_value *self, ir_builder *ir, bool isfield)
                 if (!ir_value_set_string(v, self->constval.vstring))
                     goto error;
                 break;
+            case TYPE_ARRAY:
+                asterror(ast_ctx(self), "TODO: global constant array");
+                break;
             case TYPE_FUNCTION:
                 asterror(ast_ctx(self), "global of type function not properly generated");
                 goto error;
@@ -965,6 +984,12 @@ bool ast_local_codegen(ast_value *self, ir_function *func, bool param)
         return false;
     }
 
+    if (self->expression.vtype == TYPE_ARRAY)
+    {
+        asterror(ast_ctx(self), "TODO: ast_local_codgen for TYPE_ARRAY");
+        return false;
+    }
+
     v = ir_function_create_local(func, self->name, self->expression.vtype, param);
     if (!v)
         return false;
diff --git a/gmqcc.h b/gmqcc.h
index 01ebd4a7b02a4fcdc5822d8fcc9a49105d2c2412..304cdaafe05eb27cb2668cbcf34d0fcaf7b2db04 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -1017,6 +1017,7 @@ extern bool        opts_werror;
 extern bool        opts_forcecrc;
 extern uint16_t    opts_forced_crc;
 extern bool        opts_pp_only;
+extern size_t      opts_max_array_size;
 
 /*===================================================================*/
 #define OPTS_FLAG(i) (!! (opts_flags[(i)/32] & (1<< ((i)%32))))
diff --git a/main.c b/main.c
index fbc54f235a90280fcd47f33a6f43b56970994869..773b08ed711e815c89da14e1c64235f649b49a2f 100644 (file)
--- a/main.c
+++ b/main.c
@@ -35,6 +35,7 @@ bool        opts_dump     = false;
 bool        opts_werror   = false;
 bool        opts_forcecrc = false;
 bool        opts_pp_only  = false;
+size_t      opts_max_array_size = 1024;
 
 uint16_t    opts_forced_crc;