From 04db054466b6bfd05299cb2f25e4b3923d8823ea Mon Sep 17 00:00:00 2001 From: "Wolfgang (Blub) Bumiller" Date: Sat, 11 Aug 2012 16:08:38 +0200 Subject: [PATCH] -std=gmqcc should add a dot prefix to the globals for fields, the field itself doesn't use the dot prefix for its name though --- ir.c | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/ir.c b/ir.c index d007321..d831176 100644 --- a/ir.c +++ b/ir.c @@ -2570,13 +2570,42 @@ static bool ir_builder_gen_field(ir_builder *self, ir_value *field) def.type = field->vtype; def.offset = code_globals_elements; - def.name = field->code.name = code_genstring(field->name); + + /* create a global named the same as the field */ + if (opts_standard == COMPILER_GMQCC) { + /* in our standard, the global gets a dot prefix */ + size_t len = strlen(field->name); + char name[1024]; + + /* we really don't want to have to allocate this, and 1024 + * bytes is more than enough for a variable/field name + */ + if (len+2 >= sizeof(name)) { + printf("invalid field name size: %u\n", (unsigned int)len); + return false; + } + + name[0] = '.'; + strcpy(name+1, field->name); /* no strncpy - we used strlen above */ + name[len+1] = 0; + + def.name = code_genstring(name); + fld.name = def.name + 1; /* we reuse that string table entry */ + } else { + /* in plain QC, there cannot be a global with the same name, + * and so we also name the global the same. + * FIXME: fteqcc should create a global as well + * check if it actually uses the same name. Probably does + */ + def.name = code_genstring(field->name); + fld.name = def.name; + } + + field->code.name = def.name; if (code_defs_add(def) < 0) return false; - fld.name = def.name; - fld.offset = code_fields_elements; fld.type = field->fieldtype; if (fld.type == TYPE_VOID) { @@ -2584,10 +2613,12 @@ static bool ir_builder_gen_field(ir_builder *self, ir_value *field) return false; } + fld.offset = code_alloc_field(type_sizeof[field->fieldtype]); + if (code_fields_add(fld) < 0) return false; - if (!code_globals_add(code_alloc_field(type_sizeof[field->fieldtype]))) + if (!code_globals_add(fld.offset)) return false; ir_value_code_setaddr(field, code_globals_add(fld.offset)); -- 2.39.2