Reorganize the offset calculations.

keep the offset calculations separate from the data transfers for better
clarity in what is happening.
This commit is contained in:
Bill Currie 2011-03-04 23:31:09 +09:00
parent e62163e569
commit 6d02555ca9

View file

@ -708,8 +708,11 @@ qfo_to_progs (qfo_t *qfo, int *size)
ddef_t *globaldefs; ddef_t *globaldefs;
ddef_t *fielddefs; ddef_t *fielddefs;
pr_type_t *globals; pr_type_t *globals;
pr_type_t *locals;
pr_type_t *far_data;
pr_type_t *type_data;
dprograms_t *progs; dprograms_t *progs;
int i; int i, j;
int locals_size = 0; int locals_size = 0;
int locals_start; int locals_start;
int big_locals = 0; int big_locals = 0;
@ -752,19 +755,37 @@ qfo_to_progs (qfo_t *qfo, int *size)
progs->ofs_strings = data - (byte *) progs; progs->ofs_strings = data - (byte *) progs;
strings = (char *) data; strings = (char *) data;
memcpy (strings, qfo->spaces[qfo_strings_space].d.strings,
qfo->spaces[qfo_strings_space].data_size * sizeof (char));
data += RUP (progs->numstrings * sizeof (char), 16); data += RUP (progs->numstrings * sizeof (char), 16);
progs->ofs_statements = data - (byte *) progs; progs->ofs_statements = data - (byte *) progs;
statements = (dstatement_t *) data; statements = (dstatement_t *) data;
memcpy (statements, qfo->spaces[qfo_code_space].d.code,
qfo->spaces[qfo_code_space].data_size * sizeof (dstatement_t));
data += progs->numstatements * sizeof (dstatement_t); data += progs->numstatements * sizeof (dstatement_t);
progs->ofs_functions = data - (byte *) progs; progs->ofs_functions = data - (byte *) progs;
functions = (dfunction_t *) data; functions = (dfunction_t *) data;
functions++; // skip over null function functions++; // skip over null function
data += progs->numfunctions * sizeof (dfunction_t);
progs->ofs_globaldefs = data - (byte *) progs;
globaldefs = (ddef_t *) data;
data += progs->numglobaldefs * sizeof (ddef_t);
progs->ofs_fielddefs = data - (byte *) progs;
fielddefs = (ddef_t *) (globaldefs + progs->numglobaldefs);
data += progs->numfielddefs * sizeof (ddef_t);
progs->ofs_globals = data - (byte *) progs;
globals = (pr_type_t*) data;
locals = globals + qfo->spaces[qfo_near_data_space].data_size;
far_data = locals + locals_size;
type_data = far_data + qfo->spaces[qfo_far_data_space].data_size;
memcpy (strings, qfo->spaces[qfo_strings_space].d.strings,
qfo->spaces[qfo_strings_space].data_size * sizeof (char));
memcpy (statements, qfo->spaces[qfo_code_space].d.code,
qfo->spaces[qfo_code_space].data_size * sizeof (dstatement_t));
for (i = 0; i < qfo->num_funcs; i++) { for (i = 0; i < qfo->num_funcs; i++) {
dfunction_t *df = functions + i; dfunction_t *df = functions + i;
qfo_func_t *qf = qfo->funcs + i; qfo_func_t *qf = qfo->funcs + i;
@ -778,43 +799,31 @@ qfo_to_progs (qfo_t *qfo, int *size)
df->s_file = qf->file; df->s_file = qf->file;
function_params (qfo, qf, df); function_params (qfo, qf, df);
} }
data += progs->numfunctions * sizeof (dfunction_t);
progs->ofs_globaldefs = data - (byte *) progs;
globaldefs = (ddef_t *) data;
for (i = 0; i < qfo->spaces[qfo_near_data_space].num_defs; i++) { for (i = 0; i < qfo->spaces[qfo_near_data_space].num_defs; i++) {
convert_def (qfo, qfo->spaces[qfo_near_data_space].defs + i, convert_def (qfo, qfo->spaces[qfo_near_data_space].defs + i,
globaldefs + i); globaldefs + i);
} }
data += progs->numglobaldefs * sizeof (ddef_t);
progs->ofs_fielddefs = data - (byte *) progs;
fielddefs = (ddef_t *) (globaldefs + progs->numglobaldefs);
for (i = 0; i < qfo->spaces[qfo_entity_space].num_defs; i++) { for (i = 0; i < qfo->spaces[qfo_entity_space].num_defs; i++) {
convert_def (qfo, qfo->spaces[qfo_near_data_space].defs + i, convert_def (qfo, qfo->spaces[qfo_near_data_space].defs + i,
fielddefs + i); fielddefs + i);
} }
data += progs->numfielddefs * sizeof (ddef_t);
progs->ofs_globals = data - (byte *) progs;
globals = (pr_type_t*) data;
// copy near data // copy near data
memcpy (globals, qfo->spaces[qfo_near_data_space].d.data, memcpy (globals, qfo->spaces[qfo_near_data_space].d.data,
qfo->spaces[qfo_near_data_space].data_size * sizeof (pr_type_t)); 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].d.data = globals;
globals += qfo->spaces[qfo_near_data_space].data_size;
// lcear locals data // lcear locals data
memset (globals, 0, locals_size * sizeof (pr_type_t)); memset (locals, 0, locals_size * sizeof (pr_type_t));
globals += locals_size;
// copy far data // copy far data
memcpy (globals, qfo->spaces[qfo_far_data_space].d.data, memcpy (far_data, qfo->spaces[qfo_far_data_space].d.data,
qfo->spaces[qfo_far_data_space].data_size * sizeof (pr_type_t)); qfo->spaces[qfo_far_data_space].data_size * sizeof (pr_type_t));
qfo->spaces[qfo_far_data_space].d.data = globals; qfo->spaces[qfo_far_data_space].d.data = far_data;
globals += qfo->spaces[qfo_far_data_space].data_size;
// copy type data // copy type data
memcpy (globals, qfo->spaces[qfo_type_space].d.data, memcpy (type_data, qfo->spaces[qfo_type_space].d.data,
qfo->spaces[qfo_type_space].data_size * sizeof (pr_type_t)); qfo->spaces[qfo_type_space].data_size * sizeof (pr_type_t));
qfo->spaces[qfo_type_space].d.data = globals; qfo->spaces[qfo_type_space].d.data = type_data;
// FIXME do relocs // FIXME do relocs
return progs; return progs;
} }