Rename qfo_reloc_t's def to target and correct its usage.

This commit is contained in:
Bill Currie 2011-02-27 11:37:01 +09:00
parent c8f1b5b1f0
commit 8b661bbb89
4 changed files with 47 additions and 33 deletions

View file

@ -234,7 +234,7 @@ typedef struct qfo_reloc_s {
pr_int_t space; ///< index of space holding data to be adjusted pr_int_t space; ///< index of space holding data to be adjusted
pr_int_t offset; ///< offset of the relocation pr_int_t offset; ///< offset of the relocation
pr_int_t type; ///< type of the relocation (::reloc_type) pr_int_t type; ///< type of the relocation (::reloc_type)
pr_int_t def; ///< "def" this relocation is for pr_int_t target; ///< def/func/etc this relocation is for
} qfo_reloc_t; } qfo_reloc_t;
/** In-memory representation of a QFO space /** In-memory representation of a QFO space

View file

@ -269,10 +269,10 @@ qfo_relocs (qfo_t *qfo)
case rel_op_a_def: case rel_op_a_def:
case rel_op_b_def: case rel_op_b_def:
case rel_op_c_def: case rel_op_c_def:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->target;
printf (" op.%c@%d def#%d %s", printf (" op.%c@%d def#%d %s",
reloc->type - rel_op_a_def + 'a', reloc->type - rel_op_a_def + 'a',
reloc->offset, reloc->def, reloc->offset, reloc->target,
QFO_GETSTR (qfo, def->name)); QFO_GETSTR (qfo, def->name));
break; break;
case rel_op_a_op: case rel_op_a_op:
@ -283,22 +283,22 @@ qfo_relocs (qfo_t *qfo)
break; break;
case rel_def_op: case rel_def_op:
printf (" def@%d:%x op@%d", reloc->space, reloc->offset, printf (" def@%d:%x op@%d", reloc->space, reloc->offset,
reloc->def); reloc->target);
break; break;
case rel_def_def: case rel_def_def:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->target;
printf (" def@%d:%x def#%d %s", reloc->space, reloc->offset, printf (" def@%d:%x def#%d %s", reloc->space, reloc->offset,
reloc->def, QFO_GETSTR (qfo, def->name)); reloc->target, QFO_GETSTR (qfo, def->name));
break; break;
case rel_def_func: case rel_def_func:
//func = qfo->funcs + reloc->def; func = qfo->funcs + reloc->target;
func = qfo->funcs + QFO_FUNCTION (qfo, reloc->space, //func = qfo->funcs + QFO_FUNCTION (qfo, reloc->space,
reloc->offset); // reloc->offset);
printf (" def@%d:%x func#%d %s %x", printf (" def@%d:%x func#%d %s %x",
reloc->space, reloc->offset, reloc->space, reloc->offset,
QFO_FUNCTION (qfo, reloc->space, reloc->offset), QFO_FUNCTION (qfo, reloc->space, reloc->offset),
QFO_GETSTR (qfo, func->name), QFO_GETSTR (qfo, func->name),
reloc->def); reloc->target);
break; break;
case rel_def_string: case rel_def_string:
printf (" def@%d:%x string:%x `%s'", printf (" def@%d:%x string:%x `%s'",
@ -307,31 +307,31 @@ qfo_relocs (qfo_t *qfo)
QFO_GSTRING (qfo, reloc->space, reloc->offset)); QFO_GSTRING (qfo, reloc->space, reloc->offset));
break; break;
case rel_def_field: case rel_def_field:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->target;
printf (" def@%d:%x def#%d %s", reloc->space, reloc->offset, printf (" def@%d:%x def#%d %s", reloc->space, reloc->offset,
reloc->def, QFO_GETSTR (qfo, def->name)); reloc->target, QFO_GETSTR (qfo, def->name));
break; break;
case rel_op_a_def_ofs: case rel_op_a_def_ofs:
case rel_op_b_def_ofs: case rel_op_b_def_ofs:
case rel_op_c_def_ofs: case rel_op_c_def_ofs:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->target;
printf (" op.%c@%x def#%d %s", printf (" op.%c@%x def#%d %s",
reloc->type - rel_op_a_def_ofs + 'a', reloc->type - rel_op_a_def_ofs + 'a',
reloc->offset, reloc->def, reloc->offset, reloc->target,
QFO_GETSTR (qfo, def->name)); QFO_GETSTR (qfo, def->name));
break; break;
case rel_def_def_ofs: case rel_def_def_ofs:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->target;
printf (" def@%d:%x def#%d+%d %s+%d", printf (" def@%d:%x def#%d+%d %s+%d",
reloc->space, reloc->offset, reloc->def, reloc->space, reloc->offset, reloc->target,
QFO_INT (qfo, reloc->space, reloc->offset), QFO_INT (qfo, reloc->space, reloc->offset),
QFO_GETSTR (qfo, def->name), QFO_GETSTR (qfo, def->name),
QFO_INT (qfo, reloc->space, reloc->offset)); QFO_INT (qfo, reloc->space, reloc->offset));
break; break;
case rel_def_field_ofs: case rel_def_field_ofs:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->target;
printf (" def@%d:%x def#%d+%d %s+%d", printf (" def@%d:%x def#%d+%d %s+%d",
reloc->space, reloc->offset, reloc->def, reloc->space, reloc->offset, reloc->target,
QFO_INT (qfo, reloc->space, reloc->offset), QFO_INT (qfo, reloc->space, reloc->offset),
QFO_GETSTR (qfo, def->name), QFO_GETSTR (qfo, def->name),
QFO_INT (qfo, reloc->space, reloc->offset)); QFO_INT (qfo, reloc->space, reloc->offset));

View file

@ -185,7 +185,7 @@ update_relocs (qfo_t *qfo)
} else { } else {
reloc->space += work->num_spaces; reloc->space += work->num_spaces;
} }
reloc->def += work->num_defs; reloc->target += work->num_defs; //FIXME wrong
} }
} }

View file

@ -57,6 +57,7 @@ static __attribute__ ((used)) const char rcsid[] = "$Id$";
#include "options.h" #include "options.h"
#include "qfcc.h" #include "qfcc.h"
#include "reloc.h" #include "reloc.h"
#include "statements.h"
#include "strpool.h" #include "strpool.h"
#include "symtab.h" #include "symtab.h"
#include "type.h" #include "type.h"
@ -92,22 +93,28 @@ qfo_def_flags (def_t *def)
return flags; return flags;
} }
static void
qfo_encode_one_reloc (reloc_t *reloc, qfo_reloc_t **qfo_reloc, pr_int_t target)
{
qfo_reloc_t *q;
q = (*qfo_reloc)++;
if (reloc->space) // op_* relocs do not have a space (code is implied)
q->space = reloc->space->qfo_space;
q->offset = reloc->offset;
q->type = reloc->type;
q->target = target;
}
static int static int
qfo_encode_relocs (qfo_t *qfo, reloc_t *relocs, qfo_reloc_t **qfo_relocs, qfo_encode_relocs (reloc_t *relocs, qfo_reloc_t **qfo_relocs, pr_int_t target)
qfo_def_t *def)
{ {
int count; int count;
reloc_t *r; reloc_t *r;
qfo_reloc_t *q;
for (count = 0, r = relocs; r; r = r->next) { for (count = 0, r = relocs; r; r = r->next) {
count++; count++;
q = (*qfo_relocs)++; qfo_encode_one_reloc (r, qfo_relocs, target);
if (r->space) // op_* relocs do not have a space (code is implied)
q->space = r->space->qfo_space;
q->offset = r->offset;
q->type = r->type;
q->def = def - qfo->defs;
} }
return count; return count;
} }
@ -130,7 +137,8 @@ qfo_encode_defs (qfo_t *qfo, def_t *defs, qfo_def_t **qfo_defs,
q->name = ReuseString (d->name); q->name = ReuseString (d->name);
q->offset = d->offset; q->offset = d->offset;
q->relocs = *qfo_relocs - qfo->relocs; q->relocs = *qfo_relocs - qfo->relocs;
q->num_relocs = qfo_encode_relocs (qfo, d->relocs, qfo_relocs, q); q->num_relocs = qfo_encode_relocs (d->relocs, qfo_relocs,
q - qfo->defs);
q->flags = qfo_def_flags (d); q->flags = qfo_def_flags (d);
q->file = d->file; q->file = d->file;
q->line = d->line; q->line = d->line;
@ -256,7 +264,7 @@ qfo_encode_functions (qfo_t *qfo, qfo_def_t **defs, qfo_reloc_t **relocs,
if (f->aux) if (f->aux)
q->line_info = f->aux->line_info; q->line_info = f->aux->line_info;
q->relocs = *relocs - qfo->relocs; q->relocs = *relocs - qfo->relocs;
q->num_relocs = qfo_encode_relocs (qfo, f->refs, relocs, 0); q->num_relocs = qfo_encode_relocs (f->refs, relocs, q - qfo->funcs);
} }
} }
@ -266,6 +274,7 @@ qfo_from_progs (pr_info_t *pr)
qfo_t *qfo; qfo_t *qfo;
qfo_def_t *def; qfo_def_t *def;
qfo_reloc_t *reloc; qfo_reloc_t *reloc;
reloc_t *r;
qfo = calloc (1, sizeof (qfo_t)); qfo = calloc (1, sizeof (qfo_t));
qfo->num_spaces = qfo_num_spaces; // certain spaces are always present qfo->num_spaces = qfo_num_spaces; // certain spaces are always present
@ -297,7 +306,12 @@ qfo_from_progs (pr_info_t *pr)
qfo_init_string_space (qfo, &qfo->spaces[qfo_strings_space], pr->strings); qfo_init_string_space (qfo, &qfo->spaces[qfo_strings_space], pr->strings);
qfo->num_loose_relocs = qfo->num_relocs - (reloc - qfo->relocs); qfo->num_loose_relocs = qfo->num_relocs - (reloc - qfo->relocs);
qfo_encode_relocs (qfo, pr->relocs, &reloc, 0); for (r = pr->relocs; r; r = r->next) {
if (r->type == rel_def_op)
qfo_encode_one_reloc (r, &reloc, r->label->dest->offset);
else
qfo_encode_one_reloc (r, &reloc, 0);
}
return qfo; return qfo;
} }
@ -416,7 +430,7 @@ qfo_write (qfo_t *qfo, const char *filename)
relocs[i].space = LittleLong (qfo->relocs[i].space); relocs[i].space = LittleLong (qfo->relocs[i].space);
relocs[i].offset = LittleLong (qfo->relocs[i].offset); relocs[i].offset = LittleLong (qfo->relocs[i].offset);
relocs[i].type = LittleLong (qfo->relocs[i].type); relocs[i].type = LittleLong (qfo->relocs[i].type);
relocs[i].def = LittleLong (qfo->relocs[i].def); relocs[i].target = LittleLong (qfo->relocs[i].target);
} }
for (i = 0; i < qfo->num_defs; i++) { for (i = 0; i < qfo->num_defs; i++) {
defs[i].type = LittleLong (qfo->defs[i].type); defs[i].type = LittleLong (qfo->defs[i].type);
@ -504,7 +518,7 @@ qfo_read (QFile *file)
qfo->relocs[i].space = LittleLong (qfo->relocs[i].space); qfo->relocs[i].space = LittleLong (qfo->relocs[i].space);
qfo->relocs[i].offset = LittleLong (qfo->relocs[i].offset); qfo->relocs[i].offset = LittleLong (qfo->relocs[i].offset);
qfo->relocs[i].type = LittleLong (qfo->relocs[i].type); qfo->relocs[i].type = LittleLong (qfo->relocs[i].type);
qfo->relocs[i].def = LittleLong (qfo->relocs[i].def); qfo->relocs[i].target = LittleLong (qfo->relocs[i].target);
} }
for (i = 0; i < qfo->num_defs; i++) { for (i = 0; i < qfo->num_defs; i++) {
qfo->defs[i].type = LittleLong (qfo->defs[i].type); qfo->defs[i].type = LittleLong (qfo->defs[i].type);