Create structures for new qfo format.

This breaks a lot of existing code, so that code has been commented out
for now.
This commit is contained in:
Bill Currie 2011-02-17 15:02:09 +09:00
parent 9c9a71f1af
commit bceb98e5a4
4 changed files with 244 additions and 226 deletions

View file

@ -62,28 +62,40 @@
typedef struct qfo_header_s { typedef struct qfo_header_s {
int8_t qfo[4]; ///< identifier string (includes nul) (#QFO) int8_t qfo[4]; ///< identifier string (includes nul) (#QFO)
pr_int_t version; ///< QFO format version (#QFO_VERSION) pr_int_t version; ///< QFO format version (#QFO_VERSION)
pr_int_t code_size; ///< number of instructions in code section pr_int_t num_spaces;
pr_int_t data_size; ///< number of words in data section
pr_int_t far_data_size; ///< number of words in far data section
pr_int_t strings_size; ///< number of chars in strings section
pr_int_t num_relocs; ///< number of relocation records pr_int_t num_relocs; ///< number of relocation records
pr_int_t num_defs; ///< number of def records pr_int_t num_defs; ///< number of def records
pr_int_t num_funcs; ///< number of function records pr_int_t num_funcs; ///< number of function records
pr_int_t num_lines; ///< number of line records pr_int_t num_lines; ///< number of line records
pr_int_t types_size; ///< number of chars in type strings section
/** Number of entity field words defined by the object file. There is no
corresponding section in the object file.
*/
pr_int_t entity_fields;
} qfo_header_t; } qfo_header_t;
typedef enum qfos_type_e {
qfos_null, ///< null space. no data or defs. first in qfo
qfos_code, ///< progs code. dstatement_t data
qfos_data, ///< progs data. pr_type_t data
qfos_string, ///< strings. char data
qfos_entity, ///< entity field defs. no data
qfos_type, ///< type encodings
} qfos_type_t;
/** Representation of a space in the object file.
*/
typedef struct qfo_space_s {
pr_int_t type; ///< code, string, data, entity...
pr_int_t defs; ///< index of first def
pr_int_t num_defs; ///< not used for code or string spaces
pr_int_t data; ///< byte offset in qfo
pr_int_t data_size; ///< in elements. not used for entity spaces
pr_int_t id;
} qfo_space_t;
/** Representation of a def in the object file. /** Representation of a def in the object file.
*/ */
typedef struct qfo_def_s { typedef struct qfo_def_s {
etype_t basic_type; ///< type of def as seen by the VM pr_int_t type; ///< offset in type space
string_t full_type; ///< full type string, encoded by encode_type()
string_t name; ///< def name string_t name; ///< def name
pr_int_t ofs; ///< def offset (address) pr_int_t space; ///< index of space holding this def's data
pr_int_t offset; ///< def offset (address)
pr_int_t relocs; ///< index of first reloc record pr_int_t relocs; ///< index of first reloc record
pr_int_t num_relocs; ///< number of reloc records pr_int_t num_relocs; ///< number of reloc records
@ -240,22 +252,31 @@ typedef struct qfo_func_s {
the referenced field def. the referenced field def.
*/ */
typedef struct qfo_reloc_s { typedef struct qfo_reloc_s {
pr_int_t ofs; ///< offset of the relocation pr_int_t space; ///< index of space holding data to be adjusted
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 def; ///< "def" this relocation is for
} qfo_reloc_t; } qfo_reloc_t;
/** In-memory representation of a QFO space
*/
typedef struct qfo_mspace_s {
qfos_type_t type;
qfo_def_t *defs;
int num_defs;
union {
dstatement_t *code;
pr_type_t *data;
char *strings;
} d;
int id;
} qfo_mspace_t;
/** In-memory representation of a QFO object file. /** In-memory representation of a QFO object file.
*/ */
typedef struct qfo_s { typedef struct qfo_s {
dstatement_t *code; qfo_space_t *spaces;
int code_size; int num_spaces;
pr_type_t *data;
int data_size;
pr_type_t *far_data;
int far_data_size;
char *strings;
int strings_size;
qfo_reloc_t *relocs; qfo_reloc_t *relocs;
int num_relocs; int num_relocs;
qfo_def_t *defs; qfo_def_t *defs;
@ -264,9 +285,6 @@ typedef struct qfo_s {
int num_funcs; int num_funcs;
pr_lineno_t *lines; pr_lineno_t *lines;
int num_lines; int num_lines;
char *types;
int types_size;
int entity_fields;
} qfo_t; } qfo_t;
//@} //@}

View file

@ -205,23 +205,23 @@ dump_functions (progs_t *pr)
} }
} }
static const char * //static const char *
flags_string (pr_uint_t flags) //flags_string (pr_uint_t flags)
{ //{
static dstring_t *str; // static dstring_t *str;
if (!str) // if (!str)
str = dstring_newstr (); // str = dstring_newstr ();
dstring_clearstr (str); // dstring_clearstr (str);
dstring_appendstr (str, (flags & QFOD_INITIALIZED) ? "I" : "-"); // dstring_appendstr (str, (flags & QFOD_INITIALIZED) ? "I" : "-");
dstring_appendstr (str, (flags & QFOD_CONSTANT) ? "C" : "-"); // dstring_appendstr (str, (flags & QFOD_CONSTANT) ? "C" : "-");
dstring_appendstr (str, (flags & QFOD_ABSOLUTE) ? "A" : "-"); // dstring_appendstr (str, (flags & QFOD_ABSOLUTE) ? "A" : "-");
dstring_appendstr (str, (flags & QFOD_GLOBAL) ? "G" : "-"); // dstring_appendstr (str, (flags & QFOD_GLOBAL) ? "G" : "-");
dstring_appendstr (str, (flags & QFOD_EXTERNAL) ? "E" : "-"); // dstring_appendstr (str, (flags & QFOD_EXTERNAL) ? "E" : "-");
dstring_appendstr (str, (flags & QFOD_LOCAL) ? "L" : "-"); // dstring_appendstr (str, (flags & QFOD_LOCAL) ? "L" : "-");
dstring_appendstr (str, (flags & QFOD_SYSTEM) ? "S" : "-"); // dstring_appendstr (str, (flags & QFOD_SYSTEM) ? "S" : "-");
dstring_appendstr (str, (flags & QFOD_NOSAVE) ? "N" : "-"); // dstring_appendstr (str, (flags & QFOD_NOSAVE) ? "N" : "-");
return str->str; // return str->str;
} //}
void void
qfo_globals (qfo_t *qfo) qfo_globals (qfo_t *qfo)
@ -231,11 +231,11 @@ qfo_globals (qfo_t *qfo)
for (i = 0; i < qfo->num_defs; i++) { for (i = 0; i < qfo->num_defs; i++) {
def = &qfo->defs[i]; def = &qfo->defs[i];
printf ("%-5d %-5d %s %s %s", i, def->ofs, flags_string (def->flags), // printf ("%-5d %-5d %s %s %s", i, def->offset, flags_string (def->flags),
QFO_GETSTR (qfo, def->name), // QFO_GETSTR (qfo, def->name),
QFO_TYPESTR (qfo, def->full_type)); // QFO_TYPESTR (qfo, def->full_type));
if (!(def->flags & QFOD_EXTERNAL)) // if (!(def->flags & QFOD_EXTERNAL))
printf (" %d", qfo->data[def->ofs].integer_var); // printf (" %d", qfo->data[def->offset].integer_var);
puts (""); puts ("");
} }
} }
@ -264,59 +264,59 @@ qfo_relocs (qfo_t *qfo)
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->def;
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->ofs, def->ofs, QFO_GETSTR (qfo, def->name)); // reloc->offset, def->offset, QFO_GETSTR (qfo, def->name));
break; break;
case rel_op_a_op: case rel_op_a_op:
case rel_op_b_op: case rel_op_b_op:
case rel_op_c_op: case rel_op_c_op:
printf (" op.%c op@%d", reloc->type - rel_op_a_def + 'a', printf (" op.%c op@%d", reloc->type - rel_op_a_def + 'a',
reloc->ofs); reloc->offset);
break; break;
case rel_def_op: case rel_def_op:
printf (" def@%d op@%d", reloc->ofs, reloc->def); printf (" def@%d op@%d", reloc->offset, reloc->def);
break; break;
case rel_def_def: case rel_def_def:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->def;
printf (" def@%d def@%d %s", reloc->ofs, reloc->def, // printf (" def@%d def@%d %s", reloc->offset, reloc->def,
QFO_GETSTR (qfo, def->name)); // QFO_GETSTR (qfo, def->name));
break; break;
case rel_def_func: case rel_def_func:
func = qfo->funcs + reloc->def; func = qfo->funcs + reloc->def;
printf (" def@%d func@%d %s", reloc->ofs, reloc->def, // printf (" def@%d func@%d %s", reloc->offset, reloc->def,
QFO_GETSTR (qfo, func->name)); // QFO_GETSTR (qfo, func->name));
break; break;
case rel_def_string: case rel_def_string:
printf (" def@%d string:`%s'", reloc->ofs, // printf (" def@%d string:`%s'", reloc->offset,
QFO_GSTRING (qfo, reloc->ofs)); // QFO_GSTRING (qfo, reloc->offset));
break; break;
case rel_def_field: case rel_def_field:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->def;
printf (" def@%d def@%d %s", reloc->ofs, reloc->def, // printf (" def@%d def@%d %s", reloc->offset, reloc->def,
QFO_GETSTR (qfo, def->name)); // 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->def;
printf (" op.%c@%d def@%d %s", // printf (" op.%c@%d def@%d %s",
reloc->type - rel_op_a_def_ofs + 'a', // reloc->type - rel_op_a_def_ofs + 'a',
reloc->ofs, def->ofs, QFO_GETSTR (qfo, def->name)); // reloc->offset, def->offset, 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->def;
printf (" def@%d def@%d+%d %s+%d", reloc->ofs, reloc->def, // printf (" def@%d def@%d+%d %s+%d", reloc->offset, reloc->def,
qfo->data[reloc->ofs].integer_var, // qfo->data[reloc->offset].integer_var,
QFO_GETSTR (qfo, def->name), // QFO_GETSTR (qfo, def->name),
qfo->data[reloc->ofs].integer_var); // qfo->data[reloc->offset].integer_var);
break; break;
case rel_def_field_ofs: case rel_def_field_ofs:
def = qfo->defs + reloc->def; def = qfo->defs + reloc->def;
printf (" def@%d def@%d+%d %s+%d", reloc->ofs, reloc->def, // printf (" def@%d def@%d+%d %s+%d", reloc->offset, reloc->def,
qfo->data[reloc->ofs].integer_var, // qfo->data[reloc->offset].integer_var,
QFO_GETSTR (qfo, def->name), // QFO_GETSTR (qfo, def->name),
qfo->data[reloc->ofs].integer_var); // qfo->data[reloc->offset].integer_var);
break; break;
} }
if (def && def->flags & QFOD_EXTERNAL) if (def && def->flags & QFOD_EXTERNAL)
@ -341,12 +341,12 @@ qfo_functions (qfo_t *qfo)
for (i = 0; i < qfo->num_funcs; i++) { for (i = 0; i < qfo->num_funcs; i++) {
func = &qfo->funcs[i]; func = &qfo->funcs[i];
def = &qfo->defs[func->def]; def = &qfo->defs[func->def];
printf ("%-5d %-5d %s %s %d %s", i, def->ofs, // printf ("%-5d %-5d %s %s %d %s", i, def->offset,
flags_string (def->flags), // flags_string (def->flags),
QFO_GETSTR (qfo, func->name), func->def, // QFO_GETSTR (qfo, func->name), func->def,
QFO_GETSTR (qfo, def->name)); // QFO_GETSTR (qfo, def->name));
if (!(def->flags & QFOD_EXTERNAL)) // if (!(def->flags & QFOD_EXTERNAL))
printf (" %d", qfo->data[def->ofs].integer_var); // printf (" %d", qfo->data[def->offset].integer_var);
if (func->code) if (func->code)
printf (" @ %x", func->code); printf (" @ %x", func->code);
else else

View file

@ -164,7 +164,7 @@ Xgroup_add(reloc); // relocgroup_add_relocs
Xgroup_add(func); // funcgroup_add_funcs Xgroup_add(func); // funcgroup_add_funcs
static void def_error (qfo_def_t *def, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); static void def_error (qfo_def_t *def, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
static void def_warning (qfo_def_t *def, const char *fmt, ...) __attribute__ ((format (printf, 2, 3))); //static void def_warning (qfo_def_t *def, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
static defref_t * static defref_t *
get_defref (qfo_def_t *def, defgroup_t *defgroup) get_defref (qfo_def_t *def, defgroup_t *defgroup)
@ -195,10 +195,10 @@ defs_get_key (void *_defref, void *_defgroup)
static void static void
add_strings (qfo_t *qfo) add_strings (qfo_t *qfo)
{ {
int i; // int i;
for (i = 0; i < qfo->strings_size; i += strlen (qfo->strings + i) + 1) // for (i = 0; i < qfo->strings_size; i += strlen (qfo->strings + i) + 1)
strpool_addstr (strings, qfo->strings + i); // strpool_addstr (strings, qfo->strings + i);
} }
static void static void
@ -218,7 +218,7 @@ add_relocs (qfo_t *qfo)
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:
reloc->ofs += code_base; reloc->offset += code_base;
break; break;
case rel_op_a_op: case rel_op_a_op:
case rel_op_b_op: case rel_op_b_op:
@ -226,40 +226,40 @@ add_relocs (qfo_t *qfo)
// these are relative and fixed up before the .qfo is written // these are relative and fixed up before the .qfo is written
break; break;
case rel_def_op: case rel_def_op:
reloc->ofs += data_base; reloc->offset += data_base;
reloc->def += code_base; reloc->def += code_base;
break; break;
case rel_def_func: case rel_def_func:
reloc->ofs += data_base; reloc->offset += data_base;
reloc->def += func_base; reloc->def += func_base;
break; break;
case rel_def_def: case rel_def_def:
case rel_def_def_ofs: case rel_def_def_ofs:
reloc->ofs += data_base; reloc->offset += data_base;
break; break;
case rel_def_string: case rel_def_string:
reloc->ofs += data_base; reloc->offset += data_base;
DATA (reloc->ofs)->string_var = // DATA (reloc->offset)->string_var =
strpool_addstr (strings, // strpool_addstr (strings,
qfo->strings + DATA (reloc->ofs)->string_var); // qfo->strings + DATA (reloc->offset)->string_var);
break; break;
case rel_def_field: case rel_def_field:
case rel_def_field_ofs: case rel_def_field_ofs:
//FIXME more? //FIXME more?
reloc->ofs += data_base; reloc->offset += data_base;
break; break;
} }
} }
} }
static void //static void
linker_type_mismatch (qfo_def_t *def, qfo_def_t *d) //linker_type_mismatch (qfo_def_t *def, qfo_def_t *d)
{ //{
def_error (def, "type mismatch for `%s' `%s'", // def_error (def, "type mismatch for `%s' `%s'",
STRING (def->name), // STRING (def->name),
TYPE_STRING (def->full_type)); // TYPE_STRING (def->full_type));
def_error (d, "previous definition `%s'", TYPE_STRING (d->full_type)); // def_error (d, "previous definition `%s'", TYPE_STRING (d->full_type));
} //}
static void static void
process_def (qfo_def_t *def) process_def (qfo_def_t *def)
@ -272,11 +272,11 @@ process_def (qfo_def_t *def)
return; return;
if ((_d = Hash_Find (defined_defs, STRING (def->name)))) { if ((_d = Hash_Find (defined_defs, STRING (def->name)))) {
d = deref_def (_d, &global_defs); d = deref_def (_d, &global_defs);
if (d->full_type != def->full_type) { // if (d->full_type != def->full_type) {
linker_type_mismatch (def, d); // linker_type_mismatch (def, d);
return; // return;
} // }
def->ofs = d->ofs; def->offset = d->offset;
def->flags = d->flags; def->flags = d->flags;
Hash_Add (defined_defs, get_defref (def, &global_defs)); Hash_Add (defined_defs, get_defref (def, &global_defs));
} else { } else {
@ -286,25 +286,25 @@ process_def (qfo_def_t *def)
if ((_d = Hash_Find (defined_defs, STRING (def->name)))) { if ((_d = Hash_Find (defined_defs, STRING (def->name)))) {
d = deref_def (_d, &global_defs); d = deref_def (_d, &global_defs);
if (d->flags & QFOD_SYSTEM) { if (d->flags & QFOD_SYSTEM) {
int i, size; // int i, size;
if (d->full_type != def->full_type) { // if (d->full_type != def->full_type) {
linker_type_mismatch (def, d); // linker_type_mismatch (def, d);
return; // return;
} // }
d->flags &= ~QFOD_SYSTEM; d->flags &= ~QFOD_SYSTEM;
d->flags |= def->flags & (QFOD_INITIALIZED | QFOD_CONSTANT); d->flags |= def->flags & (QFOD_INITIALIZED | QFOD_CONSTANT);
size = type_size (parse_type (TYPE_STRING (d->full_type))); // size = type_size (parse_type (TYPE_STRING (d->full_type)));
memcpy (DATA (d->ofs), DATA (def->ofs), // memcpy (DATA (d->offset), DATA (def->offset),
size * sizeof (pr_type_t)); // size * sizeof (pr_type_t));
for (i = 0; i < relocs.num_relocs; i++) { // for (i = 0; i < relocs.num_relocs; i++) {
qfo_reloc_t *reloc = relocs.relocs + i; // qfo_reloc_t *reloc = relocs.relocs + i;
if (reloc->type >= rel_def_def // if (reloc->type >= rel_def_def
&& reloc->type <= rel_def_field) // && reloc->type <= rel_def_field)
if (reloc->ofs == def->ofs) // if (reloc->offset == def->offset)
reloc->ofs = d->ofs; // reloc->offset = d->offset;
} // }
def->ofs = d->ofs; def->offset = d->offset;
def->flags = d->flags; def->flags = d->flags;
} else { } else {
def_error (def, "%s redefined", STRING (def->name)); def_error (def, "%s redefined", STRING (def->name));
@ -314,11 +314,11 @@ process_def (qfo_def_t *def)
while ((_d = Hash_Del (extern_defs, STRING (def->name)))) { while ((_d = Hash_Del (extern_defs, STRING (def->name)))) {
Hash_Add (defined_defs, _d); Hash_Add (defined_defs, _d);
d = deref_def (_d, &global_defs); d = deref_def (_d, &global_defs);
if (d->full_type != def->full_type) { // if (d->full_type != def->full_type) {
linker_type_mismatch (def, d); // linker_type_mismatch (def, d);
continue; // continue;
} // }
d->ofs = def->ofs; d->offset = def->offset;
d->flags = def->flags; d->flags = def->flags;
} }
Hash_Add (defined_defs, get_defref (def, &global_defs)); Hash_Add (defined_defs, get_defref (def, &global_defs));
@ -330,7 +330,7 @@ process_field (qfo_def_t *def)
{ {
defref_t *_d; defref_t *_d;
qfo_def_t *field_def; qfo_def_t *field_def;
pr_type_t *var = DATA (def->ofs); pr_type_t *var = DATA (def->offset);
if (strcmp (STRING (def->name), ".imm")) { //FIXME better test if (strcmp (STRING (def->name), ".imm")) { //FIXME better test
if ((_d = Hash_Find (field_defs, STRING (def->name)))) { if ((_d = Hash_Find (field_defs, STRING (def->name)))) {
@ -341,7 +341,7 @@ process_field (qfo_def_t *def)
} }
defgroup_add_defs (&fields, def, 1); defgroup_add_defs (&fields, def, 1);
field_def = fields.defs + fields.num_defs - 1; field_def = fields.defs + fields.num_defs - 1;
field_def->ofs = var->integer_var + entity_base; field_def->offset = var->integer_var + entity_base;
Hash_Add (field_defs, get_defref (field_def, &fields)); Hash_Add (field_defs, get_defref (field_def, &fields));
} }
@ -350,12 +350,12 @@ fixup_def (qfo_t *qfo, qfo_def_t *def, int def_num)
{ {
pr_int_t i; pr_int_t i;
qfo_reloc_t *reloc; qfo_reloc_t *reloc;
qfo_func_t *func; // qfo_func_t *func;
const char *full_type = QFO_TYPESTR (qfo, def->full_type); // const char *full_type = QFO_TYPESTR (qfo, def->full_type);
const char *name = QFO_GETSTR (qfo, def->name); // const char *name = QFO_GETSTR (qfo, def->name);
def->full_type = strpool_addstr (type_strings, full_type); // def->full_type = strpool_addstr (type_strings, full_type);
def->name = strpool_addstr (strings, name); // def->name = strpool_addstr (strings, name);
def->relocs += reloc_base; def->relocs += reloc_base;
for (i = 0, reloc = relocs.relocs + def->relocs; for (i = 0, reloc = relocs.relocs + def->relocs;
@ -363,28 +363,28 @@ fixup_def (qfo_t *qfo, qfo_def_t *def, int def_num)
i++, reloc++) i++, reloc++)
reloc->def = def_num; reloc->def = def_num;
def->file = strpool_addstr (strings, qfo->strings + def->file); // def->file = strpool_addstr (strings, qfo->strings + def->file);
if ((def->flags & (QFOD_LOCAL | QFOD_ABSOLUTE))) if ((def->flags & (QFOD_LOCAL | QFOD_ABSOLUTE)))
return; return;
if (!(def->flags & QFOD_EXTERNAL)) { if (!(def->flags & QFOD_EXTERNAL)) {
def->ofs += data_base; def->offset += data_base;
if (def->flags & QFOD_INITIALIZED) { // if (def->flags & QFOD_INITIALIZED) {
pr_type_t *var = DATA (def->ofs); // pr_type_t *var = DATA (def->offset);
switch (def->basic_type) { // switch (def->basic_type) {
case ev_func: // case ev_func:
if (var->func_var) { // if (var->func_var) {
func = funcs.funcs + var->func_var - 1; // func = funcs.funcs + var->func_var - 1;
func->def = def_num; // func->def = def_num;
} // }
break; // break;
case ev_field: // case ev_field:
process_field (def); // process_field (def);
break; // break;
default: // default:
break; // break;
} // }
} // }
} }
process_def (def); process_def (def);
} }
@ -421,8 +421,8 @@ add_funcs (qfo_t *qfo)
funcgroup_add_funcs (&funcs, qfo->funcs, qfo->num_funcs); funcgroup_add_funcs (&funcs, qfo->funcs, qfo->num_funcs);
for (i = func_base; i < funcs.num_funcs; i++) { for (i = func_base; i < funcs.num_funcs; i++) {
qfo_func_t *func = funcs.funcs + i; qfo_func_t *func = funcs.funcs + i;
func->name = strpool_addstr (strings, qfo->strings + func->name); // func->name = strpool_addstr (strings, qfo->strings + func->name);
func->file = strpool_addstr (strings, qfo->strings + func->file); // func->file = strpool_addstr (strings, qfo->strings + func->file);
if (func->code) if (func->code)
func->code += code_base; func->code += code_base;
if (func->num_local_defs) { if (func->num_local_defs) {
@ -469,7 +469,7 @@ fixup_relocs (void)
defref_t *_d; defref_t *_d;
qfo_reloc_t *reloc; qfo_reloc_t *reloc;
qfo_def_t *def, *field_def; qfo_def_t *def, *field_def;
qfo_func_t *func; // qfo_func_t *func;
int i; int i;
for (i = 0; i < final_relocs.num_relocs; i++) { for (i = 0; i < final_relocs.num_relocs; i++) {
@ -506,13 +506,13 @@ fixup_relocs (void)
case rel_none: case rel_none:
break; break;
case rel_op_a_def: case rel_op_a_def:
code->code[reloc->ofs].a = def->ofs; code->code[reloc->offset].a = def->offset;
break; break;
case rel_op_b_def: case rel_op_b_def:
code->code[reloc->ofs].b = def->ofs; code->code[reloc->offset].b = def->offset;
break; break;
case rel_op_c_def: case rel_op_c_def:
code->code[reloc->ofs].c = def->ofs; code->code[reloc->offset].c = def->offset;
break; break;
case rel_op_a_op: case rel_op_a_op:
case rel_op_b_op: case rel_op_b_op:
@ -524,13 +524,13 @@ fixup_relocs (void)
case rel_def_field_ofs: case rel_def_field_ofs:
break; break;
case rel_def_op: case rel_def_op:
DATA (reloc->ofs)->integer_var = reloc->def; DATA (reloc->offset)->integer_var = reloc->def;
break; break;
case rel_def_def: case rel_def_def:
DATA (reloc->ofs)->integer_var = def->ofs; DATA (reloc->offset)->integer_var = def->offset;
break; break;
case rel_def_func: case rel_def_func:
DATA (reloc->ofs)->func_var = reloc->def + 1; DATA (reloc->offset)->func_var = reloc->def + 1;
break; break;
case rel_def_string: case rel_def_string:
break; break;
@ -538,22 +538,22 @@ fixup_relocs (void)
_d = Hash_Find (field_defs, STRING (def->name)); _d = Hash_Find (field_defs, STRING (def->name));
if (_d) { // null if not initialized if (_d) { // null if not initialized
field_def = deref_def (_d, &fields); field_def = deref_def (_d, &fields);
DATA (reloc->ofs)->integer_var = field_def->ofs; DATA (reloc->offset)->integer_var = field_def->offset;
} }
break; break;
} }
} }
for (i = 0; i < defs.num_defs; i++) { for (i = 0; i < defs.num_defs; i++) {
def = defs.defs + i; def = defs.defs + i;
if (def->basic_type == ev_func // if (def->basic_type == ev_func
&& (def->flags & QFOD_INITIALIZED) // && (def->flags & QFOD_INITIALIZED)
&& !(def->flags & (QFOD_LOCAL | QFOD_EXTERNAL | QFOD_ABSOLUTE))) { // && !(def->flags & (QFOD_LOCAL | QFOD_EXTERNAL | QFOD_ABSOLUTE))) {
pr_type_t *var = DATA (def->ofs); // pr_type_t *var = DATA (def->offset);
if (var->func_var) { // if (var->func_var) {
func = funcs.funcs + var->func_var - 1; // func = funcs.funcs + var->func_var - 1;
func->def = i; // func->def = i;
} // }
} // }
} }
} }
@ -574,15 +574,15 @@ move_def (hashtab_t *deftab, qfo_def_t *d)
relocs.relocs[d->relocs + j].type = rel_none; relocs.relocs[d->relocs + j].type = rel_none;
final_relocs.relocs[def->relocs + j].def = def_num; final_relocs.relocs[def->relocs + j].def = def_num;
} }
if ((d->flags & QFOD_CONSTANT) && d->basic_type == ev_func) { // if ((d->flags & QFOD_CONSTANT) && d->basic_type == ev_func) {
qfo_func_t *func; // qfo_func_t *func;
pr_type_t *var = DATA (d->ofs); // pr_type_t *var = DATA (d->offset);
if (var->func_var) { // if (var->func_var) {
func = funcs.funcs + var->func_var - 1; // func = funcs.funcs + var->func_var - 1;
func->def = def_num; // func->def = def_num;
} // }
} // }
if (deftab) { if (deftab) {
while ((_d = Hash_Del (deftab, STRING (def->name)))) { while ((_d = Hash_Del (deftab, STRING (def->name)))) {
int def_relocs; int def_relocs;
@ -658,10 +658,10 @@ define_def (const char *name, etype_t basic_type, const char *full_type,
memset (&d, 0, sizeof (d)); memset (&d, 0, sizeof (d));
d.basic_type = basic_type; // d.basic_type = basic_type;
d.full_type = strpool_addstr (type_strings, full_type); // d.full_type = strpool_addstr (type_strings, full_type);
d.name = strpool_addstr (strings, name); d.name = strpool_addstr (strings, name);
d.ofs = data->size; d.offset = data->size;
if (basic_type == ev_field) { if (basic_type == ev_field) {
d.relocs = relocs.num_relocs; d.relocs = relocs.num_relocs;
d.num_relocs = 1; d.num_relocs = 1;
@ -675,7 +675,7 @@ define_def (const char *name, etype_t basic_type, const char *full_type,
if (basic_type == ev_field) { if (basic_type == ev_field) {
int def_num = global_defs.num_defs - 1; int def_num = global_defs.num_defs - 1;
qfo_def_t *def = global_defs.defs + def_num; qfo_def_t *def = global_defs.defs + def_num;
qfo_reloc_t rel = {def->ofs, rel_def_field, def_num}; qfo_reloc_t rel = {def->offset, rel_def_field, def_num};
relocgroup_add_relocs (&relocs, &rel, 1); relocgroup_add_relocs (&relocs, &rel, 1);
process_field (def); process_field (def);
} }
@ -726,10 +726,10 @@ linker_add_qfo (qfo_t *qfo)
line_base = lines.num_lines; line_base = lines.num_lines;
entity_base = entity->size; entity_base = entity->size;
codespace_addcode (code, qfo->code, qfo->code_size); // codespace_addcode (code, qfo->code, qfo->code_size);
defspace_add_data (data, qfo->data, qfo->data_size); // defspace_add_data (data, qfo->data, qfo->data_size);
defspace_add_data (far_data, qfo->far_data, qfo->far_data_size); // defspace_add_data (far_data, qfo->far_data, qfo->far_data_size);
defspace_add_data (entity, 0, qfo->entity_fields); // defspace_add_data (entity, 0, qfo->entity_fields);
add_strings (qfo); add_strings (qfo);
add_relocs (qfo); add_relocs (qfo);
add_funcs (qfo); add_funcs (qfo);
@ -807,17 +807,17 @@ linker_add_lib (const char *libname)
return 1; return 1;
for (j = 0; j < qfo->num_defs; j++) { for (j = 0; j < qfo->num_defs; j++) {
qfo_def_t *def = qfo->defs + j; // qfo_def_t *def = qfo->defs + j;
if ((def->flags & QFOD_GLOBAL) // if ((def->flags & QFOD_GLOBAL)
&& !(def->flags & QFOD_EXTERNAL) // && !(def->flags & QFOD_EXTERNAL)
&& Hash_Find (extern_defs, qfo->strings + def->name)) { // && Hash_Find (extern_defs, qfo->strings + def->name)) {
if (options.verbosity >= 2) // if (options.verbosity >= 2)
printf ("adding %s because of %s\n", // printf ("adding %s because of %s\n",
pack->files[i].name, qfo->strings + def->name); // pack->files[i].name, qfo->strings + def->name);
linker_add_qfo (qfo); // linker_add_qfo (qfo);
did_something = 1; // did_something = 1;
break; // break;
} // }
} }
qfo_delete (qfo); qfo_delete (qfo);
@ -844,14 +844,14 @@ undefined_def (qfo_def_t *def)
&& lines.lines) { && lines.lines) {
qfo_func_t *func = funcs.funcs; qfo_func_t *func = funcs.funcs;
qfo_func_t *best = func; qfo_func_t *best = func;
pr_int_t best_dist = reloc->ofs - func->code; pr_int_t best_dist = reloc->offset - func->code;
pr_lineno_t *line; pr_lineno_t *line;
while (best_dist && func - funcs.funcs < funcs.num_funcs) { while (best_dist && func - funcs.funcs < funcs.num_funcs) {
if (func->code <= reloc->ofs) { if (func->code <= reloc->offset) {
if (best_dist < 0 || reloc->ofs - func->code < best_dist) { if (best_dist < 0 || reloc->offset - func->code < best_dist) {
best = func; best = func;
best_dist = reloc->ofs - func->code; best_dist = reloc->offset - func->code;
} }
} }
func++; func++;
@ -862,7 +862,7 @@ undefined_def (qfo_def_t *def)
if (!line->line if (!line->line
&& line->fa.func == (pr_uint_t) (best - funcs.funcs)) { && line->fa.func == (pr_uint_t) (best - funcs.funcs)) {
while (line - lines.lines < lines.num_lines - 1 && line[1].line while (line - lines.lines < lines.num_lines - 1 && line[1].line
&& line[1].fa.addr <= (pr_uint_t) reloc->ofs) && line[1].fa.addr <= (pr_uint_t) reloc->offset)
line++; line++;
line_def.line = line->line + best->line; line_def.line = line->line + best->line;
} }
@ -890,9 +890,9 @@ linker_finish (void)
if (strcmp (name, ".self") == 0 && !did_self) { if (strcmp (name, ".self") == 0 && !did_self) {
defref_t *_d = Hash_Find (defined_defs, "self"); defref_t *_d = Hash_Find (defined_defs, "self");
if (_d) { if (_d) {
qfo_def_t *d = deref_def (_d, &global_defs); // qfo_def_t *d = deref_def (_d, &global_defs);
if (d->basic_type == ev_entity) // if (d->basic_type == ev_entity)
def_warning (d, "@self and self used together"); // def_warning (d, "@self and self used together");
} }
define_def (".self", ev_entity, "E", 0, 1, 0); define_def (".self", ev_entity, "E", 0, 1, 0);
did_self = 1; did_self = 1;
@ -929,7 +929,7 @@ linker_finish (void)
qfo_add_funcs (qfo, funcs.funcs, funcs.num_funcs); qfo_add_funcs (qfo, funcs.funcs, funcs.num_funcs);
qfo_add_lines (qfo, lines.lines, lines.num_lines); qfo_add_lines (qfo, lines.lines, lines.num_lines);
qfo_add_types (qfo, type_strings->strings, type_strings->size); qfo_add_types (qfo, type_strings->strings, type_strings->size);
qfo->entity_fields = entity->size; // qfo->entity_fields = entity->size;
return qfo; return qfo;
} }
@ -962,21 +962,21 @@ def_error (qfo_def_t *def, const char *fmt, ...)
error (0, "%s", string->str); error (0, "%s", string->str);
} }
static void //static void
def_warning (qfo_def_t *def, const char *fmt, ...) //def_warning (qfo_def_t *def, const char *fmt, ...)
{ //{
va_list args; // va_list args;
static dstring_t *string; // static dstring_t *string;
//
if (!string) // if (!string)
string = dstring_new (); // string = dstring_new ();
//
va_start (args, fmt); // va_start (args, fmt);
dvsprintf (string, fmt, args); // dvsprintf (string, fmt, args);
va_end (args); // va_end (args);
//
pr.source_file = def->file; // pr.source_file = def->file;
pr.source_line = def->line; // pr.source_line = def->line;
pr.strings = strings; // pr.strings = strings;
warning (0, "%s", string->str); // warning (0, "%s", string->str);
} //}

View file

@ -127,9 +127,9 @@ static int num_edicts;
static int reserved_edicts = 1; static int reserved_edicts = 1;
static progs_t pr; static progs_t pr;
static pr_debug_header_t debug; //static pr_debug_header_t debug;
static qfo_t *qfo; static qfo_t *qfo;
static dprograms_t progs; //static dprograms_t progs;
static const char *source_path = ""; static const char *source_path = "";
@ -252,7 +252,7 @@ init_qf (void)
func_tab = Hash_NewTable (1021, 0, 0, 0); func_tab = Hash_NewTable (1021, 0, 0, 0);
Hash_SetHashCompare (func_tab, func_hash, func_compare); Hash_SetHashCompare (func_tab, func_hash, func_compare);
} }
/*
static etype_t static etype_t
get_auxtype (const char *type) get_auxtype (const char *type)
{ {
@ -455,7 +455,7 @@ convert_qfo (void)
pr.debug = &debug; pr.debug = &debug;
} }
*/
static int static int
load_progs (const char *name) load_progs (const char *name)
{ {
@ -480,7 +480,7 @@ load_progs (const char *name)
if (!qfo) if (!qfo)
return 0; return 0;
convert_qfo (); // convert_qfo ();
} else { } else {
pr.progs_name = name; pr.progs_name = name;
PR_LoadProgsFile (&pr, file, size, 1, 0); PR_LoadProgsFile (&pr, file, size, 1, 0);