adding opts_max_array_size with a default of 1024, adding some TODO errors for arrays in the AST

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-11-11 11:09:36 +01:00
parent 62d062f860
commit a7d3a2d6ea
3 changed files with 34 additions and 7 deletions

39
ast.c
View file

@ -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;

View file

@ -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))))

1
main.c
View file

@ -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;