prepare fields before generating globals so we avoid the need for relocating initialized fieldpointers

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-11-30 21:22:48 +01:00
parent 2a3e7c1cff
commit 2a2465c884
2 changed files with 16 additions and 17 deletions

31
ir.c
View file

@ -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
View file

@ -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 */