mirror of
https://github.com/DarkPlacesEngine/gmqcc.git
synced 2025-01-31 03:50:36 +00:00
prepare fields before generating globals so we avoid the need for relocating initialized fieldpointers
This commit is contained in:
parent
2a3e7c1cff
commit
2a2465c884
2 changed files with 16 additions and 17 deletions
31
ir.c
31
ir.c
|
@ -2448,25 +2448,12 @@ static bool gen_global_field(ir_value *global)
|
|||
return false;
|
||||
}
|
||||
|
||||
/* Now, in this case, a relocation would be impossible to code
|
||||
* since it looks like this:
|
||||
* .vector v = origin; <- parse error, wtf is 'origin'?
|
||||
* .vector origin;
|
||||
*
|
||||
* But we will need a general relocation support later anyway
|
||||
* for functions... might as well support that here.
|
||||
*/
|
||||
if (!fld->code.globaladdr) {
|
||||
irerror(global->context, "FIXME: Relocation support");
|
||||
return false;
|
||||
}
|
||||
|
||||
/* copy the field's value */
|
||||
ir_value_code_setaddr(global, vec_size(code_globals));
|
||||
vec_push(code_globals, code_globals[fld->code.globaladdr]);
|
||||
vec_push(code_globals, fld->code.fieldaddr);
|
||||
if (global->fieldtype == TYPE_VECTOR) {
|
||||
vec_push(code_globals, code_globals[fld->code.globaladdr]+1);
|
||||
vec_push(code_globals, code_globals[fld->code.globaladdr]+2);
|
||||
vec_push(code_globals, fld->code.fieldaddr+1);
|
||||
vec_push(code_globals, fld->code.fieldaddr+2);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -3120,6 +3107,11 @@ static bool ir_builder_gen_global(ir_builder *self, ir_value *global, bool isloc
|
|||
}
|
||||
}
|
||||
|
||||
static void ir_builder_prepare_field(ir_value *field)
|
||||
{
|
||||
field->code.fieldaddr = code_alloc_field(type_sizeof[field->fieldtype]);
|
||||
}
|
||||
|
||||
static bool ir_builder_gen_field(ir_builder *self, ir_value *field)
|
||||
{
|
||||
prog_section_def def;
|
||||
|
@ -3171,7 +3163,7 @@ static bool ir_builder_gen_field(ir_builder *self, ir_value *field)
|
|||
return false;
|
||||
}
|
||||
|
||||
fld.offset = code_alloc_field(type_sizeof[field->fieldtype]);
|
||||
fld.offset = field->code.fieldaddr;
|
||||
|
||||
vec_push(code_fields, fld);
|
||||
|
||||
|
@ -3193,6 +3185,11 @@ bool ir_builder_generate(ir_builder *self, const char *filename)
|
|||
|
||||
code_init();
|
||||
|
||||
for (i = 0; i < vec_size(self->fields); ++i)
|
||||
{
|
||||
ir_builder_prepare_field(self->fields[i]);
|
||||
}
|
||||
|
||||
for (i = 0; i < vec_size(self->globals); ++i)
|
||||
{
|
||||
if (!ir_builder_gen_global(self, self->globals[i], false)) {
|
||||
|
|
2
ir.h
2
ir.h
|
@ -67,6 +67,8 @@ typedef struct ir_value_s {
|
|||
int32_t local;
|
||||
/* added for members */
|
||||
int32_t addroffset;
|
||||
/* to generate field-addresses early */
|
||||
int32_t fieldaddr;
|
||||
} code;
|
||||
|
||||
/* for acessing vectors */
|
||||
|
|
Loading…
Reference in a new issue