mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-01-18 23:11:38 +00:00
[qfcc] Remove a union wart from qfo_mspace_t
This commit is contained in:
parent
c9f372fa38
commit
dcf8beeccc
5 changed files with 74 additions and 74 deletions
|
@ -254,7 +254,7 @@ typedef struct qfo_mspace_s {
|
|||
dstatement_t *code;
|
||||
pr_type_t *data;
|
||||
char *strings;
|
||||
} d;
|
||||
};
|
||||
unsigned data_size;
|
||||
unsigned id;
|
||||
} qfo_mspace_t;
|
||||
|
@ -305,7 +305,7 @@ enum {
|
|||
|
||||
\hideinitializer
|
||||
*/
|
||||
#define QFO_var(q, s, t, o) ((q)->spaces[s].d.data[o].t##_var)
|
||||
#define QFO_var(q, s, t, o) ((q)->spaces[s].data[o].t##_var)
|
||||
|
||||
/** Access a double variable in the object file. Can be assigned to.
|
||||
|
||||
|
@ -318,7 +318,7 @@ enum {
|
|||
|
||||
\hideinitializer
|
||||
*/
|
||||
#define QFO_DOUBLE(q, s, o) (*(double *) ((q)->spaces[s].d.data + o))
|
||||
#define QFO_DOUBLE(q, s, o) (*(double *) ((q)->spaces[s].data + o))
|
||||
|
||||
/** Access a float variable in the object file. Can be assigned to.
|
||||
|
||||
|
@ -380,10 +380,10 @@ enum {
|
|||
|
||||
\hideinitializer
|
||||
*/
|
||||
#define QFO_GETSTR(q, s) ((q)->spaces[qfo_strings_space].d.strings + (s))
|
||||
#define QFO_GETSTR(q, s) ((q)->spaces[qfo_strings_space].strings + (s))
|
||||
|
||||
#define QFO_TYPE(q, t) ((qfot_type_t *) (char *) \
|
||||
((q)->spaces[qfo_type_space].d.data + (t)))
|
||||
((q)->spaces[qfo_type_space].data + (t)))
|
||||
|
||||
/** Retrieve a type string from the object file, converting it to a C string.
|
||||
|
||||
|
@ -399,7 +399,7 @@ enum {
|
|||
#define QFO_TYPEMETA(q, t) QFO_INT (q, qfo_type_space, (t) + 0)
|
||||
#define QFO_TYPETYPE(q, t) QFO_INT (q, qfo_type_space, (t) + 3)
|
||||
|
||||
#define QFO_STATEMENT(q, s) ((q)->spaces[qfo_code_space].d.code + (s))
|
||||
#define QFO_STATEMENT(q, s) ((q)->spaces[qfo_code_space].code + (s))
|
||||
|
||||
/** Access a string global, converting it to a C string.
|
||||
|
||||
|
|
|
@ -325,9 +325,9 @@ qfo_globals (qfo_t *qfo)
|
|||
QFO_GETSTR (qfo, def->name),
|
||||
def->type,
|
||||
QFO_TYPESTR (qfo, def->type));
|
||||
if (!(def->flags & QFOD_EXTERNAL) && qfo->spaces[space].d.data)
|
||||
if (!(def->flags & QFOD_EXTERNAL) && qfo->spaces[space].data)
|
||||
printf (" %d",
|
||||
qfo->spaces[space].d.data[def->offset].integer_var);
|
||||
qfo->spaces[space].data[def->offset].integer_var);
|
||||
puts ("");
|
||||
}
|
||||
}
|
||||
|
@ -481,7 +481,7 @@ qfo_functions (qfo_t *qfo)
|
|||
locals = &qfo->spaces[func->locals_space];
|
||||
printf ("%*s%d %p %d %p %d %d\n", 16, "", locals->type,
|
||||
locals->defs, locals->num_defs,
|
||||
locals->d.data, locals->data_size, locals->id);
|
||||
locals->data, locals->data_size, locals->id);
|
||||
for (j = 0; j < locals->num_defs; j++) {
|
||||
qfo_def_t *def = locals->defs + j;
|
||||
int offset;
|
||||
|
@ -627,10 +627,10 @@ dump_types (progs_t *pr)
|
|||
}
|
||||
memset (spaces, 0, sizeof (spaces));
|
||||
spaces[qfo_strings_space].type = qfos_string;
|
||||
spaces[qfo_strings_space].d.strings = pr->pr_strings;
|
||||
spaces[qfo_strings_space].strings = pr->pr_strings;
|
||||
spaces[qfo_strings_space].data_size = pr->pr_stringsize;
|
||||
spaces[qfo_type_space].type = qfos_type;
|
||||
spaces[qfo_type_space].d.data = pr->pr_globals + encodings->types;
|
||||
spaces[qfo_type_space].data = pr->pr_globals + encodings->types;
|
||||
spaces[qfo_type_space].data_size = encodings->size;
|
||||
memset (&qfo, 0, sizeof (qfo));
|
||||
qfo.spaces = spaces;
|
||||
|
|
|
@ -94,5 +94,5 @@ qfo_strings (qfo_t *qfo)
|
|||
printf ("no strings\n");
|
||||
return;
|
||||
}
|
||||
dump_string_block (space->d.strings, space->data_size);
|
||||
dump_string_block (space->strings, space->data_size);
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ static dstring_t *linker_current_file;
|
|||
#define QFOSTR(q,s) QFO_GETSTR (q, s)
|
||||
#define WORKSTR(s) QFOSTR (work, s)
|
||||
#define QFOTYPE(t) ((qfot_type_t *) (char *) \
|
||||
(qfo_type_defs->d.data + (t)))
|
||||
(qfo_type_defs->data + (t)))
|
||||
#define WORKTYPE(t) ((qfot_type_t *) (char *) \
|
||||
(work_type_data->data + (t)))
|
||||
|
||||
|
@ -247,7 +247,7 @@ linker_add_string (const char *str)
|
|||
{
|
||||
string_t new;
|
||||
new = strpool_addstr (work_strings, str);
|
||||
work->spaces[qfo_strings_space].d.strings = work_strings->strings;
|
||||
work->spaces[qfo_strings_space].strings = work_strings->strings;
|
||||
work->spaces[qfo_strings_space].data_size = work_strings->size;
|
||||
return new;
|
||||
}
|
||||
|
@ -268,7 +268,7 @@ alloc_data (int space, int size)
|
|||
if (size <= 0)
|
||||
linker_internal_error ("bad size for alloc_data (): %d", space);
|
||||
offset = defspace_alloc_loc (*work_spaces[space], size);
|
||||
work->spaces[space].d.data = (*work_spaces[space])->data;
|
||||
work->spaces[space].data = (*work_spaces[space])->data;
|
||||
work->spaces[space].data_size = (*work_spaces[space])->size;
|
||||
return offset;
|
||||
}
|
||||
|
@ -536,11 +536,11 @@ add_defs (qfo_t *qfo, qfo_mspace_t *space, qfo_mspace_t *dest_space,
|
|||
static void
|
||||
add_qfo_strings (qfo_mspace_t *strings)
|
||||
{
|
||||
const char *str = strings->d.strings;
|
||||
const char *str = strings->strings;
|
||||
|
||||
while ((pr_uint_t) (str - strings->d.strings) < strings->data_size) {
|
||||
while ((pr_uint_t) (str - strings->strings) < strings->data_size) {
|
||||
linker_add_string (str);
|
||||
while ((pr_uint_t) (str - strings->d.strings) < strings->data_size
|
||||
while ((pr_uint_t) (str - strings->strings) < strings->data_size
|
||||
&& *str)
|
||||
str++;
|
||||
str++; // advance past the terminating nul
|
||||
|
@ -554,8 +554,8 @@ add_qfo_strings (qfo_mspace_t *strings)
|
|||
static void
|
||||
add_code (qfo_mspace_t *code)
|
||||
{
|
||||
codespace_addcode (work_code, code->d.code, code->data_size);
|
||||
work->spaces[qfo_code_space].d.code = work_code->code;
|
||||
codespace_addcode (work_code, code->code, code->data_size);
|
||||
work->spaces[qfo_code_space].code = work_code->code;
|
||||
work->spaces[qfo_code_space].data_size = work_code->size;
|
||||
}
|
||||
|
||||
|
@ -570,8 +570,8 @@ add_data (int space, qfo_mspace_t *data)
|
|||
if (space < 0 || space >= qfo_num_spaces || !work_spaces[space])
|
||||
linker_internal_error ("bad space for add_data (): %d", space);
|
||||
if (data->data_size)
|
||||
defspace_add_data (*work_spaces[space], data->d.data, data->data_size);
|
||||
work->spaces[space].d.data = (*work_spaces[space])->data;
|
||||
defspace_add_data (*work_spaces[space], data->data, data->data_size);
|
||||
work->spaces[space].data = (*work_spaces[space])->data;
|
||||
work->spaces[space].data_size = (*work_spaces[space])->size;
|
||||
}
|
||||
|
||||
|
@ -596,10 +596,10 @@ add_data_space (qfo_t *qfo, qfo_mspace_t *space)
|
|||
ws->type = space->type;
|
||||
if (space->num_defs)
|
||||
add_defs (qfo, space, ws, process_data_def);
|
||||
if (space->d.data) {
|
||||
if (space->data) {
|
||||
int size = space->data_size * sizeof (pr_type_t);
|
||||
ws->d.data = malloc (size);
|
||||
memcpy (ws->d.data, space->d.data, size);
|
||||
ws->data = malloc (size);
|
||||
memcpy (ws->data, space->data, size);
|
||||
}
|
||||
ws->data_size = space->data_size;
|
||||
ws->id = space->id;
|
||||
|
@ -630,7 +630,7 @@ make_def (int s, const char *name, type_t *type, unsigned flags, void *val)
|
|||
if (val)
|
||||
memcpy (&def_space->data[def->offset], val,
|
||||
type_size (type) * sizeof (pr_type_t));
|
||||
space->d.data = def_space->data;
|
||||
space->data = def_space->data;
|
||||
space->data_size = def_space->size;
|
||||
|
||||
ref = get_defref (def, space);
|
||||
|
@ -695,25 +695,25 @@ linker_begin (void)
|
|||
work->num_spaces = qfo_num_spaces;
|
||||
work->spaces[qfo_null_space].type = qfos_null;
|
||||
work->spaces[qfo_strings_space].type = qfos_string;
|
||||
work->spaces[qfo_strings_space].d.strings = work_strings->strings;
|
||||
work->spaces[qfo_strings_space].strings = work_strings->strings;
|
||||
work->spaces[qfo_strings_space].data_size = work_strings->size;
|
||||
work->spaces[qfo_code_space].type = qfos_code;
|
||||
work->spaces[qfo_code_space].d.code = work_code->code;
|
||||
work->spaces[qfo_code_space].code = work_code->code;
|
||||
work->spaces[qfo_code_space].data_size = work_code->size;
|
||||
work->spaces[qfo_near_data_space].type = qfos_data;
|
||||
work->spaces[qfo_near_data_space].d.data = work_near_data->data;
|
||||
work->spaces[qfo_near_data_space].data = work_near_data->data;
|
||||
work->spaces[qfo_near_data_space].data_size = work_near_data->size;
|
||||
work->spaces[qfo_far_data_space].type = qfos_data;
|
||||
work->spaces[qfo_far_data_space].d.data = work_far_data->data;
|
||||
work->spaces[qfo_far_data_space].data = work_far_data->data;
|
||||
work->spaces[qfo_far_data_space].data_size = work_far_data->size;
|
||||
work->spaces[qfo_entity_space].type = qfos_entity;
|
||||
work->spaces[qfo_entity_space].d.data = work_entity_data->data;
|
||||
work->spaces[qfo_entity_space].data = work_entity_data->data;
|
||||
work->spaces[qfo_entity_space].data_size = work_entity_data->size;
|
||||
work->spaces[qfo_type_space].type = qfos_type;
|
||||
work->spaces[qfo_type_space].d.data = work_type_data->data;
|
||||
work->spaces[qfo_type_space].data = work_type_data->data;
|
||||
work->spaces[qfo_type_space].data_size = work_type_data->size;
|
||||
work->spaces[qfo_debug_space].type = qfos_debug;
|
||||
work->spaces[qfo_debug_space].d.data = work_type_data->data;
|
||||
work->spaces[qfo_debug_space].data = work_type_data->data;
|
||||
work->spaces[qfo_debug_space].data_size = work_type_data->size;
|
||||
for (i = 0; i < qfo_num_spaces; i++)
|
||||
work->spaces[i].id = i;
|
||||
|
@ -739,7 +739,7 @@ process_null_space (qfo_t *qfo, qfo_mspace_t *space, int pass)
|
|||
{
|
||||
if (pass != 0)
|
||||
return 0;
|
||||
if (space->defs || space->num_defs || space->d.data || space->data_size
|
||||
if (space->defs || space->num_defs || space->data || space->data_size
|
||||
|| space->id) {
|
||||
linker_error ("non-null null space");
|
||||
return 1;
|
||||
|
@ -1279,7 +1279,7 @@ build_qfo (void)
|
|||
for (i = 0; i < work->num_spaces; i++) {
|
||||
qfo->spaces[i].type = work->spaces[i].type;
|
||||
qfo->spaces[i].id = work->spaces[i].id;
|
||||
qfo->spaces[i].d = work->spaces[i].d;
|
||||
qfo->spaces[i].data = work->spaces[i].data;
|
||||
qfo->spaces[i].data_size = work->spaces[i].data_size;
|
||||
}
|
||||
// allocate space for all relocs and copy in the loose relocs. bound
|
||||
|
|
|
@ -198,10 +198,10 @@ qfo_init_string_space (qfo_t *qfo, qfo_mspace_t *space, strpool_t *strings)
|
|||
space->type = qfos_string;
|
||||
space->num_defs = 0;
|
||||
space->defs = 0;
|
||||
space->d.strings = 0;
|
||||
space->strings = 0;
|
||||
if (strings->strings) {
|
||||
space->d.strings = malloc (size);
|
||||
memcpy (space->d.strings, strings->strings, size);
|
||||
space->strings = malloc (size);
|
||||
memcpy (space->strings, strings->strings, size);
|
||||
}
|
||||
space->data_size = strings->size;
|
||||
space->id = qfo_strings_space;
|
||||
|
@ -215,10 +215,10 @@ qfo_init_code_space (qfo_t *qfo, qfo_mspace_t *space, codespace_t *code)
|
|||
space->type = qfos_code;
|
||||
space->num_defs = 0;
|
||||
space->defs = 0;
|
||||
space->d.code = 0;
|
||||
space->code = 0;
|
||||
if (code->code) {
|
||||
space->d.code = malloc (size);
|
||||
memcpy (space->d.code, code->code, size);
|
||||
space->code = malloc (size);
|
||||
memcpy (space->code, code->code, size);
|
||||
}
|
||||
space->data_size = code->size;
|
||||
space->id = qfo_code_space;
|
||||
|
@ -233,10 +233,10 @@ qfo_init_data_space (qfo_t *qfo, qfo_def_t **defs, qfo_reloc_t **relocs,
|
|||
space->type = qfos_data;
|
||||
space->defs = *defs;
|
||||
space->num_defs = qfo_encode_defs (qfo, data->defs, defs, relocs);
|
||||
space->d.data = 0;
|
||||
space->data = 0;
|
||||
if (data->data) {
|
||||
space->d.data = malloc (size);
|
||||
memcpy (space->d.data, data->data, size);
|
||||
space->data = malloc (size);
|
||||
memcpy (space->data, data->data, size);
|
||||
}
|
||||
space->data_size = data->size;
|
||||
}
|
||||
|
@ -249,7 +249,7 @@ qfo_init_entity_space (qfo_t *qfo, qfo_def_t **defs, qfo_reloc_t **relocs,
|
|||
space->type = qfos_entity;
|
||||
space->defs = *defs;
|
||||
space->num_defs = qfo_encode_defs (qfo, data->defs, defs, relocs);
|
||||
space->d.data = 0;
|
||||
space->data = 0;
|
||||
space->data_size = data->size;
|
||||
space->id = qfo_entity_space;
|
||||
}
|
||||
|
@ -263,10 +263,10 @@ qfo_init_type_space (qfo_t *qfo, qfo_def_t **defs, qfo_reloc_t **relocs,
|
|||
space->type = qfos_type;
|
||||
space->defs = *defs;
|
||||
space->num_defs = qfo_encode_defs (qfo, data->defs, defs, relocs);
|
||||
space->d.data = 0;
|
||||
space->data = 0;
|
||||
if (data->data) {
|
||||
space->d.data = malloc (size);
|
||||
memcpy (space->d.data, data->data, size);
|
||||
space->data = malloc (size);
|
||||
memcpy (space->data, data->data, size);
|
||||
}
|
||||
space->data_size = data->size;
|
||||
space->id = qfo_type_space;
|
||||
|
@ -281,10 +281,10 @@ qfo_init_debug_space (qfo_t *qfo, qfo_def_t **defs, qfo_reloc_t **relocs,
|
|||
space->type = qfos_debug;
|
||||
space->defs = *defs;
|
||||
space->num_defs = qfo_encode_defs (qfo, data->defs, defs, relocs);
|
||||
space->d.data = 0;
|
||||
space->data = 0;
|
||||
if (data->data) {
|
||||
space->d.data = malloc (size);
|
||||
memcpy (space->d.data, data->data, size);
|
||||
space->data = malloc (size);
|
||||
memcpy (space->data, data->data, size);
|
||||
}
|
||||
space->data_size = data->size;
|
||||
space->id = qfo_debug_space;
|
||||
|
@ -393,20 +393,20 @@ qfo_space_size (qfo_mspace_t *space)
|
|||
case qfos_null:
|
||||
return 0;
|
||||
case qfos_code:
|
||||
return space->data_size * sizeof (*space->d.code);
|
||||
return space->data_size * sizeof (*space->code);
|
||||
case qfos_data:
|
||||
// data size > 0 but d.data == null -> all data is zero
|
||||
if (!space->d.data)
|
||||
// data size > 0 but data == null -> all data is zero
|
||||
if (!space->data)
|
||||
return 0;
|
||||
return space->data_size * sizeof (*space->d.data);
|
||||
return space->data_size * sizeof (*space->data);
|
||||
case qfos_string:
|
||||
return space->data_size * sizeof (*space->d.strings);
|
||||
return space->data_size * sizeof (*space->strings);
|
||||
case qfos_entity:
|
||||
return 0;
|
||||
case qfos_type:
|
||||
return space->data_size * sizeof (*space->d.data);
|
||||
return space->data_size * sizeof (*space->data);
|
||||
case qfos_debug:
|
||||
return space->data_size * sizeof (*space->d.data);
|
||||
return space->data_size * sizeof (*space->data);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -491,10 +491,10 @@ qfo_write (qfo_t *qfo, const char *filename)
|
|||
if (qfo->spaces[i].defs)
|
||||
spaces[i].defs = LittleLong (qfo->spaces[i].defs - qfo->defs);
|
||||
spaces[i].num_defs = LittleLong (qfo->spaces[i].num_defs);
|
||||
if (qfo->spaces[i].d.data) {
|
||||
if (qfo->spaces[i].data) {
|
||||
int space_size = qfo_space_size (qfo->spaces + i);
|
||||
spaces[i].data = LittleLong (space_data - data);
|
||||
memcpy (space_data, qfo->spaces[i].d.data, space_size);
|
||||
memcpy (space_data, qfo->spaces[i].data, space_size);
|
||||
qfo_byteswap_space (space_data, qfo->spaces[i].data_size,
|
||||
qfo->spaces[i].type);
|
||||
space_data += RUP (space_size, 16);
|
||||
|
@ -586,8 +586,8 @@ qfo_read (QFile *file)
|
|||
qfo->spaces[i].defs = qfo->defs + LittleLong (spaces[i].defs);
|
||||
qfo->spaces[i].data_size = LittleLong (spaces[i].data_size);
|
||||
if (spaces[i].data) {
|
||||
qfo->spaces[i].d.strings = data + LittleLong (spaces[i].data);
|
||||
qfo_byteswap_space (qfo->spaces[i].d.data,
|
||||
qfo->spaces[i].strings = data + LittleLong (spaces[i].data);
|
||||
qfo_byteswap_space (qfo->spaces[i].data,
|
||||
qfo->spaces[i].data_size, qfo->spaces[i].type);
|
||||
}
|
||||
qfo->spaces[i].id = LittleLong (spaces[i].id);
|
||||
|
@ -657,7 +657,7 @@ qfo_delete (qfo_t *qfo)
|
|||
} else {
|
||||
unsigned i;
|
||||
for (i = 0; i < qfo->num_spaces; i++)
|
||||
free (qfo->spaces[i].d.data);
|
||||
free (qfo->spaces[i].data);
|
||||
free (qfo->relocs);
|
||||
free (qfo->defs);
|
||||
free (qfo->funcs);
|
||||
|
@ -1049,13 +1049,13 @@ qfo_to_progs (qfo_t *qfo, int *size)
|
|||
type_data = globals + type_encodings_start;
|
||||
xdef_data = globals + xdefs_start;
|
||||
|
||||
memcpy (strings, qfo->spaces[qfo_strings_space].d.strings,
|
||||
memcpy (strings, qfo->spaces[qfo_strings_space].strings,
|
||||
qfo->spaces[qfo_strings_space].data_size * sizeof (char));
|
||||
qfo->spaces[qfo_strings_space].d.strings = strings;
|
||||
qfo->spaces[qfo_strings_space].strings = strings;
|
||||
|
||||
memcpy (statements, qfo->spaces[qfo_code_space].d.code,
|
||||
memcpy (statements, qfo->spaces[qfo_code_space].code,
|
||||
qfo->spaces[qfo_code_space].data_size * sizeof (dstatement_t));
|
||||
qfo->spaces[qfo_code_space].d.code = statements;
|
||||
qfo->spaces[qfo_code_space].code = statements;
|
||||
|
||||
for (i = 0; i < qfo->num_funcs; i++) {
|
||||
dfunction_t *df = functions + i;
|
||||
|
@ -1108,19 +1108,19 @@ qfo_to_progs (qfo_t *qfo, int *size)
|
|||
}
|
||||
|
||||
// copy near data
|
||||
memcpy (globals, qfo->spaces[qfo_near_data_space].d.data,
|
||||
memcpy (globals, qfo->spaces[qfo_near_data_space].data,
|
||||
qfo->spaces[qfo_near_data_space].data_size * sizeof (pr_type_t));
|
||||
qfo->spaces[qfo_near_data_space].d.data = globals;
|
||||
qfo->spaces[qfo_near_data_space].data = globals;
|
||||
// clear locals data
|
||||
memset (locals, 0, locals_size * sizeof (pr_type_t));
|
||||
// copy far data
|
||||
memcpy (far_data, qfo->spaces[qfo_far_data_space].d.data,
|
||||
memcpy (far_data, qfo->spaces[qfo_far_data_space].data,
|
||||
qfo->spaces[qfo_far_data_space].data_size * sizeof (pr_type_t));
|
||||
qfo->spaces[qfo_far_data_space].d.data = far_data;
|
||||
qfo->spaces[qfo_far_data_space].data = far_data;
|
||||
// copy type data
|
||||
memcpy (type_data, qfo->spaces[qfo_type_space].d.data,
|
||||
memcpy (type_data, qfo->spaces[qfo_type_space].data,
|
||||
qfo->spaces[qfo_type_space].data_size * sizeof (pr_type_t));
|
||||
qfo->spaces[qfo_type_space].d.data = type_data;
|
||||
qfo->spaces[qfo_type_space].data = type_data;
|
||||
|
||||
qfo_relocate_refs (qfo);
|
||||
if (types_def) {
|
||||
|
@ -1287,7 +1287,7 @@ qfo_to_sym (qfo_t *qfo, int *size)
|
|||
pr_def_t *prdef = &debug_defs[i];
|
||||
qfo_def_to_prdef (qfo, def, prdef);
|
||||
}
|
||||
memcpy (debug_data, qfo->spaces[qfo_debug_space].d.data,
|
||||
memcpy (debug_data, qfo->spaces[qfo_debug_space].data,
|
||||
sym->debug_data_size * sizeof (*debug_data));
|
||||
return sym;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue