From a7d3a2d6ea4d921046702de5839840f8a4f69bf5 Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Sun, 11 Nov 2012 11:09:36 +0100 Subject: [PATCH] adding opts_max_array_size with a default of 1024, adding some TODO errors for arrays in the AST --- ast.c | 39 ++++++++++++++++++++++++++++++++------- gmqcc.h | 1 + main.c | 1 + 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/ast.c b/ast.c index f10dbb2..6417ae1 100644 --- 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 01ebd4a..304cdaa 100644 --- 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 fbc54f2..773b08e 100644 --- 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; -- 2.39.2