Move to using an in-memory form of ddef_t

This allows the VM to work with extended ddefs transparently. It seems
to have uncovered a typedef alias relocation bug, though.
This commit is contained in:
Bill Currie 2020-02-22 22:33:44 +09:00
parent 4df926e531
commit 81083698a8
19 changed files with 213 additions and 125 deletions

View file

@ -420,7 +420,7 @@ typedef struct ddef_s {
pr_ushort_t type; // if DEF_SAVEGLOBGAL bit is set
// the variable needs to be saved in savegames
pr_ushort_t ofs;
pr_int_t s_name;
string_t s_name;
} ddef_t;
typedef struct xdef_s {
@ -433,6 +433,13 @@ typedef struct pr_xdefs_s {
pr_int_t num_xdefs;
} pr_xdefs_t;
typedef struct pr_def_s {
pr_uint_t type;
pointer_t ofs;
string_t name;
pointer_t type_encoding;
} pr_def_t;
typedef struct dparmsize_s {
uint8_t size:5;
uint8_t alignment:3;
@ -445,11 +452,11 @@ typedef struct dparmsize_s {
typedef struct dfunction_s {
pr_int_t first_statement; // negative numbers are builtins
pr_int_t parm_start;
pr_int_t locals; // total ints of parms + locals
pr_uint_t locals; // total ints of parms + locals
pr_int_t profile; // runtime
pr_int_t s_name;
string_t s_name;
pr_int_t s_file; // source file defined in
pr_int_t numparms;

View file

@ -51,7 +51,7 @@ typedef struct pr_lineno_s {
pr_uint_t line;
} pr_lineno_t;
#define PROG_DEBUG_VERSION 0x00001002 // MMmmmRRR 0.001.002 (hex)
#define PROG_DEBUG_VERSION 0x00001003 // MMmmmRRR 0.001.002 (hex)
typedef struct pr_debug_header_s {
pr_int_t version;

View file

@ -236,7 +236,7 @@ void ED_PrintNum (progs_t *pr, pr_int_t ent);
// pr_parse.c
struct script_s;
struct plitem_s;
qboolean ED_ParseEpair (progs_t *pr, pr_type_t *base, ddef_t *key,
qboolean ED_ParseEpair (progs_t *pr, pr_type_t *base, pr_def_t *key,
const char *s);
struct plitem_s *ED_EntityDict (progs_t *pr, edict_t *ed);
struct plitem_s *ED_GlobalsDict (progs_t *pr);
@ -269,11 +269,11 @@ void ED_EntityParseFunction (progs_t *pr);
*/
///@{
ddef_t *PR_FieldAtOfs (progs_t *pr, pr_int_t ofs) __attribute__((pure));
ddef_t *PR_GlobalAtOfs (progs_t *pr, pr_int_t ofs) __attribute__((pure));
pr_def_t *PR_FieldAtOfs (progs_t *pr, pointer_t ofs) __attribute__((pure));
pr_def_t *PR_GlobalAtOfs (progs_t *pr, pointer_t ofs) __attribute__((pure));
ddef_t *PR_FindField (progs_t *pr, const char *name);
ddef_t *PR_FindGlobal (progs_t *pr, const char *name);
pr_def_t *PR_FindField (progs_t *pr, const char *name);
pr_def_t *PR_FindGlobal (progs_t *pr, const char *name);
dfunction_t *PR_FindFunction (progs_t *pr, const char *name);
int PR_ResolveGlobals (progs_t *pr);
@ -1499,8 +1499,8 @@ pr_uint_t PR_Get_Lineno_Line (progs_t *pr, pr_lineno_t *lineno) __attribute__((p
pr_lineno_t *PR_Find_Lineno (progs_t *pr, pr_uint_t addr) __attribute__((pure));
const char *PR_Get_Source_File (progs_t *pr, pr_lineno_t *lineno) __attribute__((pure));
const char *PR_Get_Source_Line (progs_t *pr, pr_uint_t addr);
ddef_t *PR_Get_Param_Def (progs_t *pr, dfunction_t *func, unsigned parm) __attribute__((pure));
ddef_t *PR_Get_Local_Def (progs_t *pr, pr_int_t offs) __attribute__((pure));
pr_def_t *PR_Get_Param_Def (progs_t *pr, dfunction_t *func, unsigned parm) __attribute__((pure));
pr_def_t *PR_Get_Local_Def (progs_t *pr, pointer_t offs) __attribute__((pure));
void PR_PrintStatement (progs_t *pr, dstatement_t *s, int contents);
void PR_DumpState (progs_t *pr);
void PR_StackTrace (progs_t *pr);
@ -1616,8 +1616,10 @@ struct progs_s {
bfunction_t *function_table;
char *pr_strings;
int pr_stringsize;
ddef_t *pr_globaldefs;
ddef_t *pr_fielddefs;
ddef_t *pr_globalddefs;
ddef_t *pr_fieldddefs;
pr_def_t *pr_globaldefs;
pr_def_t *pr_fielddefs;
dstatement_t *pr_statements;
pr_type_t *pr_globals;
unsigned globals_size;
@ -1708,7 +1710,7 @@ struct progs_s {
struct pr_auxfunction_s *auxfunctions;
struct pr_auxfunction_s **auxfunction_map;
struct pr_lineno_s *linenos;
ddef_t *local_defs;
pr_def_t *local_defs;
pr_type_t *watch;
int wp_conditional;
pr_type_t wp_val;

View file

@ -117,7 +117,7 @@ static int
menu_resolve_globals (progs_t *pr)
{
const char *sym;
ddef_t *def;
pr_def_t *def;
dfunction_t *f;
size_t i;

View file

@ -126,17 +126,17 @@ pr_debug_expression_error (script_t *script, const char *msg)
Sys_Printf ("%s\n", msg);
}
static ddef_t
static pr_def_t
parse_expression (progs_t *pr, const char *expr, int conditional)
{
script_t *es;
char *e;
pr_type_t *expr_ptr;
ddef_t d;
pr_def_t d;
d.ofs = 0;
d.type = ev_invalid;
d.s_name = 0;
d.name = 0;
es = Script_New ();
es->error = pr_debug_expression_error;
Script_Start (es, "<console>", expr);
@ -145,7 +145,7 @@ parse_expression (progs_t *pr, const char *expr, int conditional)
if (Script_GetToken (es, 1)) {
if (strequal (es->token->str, "[")) {
edict_t *ent;
ddef_t *field;
pr_def_t *field;
if (!Script_GetToken (es, 1))
goto error;
@ -169,7 +169,7 @@ parse_expression (progs_t *pr, const char *expr, int conditional)
d.type = ev_void;
d.ofs = PR_SetPointer (pr, expr_ptr);
} else {
ddef_t *global = PR_FindGlobal (pr, es->token->str);
pr_def_t *global = PR_FindGlobal (pr, es->token->str);
if (!global)
goto error;
d = *global;
@ -277,7 +277,7 @@ PR_LoadDebug (progs_t *pr)
const char *path_end, *sym_file;
off_t debug_size;
pr_uint_t i;
ddef_t *def;
pr_def_t *def;
pr_type_t *str = 0;
if (pr->debug)
@ -348,7 +348,7 @@ PR_LoadDebug (progs_t *pr)
pr->auxfunctions = (pr_auxfunction_t*)((char*)pr->debug +
pr->debug->auxfunctions);
pr->linenos = (pr_lineno_t*)((char*)pr->debug + pr->debug->linenos);
pr->local_defs = (ddef_t*)((char*)pr->debug + pr->debug->locals);
pr->local_defs = (pr_def_t*)((char*)pr->debug + pr->debug->locals);
i = pr->progs->numfunctions * sizeof (pr_auxfunction_t *);
pr->auxfunction_map = pr->allocate_progs_mem (pr, i);
@ -377,7 +377,7 @@ PR_LoadDebug (progs_t *pr)
for (i = 0; i < pr->debug->num_locals; i++) {
pr->local_defs[i].type = LittleShort (pr->local_defs[i].type);
pr->local_defs[i].ofs = LittleShort (pr->local_defs[i].ofs);
pr->local_defs[i].s_name = LittleLong (pr->local_defs[i].s_name);
pr->local_defs[i].name = LittleLong (pr->local_defs[i].name);
}
return 1;
}
@ -474,12 +474,12 @@ PR_Get_Source_Line (progs_t *pr, pr_uint_t addr)
file->lines[line - 1].text);
}
ddef_t *
pr_def_t *
PR_Get_Param_Def (progs_t *pr, dfunction_t *func, unsigned parm)
{
pr_uint_t i;
pr_auxfunction_t *aux_func;
ddef_t *ddef = 0;
pr_def_t *ddef = 0;
int num_params;
int param_offs = 0;
@ -522,7 +522,7 @@ static etype_t
get_etype (progs_t *pr, int typeptr)
{
//FIXME cache .type_encodings def
ddef_t *te_def = PR_FindGlobal (pr, ".type_encodings");
pr_def_t *te_def = PR_FindGlobal (pr, ".type_encodings");
qfot_type_encodings_t *encodings;
qfot_type_t *type;
@ -538,8 +538,8 @@ get_etype (progs_t *pr, int typeptr)
return ev_void;
}
ddef_t *
PR_Get_Local_Def (progs_t *pr, pr_int_t offs)
pr_def_t *
PR_Get_Local_Def (progs_t *pr, pointer_t offs)
{
pr_uint_t i;
dfunction_t *func;
@ -554,7 +554,7 @@ PR_Get_Local_Def (progs_t *pr, pr_int_t offs)
if (!aux_func)
return 0;
offs -= func->parm_start;
if (offs < 0 || offs >= func->locals)
if (offs >= func->locals)
return 0;
for (i = 0; i < aux_func->num_locals; i++)
if (pr->local_defs[aux_func->local_defs + i].ofs == offs)
@ -594,7 +594,7 @@ static const char *
value_string (progs_t *pr, etype_t type, pr_type_t *val)
{
static dstring_t *line;
ddef_t *def;
pr_def_t *def;
pr_int_t ofs;
edict_t *edict;
dfunction_t *f;
@ -655,7 +655,7 @@ value_string (progs_t *pr, etype_t type, pr_type_t *val)
case ev_field:
def = PR_FieldAtOfs (pr, val->integer_var);
if (def)
dsprintf (line, ".%s", PR_GetString (pr, def->s_name));
dsprintf (line, ".%s", PR_GetString (pr, def->name));
else
dsprintf (line, ".<$%04x>", val->integer_var);
break;
@ -679,8 +679,8 @@ value_string (progs_t *pr, etype_t type, pr_type_t *val)
def = PR_Get_Local_Def (pr, ofs);
if (!def)
def = PR_GlobalAtOfs (pr, ofs);
if (def && def->s_name)
dsprintf (line, "&%s", PR_GetString (pr, def->s_name));
if (def && def->name)
dsprintf (line, "&%s", PR_GetString (pr, def->name));
else
dsprintf (line, "[$%x]", ofs);
break;
@ -711,17 +711,17 @@ value_string (progs_t *pr, etype_t type, pr_type_t *val)
return line->str;
}
static ddef_t *
static pr_def_t *
def_string (progs_t *pr, pr_int_t ofs, dstring_t *dstr)
{
ddef_t *def = 0;
pr_def_t *def = 0;
const char *name;
if (pr_debug->int_val && pr->debug)
def = PR_Get_Local_Def (pr, ofs);
if (!def)
def = PR_GlobalAtOfs (pr, ofs);
if (!def || !*(name = PR_GetString (pr, def->s_name)))
if (!def || !*(name = PR_GetString (pr, def->name)))
dsprintf (dstr, "[$%x]", ofs);
else
dsprintf (dstr, "%s", name);
@ -732,7 +732,7 @@ static const char *
global_string (progs_t *pr, pointer_t ofs, etype_t type, int contents)
{
static dstring_t *line = NULL;
ddef_t *def = NULL;
pr_def_t *def = NULL;
const char *s;
if (!line)
@ -771,7 +771,7 @@ global_string (progs_t *pr, pointer_t ofs, etype_t type, int contents)
VISIBLE void
PR_Debug_Watch (progs_t *pr, const char *expr)
{
ddef_t watch;
pr_def_t watch;
if (!expr) {
Sys_Printf ("watch <watchpoint expr>\n");
if (pr->watch) {
@ -802,7 +802,7 @@ PR_Debug_Watch (progs_t *pr, const char *expr)
VISIBLE void
PR_Debug_Print (progs_t *pr, const char *expr)
{
ddef_t print;
pr_def_t print;
if (!expr) {
Sys_Printf ("print <print expr>\n");
@ -825,7 +825,7 @@ PR_PrintStatement (progs_t *pr, dstatement_t *s, int contents)
opcode_t *op;
static dstring_t *line;
dfunction_t *call_func = 0;
ddef_t *parm_def = 0;
pr_def_t *parm_def = 0;
pr_auxfunction_t *aux_func = 0;
if (!line)
@ -1075,7 +1075,7 @@ ED_Print (progs_t *pr, edict_t *ed)
int type, l;
pr_uint_t i;
const char *name;
ddef_t *d;
pr_def_t *d;
pr_type_t *v;
if (ed->free) {
@ -1086,9 +1086,9 @@ ED_Print (progs_t *pr, edict_t *ed)
Sys_Printf ("\nEDICT %d:\n", NUM_FOR_BAD_EDICT (pr, ed));
for (i = 0; i < pr->progs->numfielddefs; i++) {
d = &pr->pr_fielddefs[i];
if (!d->s_name) // null field def (probably 1st)
if (!d->name) // null field def (probably 1st)
continue;
name = PR_GetString (pr, d->s_name);
name = PR_GetString (pr, d->name);
if (name[strlen (name) - 2] == '_'
&& strchr ("xyz", name[strlen (name) -1]))
continue; // skip _x, _y, _z vars

View file

@ -158,7 +158,7 @@ ED_PrintEdicts (progs_t *pr, const char *fieldval)
{
pr_int_t i;
int count;
ddef_t *def;
pr_def_t *def;
def = PR_FindField(pr, "classname");
@ -188,8 +188,8 @@ ED_Count (progs_t *pr)
{
pr_int_t i;
int active, models, solid, step, zombie;
ddef_t *solid_def;
ddef_t *model_def;
pr_def_t *solid_def;
pr_def_t *model_def;
edict_t *ent;
solid_def = PR_FindField (pr, "solid");

View file

@ -70,8 +70,8 @@ static const char *
var_get_key (const void *d, void *_pr)
{
progs_t *pr = (progs_t*)_pr;
ddef_t *def = (ddef_t*)d;
return PR_GetString (pr, def->s_name);
pr_def_t *def = (pr_def_t*)d;
return PR_GetString (pr, def->name);
}
static void
@ -119,6 +119,8 @@ PR_LoadProgsFile (progs_t *pr, QFile *file, int size)
dprograms_t progs;
byte *base;
byte *heap;
pr_def_t *xdefs_def = 0;
if (!pr->file_error)
pr->file_error = file_error;
@ -220,8 +222,8 @@ PR_LoadProgsFile (progs_t *pr, QFile *file, int size)
(dfunction_t *) (base + pr->progs->ofs_functions);
pr->pr_strings = (char *) base + pr->progs->ofs_strings;
pr->pr_stringsize = (char *) heap + pr->zone_size - (char *) base;
pr->pr_globaldefs = (ddef_t *) (base + pr->progs->ofs_globaldefs);
pr->pr_fielddefs = (ddef_t *) (base + pr->progs->ofs_fielddefs);
pr->pr_globalddefs = (ddef_t *) (base + pr->progs->ofs_globaldefs);
pr->pr_fieldddefs = (ddef_t *) (base + pr->progs->ofs_fielddefs);
pr->pr_statements = (dstatement_t *) (base + pr->progs->ofs_statements);
pr->pr_globals = (pr_type_t *) (base + pr->progs->ofs_globals);
@ -272,24 +274,58 @@ PR_LoadProgsFile (progs_t *pr, QFile *file, int size)
Hash_Add (pr->function_hash, &pr->pr_functions[i]);
}
if (pr->pr_globaldefs) {
free (pr->pr_globaldefs);
}
pr->pr_globaldefs = calloc (pr->progs->numglobaldefs, sizeof (pr_def_t));
for (i = 0; i < pr->progs->numglobaldefs; i++) {
pr->pr_globaldefs[i].type = LittleShort (pr->pr_globaldefs[i].type);
pr->pr_globaldefs[i].ofs = LittleShort (pr->pr_globaldefs[i].ofs);
pr->pr_globaldefs[i].s_name = LittleLong (pr->pr_globaldefs[i].s_name);
pr->pr_globalddefs[i].type = LittleShort (pr->pr_globalddefs[i].type);
pr->pr_globalddefs[i].ofs = LittleShort (pr->pr_globalddefs[i].ofs);
pr->pr_globalddefs[i].s_name = LittleLong (pr->pr_globalddefs[i].s_name);
pr->pr_globaldefs[i].type = pr->pr_globalddefs[i].type;
pr->pr_globaldefs[i].ofs = pr->pr_globalddefs[i].ofs;
pr->pr_globaldefs[i].name = pr->pr_globalddefs[i].s_name;
Hash_Add (pr->global_hash, &pr->pr_globaldefs[i]);
}
if (pr->pr_fielddefs) {
free (pr->pr_fielddefs);
}
pr->pr_fielddefs = calloc (pr->progs->numfielddefs, sizeof (pr_def_t));
for (i = 0; i < pr->progs->numfielddefs; i++) {
pr->pr_fielddefs[i].type = LittleShort (pr->pr_fielddefs[i].type);
pr->pr_fieldddefs[i].type = LittleShort (pr->pr_fieldddefs[i].type);
if (pr->pr_fielddefs[i].type & DEF_SAVEGLOBAL)
PR_Error (pr, "PR_LoadProgs: pr_fielddefs[i].type & DEF_SAVEGLOBAL");
pr->pr_fielddefs[i].ofs = LittleShort (pr->pr_fielddefs[i].ofs);
pr->pr_fielddefs[i].s_name = LittleLong (pr->pr_fielddefs[i].s_name);
pr->pr_fieldddefs[i].ofs = LittleShort (pr->pr_fieldddefs[i].ofs);
pr->pr_fieldddefs[i].s_name = LittleLong (pr->pr_fieldddefs[i].s_name);
pr->pr_fielddefs[i].type = pr->pr_fieldddefs[i].type;
pr->pr_fielddefs[i].ofs = pr->pr_fieldddefs[i].ofs;
pr->pr_fielddefs[i].name = pr->pr_fieldddefs[i].s_name;
Hash_Add (pr->field_hash, &pr->pr_fielddefs[i]);
}
for (i = 0; i < pr->progs->numglobals; i++)
((int *) pr->pr_globals)[i] = LittleLong (((int *) pr->pr_globals)[i]);
xdefs_def = PR_FindGlobal (pr, ".xdefs");
if (xdefs_def) {
pr_xdefs_t *xdefs = &G_STRUCT (pr, pr_xdefs_t, xdefs_def->ofs);
xdef_t *xdef = &G_STRUCT (pr, xdef_t, xdefs->xdefs);
pr_def_t *def;
for (def = pr->pr_globaldefs, i = 0; i < pr->progs->numglobaldefs;
i++, xdef++, def++) {
def->ofs = xdef->ofs;
def->type_encoding = xdef->type;
}
for (def = pr->pr_fielddefs, i = 0; i < pr->progs->numfielddefs;
i++, xdef++, def++) {
def->ofs = xdef->ofs;
def->type_encoding = xdef->type;
}
}
}
VISIBLE void

View file

@ -1535,7 +1535,7 @@ check_global (progs_t *pr, dstatement_t *st, opcode_t *op, etype_t type,
unsigned short operand, int check_denorm)
{
const char *msg;
ddef_t *def;
pr_def_t *def;
switch (type) {
case ev_short:

View file

@ -71,7 +71,7 @@ static const char *
PR_UglyValueString (progs_t *pr, etype_t type, pr_type_t *val)
{
static dstring_t *line = 0;
ddef_t *def;
pr_def_t *def;
dfunction_t *f;
if (!line)
@ -93,7 +93,7 @@ PR_UglyValueString (progs_t *pr, etype_t type, pr_type_t *val)
break;
case ev_field:
def = PR_FieldAtOfs (pr, val->integer_var);
dsprintf (line, "%s", PR_GetString (pr, def->s_name));
dsprintf (line, "%s", PR_GetString (pr, def->name));
break;
case ev_void:
dstring_copystr (line, "void");
@ -131,9 +131,9 @@ ED_EntityDict (progs_t *pr, edict_t *ed)
if (!ed->free) {
for (i = 0; i < pr->progs->numfielddefs; i++) {
ddef_t *d = &pr->pr_fielddefs[i];
pr_def_t *d = &pr->pr_fielddefs[i];
name = PR_GetString (pr, d->s_name);
name = PR_GetString (pr, d->name);
if (!name[0])
continue; // skip unnamed fields
if (name[strlen (name) - 2] == '_')
@ -169,7 +169,7 @@ ED_GlobalsDict (progs_t *pr)
pr_uint_t i;
const char *name;
const char *value;
ddef_t *def;
pr_def_t *def;
int type;
for (i = 0; i < pr->progs->numglobaldefs; i++) {
@ -182,7 +182,7 @@ ED_GlobalsDict (progs_t *pr)
if (type != ev_string && type != ev_float && type != ev_entity)
continue;
name = PR_GetString (pr, def->s_name);
name = PR_GetString (pr, def->name);
value = PR_UglyValueString (pr, type, &pr->pr_globals[def->ofs]);
PL_D_AddObject (globals, name, PL_NewString (value));
}
@ -222,11 +222,11 @@ ED_NewString (progs_t *pr, const char *string)
returns false if error
*/
VISIBLE qboolean
ED_ParseEpair (progs_t *pr, pr_type_t *base, ddef_t *key, const char *s)
ED_ParseEpair (progs_t *pr, pr_type_t *base, pr_def_t *key, const char *s)
{
int i;
char *string;
ddef_t *def;
pr_def_t *def;
char *v, *w;
pr_type_t *d;
dfunction_t *func;
@ -357,8 +357,8 @@ ED_ConvertToPlist (script_t *script, int nohack)
VISIBLE void
ED_InitGlobals (progs_t *pr, plitem_t *globals)
{
ddef_t vector_def;
ddef_t *global;
pr_def_t vector_def;
pr_def_t *global;
plitem_t *keys;
int count;
const char *global_name;
@ -405,7 +405,7 @@ ED_InitGlobals (progs_t *pr, plitem_t *globals)
VISIBLE void
ED_InitEntity (progs_t *pr, plitem_t *entity, edict_t *ent)
{
ddef_t *field;
pr_def_t *field;
plitem_t *keys;
const char *field_name;
const char *value;

View file

@ -52,10 +52,10 @@
#include "compat.h"
ddef_t *
PR_GlobalAtOfs (progs_t * pr, pr_int_t ofs)
pr_def_t *
PR_GlobalAtOfs (progs_t * pr, pointer_t ofs)
{
ddef_t *def;
pr_def_t *def;
pr_uint_t i;
for (i = 0; i < pr->progs->numglobaldefs; i++) {
@ -66,10 +66,10 @@ PR_GlobalAtOfs (progs_t * pr, pr_int_t ofs)
return NULL;
}
VISIBLE ddef_t *
PR_FieldAtOfs (progs_t * pr, pr_int_t ofs)
VISIBLE pr_def_t *
PR_FieldAtOfs (progs_t * pr, pointer_t ofs)
{
ddef_t *def;
pr_def_t *def;
pr_uint_t i;
for (i = 0; i < pr->progs->numfielddefs; i++) {
@ -80,13 +80,13 @@ PR_FieldAtOfs (progs_t * pr, pr_int_t ofs)
return NULL;
}
VISIBLE ddef_t *
VISIBLE pr_def_t *
PR_FindField (progs_t * pr, const char *name)
{
return Hash_Find (pr->field_hash, name);
}
VISIBLE ddef_t *
VISIBLE pr_def_t *
PR_FindGlobal (progs_t * pr, const char *name)
{
return Hash_Find (pr->global_hash, name);
@ -108,7 +108,7 @@ VISIBLE int
PR_ResolveGlobals (progs_t *pr)
{
const char *sym;
ddef_t *def;
pr_def_t *def;
int i;
if (pr->progs->version == PROG_ID_VERSION) {
@ -180,7 +180,7 @@ int
PR_AccessField (progs_t *pr, const char *name, etype_t type,
const char *file, int line)
{
ddef_t *def = PR_FindField (pr, name);
pr_def_t *def = PR_FindField (pr, name);
if (!def)
PR_Error (pr, "undefined field %s accessed at %s:%d", name, file, line);

View file

@ -255,7 +255,7 @@ PF_Find (progs_t *pr)
int i; // ev_vector
int e, f;
etype_t type;
ddef_t *field_def;
pr_def_t *field_def;
edict_t *ed;
e = P_EDICTNUM (pr, 0);
@ -596,7 +596,7 @@ static void
PF_PR_SetField (progs_t *pr)
{
edict_t *ent = P_EDICT (pr, 0);
ddef_t *field = PR_FindField (pr, P_GSTRING (pr, 1));
pr_def_t *field = PR_FindField (pr, P_GSTRING (pr, 1));
const char *value = P_GSTRING (pr, 2);
R_INT (pr) = 0;

View file

@ -1550,7 +1550,7 @@ static void
rua_PR_FindGlobal (progs_t *pr)
{
const char *name = P_GSTRING (pr, 0);
ddef_t *def;
pr_def_t *def;
R_POINTER (pr) = 0;
def = PR_FindGlobal (pr, name);
@ -1654,7 +1654,7 @@ rua_init_finish (progs_t *pr)
static int
rua_init_runtime (progs_t *pr)
{
ddef_t *def;
pr_def_t *def;
unsigned i;
if (!pr->selector_hash)

View file

@ -379,7 +379,7 @@ set_address (sv_def_t *def, void *address)
static int
resolve_globals (progs_t *pr, sv_def_t *def, int mode)
{
ddef_t *ddef;
pr_def_t *ddef;
int ret = 1;
if (mode == 2) {
@ -425,7 +425,7 @@ resolve_functions (progs_t *pr, sv_def_t *def, int mode)
static int
resolve_fields (progs_t *pr, sv_def_t *def, int mode)
{
ddef_t *ddef;
pr_def_t *ddef;
int ret = 1;
if (mode == 2) {

View file

@ -551,7 +551,7 @@ static int
qwe_load_finish (progs_t *pr)
{
edict_t *ent;
ddef_t *targetname;
pr_def_t *targetname;
targetname = PR_FindField (pr, "targetname");
ent = EDICT_NUM (pr, 0);

View file

@ -389,7 +389,7 @@ set_address (sv_def_t *def, void *address)
static int
resolve_globals (progs_t *pr, sv_def_t *def, int mode)
{
ddef_t *ddef;
pr_def_t *ddef;
int ret = 1;
if (mode == 2) {
@ -435,7 +435,7 @@ resolve_functions (progs_t *pr, sv_def_t *def, int mode)
static int
resolve_fields (progs_t *pr, sv_def_t *def, int mode)
{
ddef_t *ddef;
pr_def_t *ddef;
int ret = 1;
if (mode == 2) {

View file

@ -52,14 +52,14 @@
static int
cmp (const void *_a, const void *_b)
{
const ddef_t *a = (const ddef_t *)_a;
const ddef_t *b = (const ddef_t *)_b;
const pr_def_t *a = (const pr_def_t *)_a;
const pr_def_t *b = (const pr_def_t *)_b;
return a->ofs - b->ofs;
}
static void
dump_def (progs_t *pr, ddef_t *def, int indent)
dump_def (progs_t *pr, pr_def_t *def, int indent)
{
const char *name;
const char *type;
@ -69,10 +69,10 @@ dump_def (progs_t *pr, ddef_t *def, int indent)
const char *str;
int saveglobal;
if (!def->type && !def->ofs && !def->s_name)
if (!def->type && !def->ofs && !def->name)
return;
name = PR_GetString (pr, def->s_name);
name = PR_GetString (pr, def->name);
type = pr_type_name[def->type & ~DEF_SAVEGLOBAL];
saveglobal = (def->type & DEF_SAVEGLOBAL) != 0;
offset = def->ofs;
@ -148,15 +148,15 @@ dump_def (progs_t *pr, ddef_t *def, int indent)
break;
}
}
printf ("%*s %x %d %s %s%s\n", indent * 12, "",
offset, saveglobal, name, type, comment);
printf ("%*s %x %d %s %s:%x %s\n", indent * 12, "",
offset, saveglobal, name, type, def->type_encoding, comment);
}
void
dump_globals (progs_t *pr)
{
unsigned int i;
ddef_t *global_defs = pr->pr_globaldefs;
pr_def_t *global_defs = pr->pr_globaldefs;
if (sorted) {
global_defs = malloc (pr->progs->numglobaldefs * sizeof (ddef_t));
@ -165,7 +165,7 @@ dump_globals (progs_t *pr)
qsort (global_defs, pr->progs->numglobaldefs, sizeof (ddef_t), cmp);
}
for (i = 0; i < pr->progs->numglobaldefs; i++) {
ddef_t *def = &global_defs[i];
pr_def_t *def = &global_defs[i];
dump_def (pr, def, 0);
}
}
@ -180,9 +180,9 @@ dump_fields (progs_t *pr)
const char *comment;
for (i = 0; i < pr->progs->numfielddefs; i++) {
ddef_t *def = &pr->pr_fielddefs[i];
pr_def_t *def = &pr->pr_fielddefs[i];
name = PR_GetString (pr, def->s_name);
name = PR_GetString (pr, def->name);
type = pr_type_name[def->type & ~DEF_SAVEGLOBAL];
offset = def->ofs;
@ -516,7 +516,7 @@ dump_types (progs_t *pr)
{
qfo_mspace_t spaces[qfo_num_spaces];
qfo_t qfo;
ddef_t *encodings_def;
pr_def_t *encodings_def;
qfot_type_encodings_t *encodings;
encodings_def = PR_FindGlobal (pr, ".type_encodings");

View file

@ -205,11 +205,11 @@ dump_modules (progs_t *pr)
unsigned int i;
for (i = 0; i < pr->progs->numglobaldefs; i++) {
ddef_t *def = &pr->pr_globaldefs[i];
pr_def_t *def = &pr->pr_globaldefs[i];
const char *name = "<invalid_string>";
if (PR_StringValid (pr, def->s_name))
name = PR_GetString (pr, def->s_name);
if (PR_StringValid (pr, def->name))
name = PR_GetString (pr, def->name);
if (strcmp (name, "_OBJ_MODULE") == 0) {
printf ("module @ %x\n", def->ofs);
dump_module (pr, &G_STRUCT (pr, pr_module_t, def->ofs));

View file

@ -926,6 +926,7 @@ qfo_to_progs (qfo_t *qfo, int *size)
progs->numglobals = RUP (progs->numglobals, type_xdef.alignment);
xdefs_start = progs->numglobals;
progs->numglobals += progs->numglobaldefs * type_size (&type_xdef);
progs->numglobals += progs->numfielddefs * type_size (&type_xdef);
progs->entityfields = qfo->spaces[qfo_entity_space].data_size;
*size += progs->numstatements * sizeof (dstatement_t);
*size += progs->numglobaldefs * sizeof (ddef_t);
@ -1012,10 +1013,6 @@ qfo_to_progs (qfo_t *qfo, int *size)
globaldefs++;
}
for (i = 0; i < qfo->spaces[qfo_type_space].num_defs; i++) {
qfo->spaces[qfo_type_space].defs[i].offset += type_data - globals;
}
for (i = 0; i < qfo->spaces[qfo_entity_space].num_defs; i++) {
convert_def (qfo, qfo->spaces[qfo_entity_space].defs + i,
fielddefs + i);
@ -1044,21 +1041,27 @@ qfo_to_progs (qfo_t *qfo, int *size)
encodings->size = qfo->spaces[qfo_type_space].data_size;
}
if (xdefs_def) {
int xdef_data_size = type_size (&type_xdef);
pr_xdefs_t *xdefs = (pr_xdefs_t *) &globals[xdefs_def->offset];
pr_xdefs_t *xdefs = (pr_xdefs_t *) &globals[xdefs_def->offset];
xdef_t *xdef = (xdef_t *) xdef_data;
xdefs->xdefs = xdefs_start;
xdefs->num_xdefs = progs->numglobaldefs;
for (i = 0; i < qfo->spaces[qfo_near_data_space].num_defs; i++) {
xdefs->num_xdefs = progs->numglobaldefs + progs->numfielddefs;
for (i = 0; i < qfo->spaces[qfo_near_data_space].num_defs;
i++, xdef++) {
qfo_def_t *def = qfo->spaces[qfo_near_data_space].defs + i;
xdef_data[0].pointer_var = def->type + type_encodings_start;
xdef_data[1].pointer_var = def->offset;
xdef_data += xdef_data_size;
xdef->type = def->type + type_encodings_start;
xdef->ofs = def->offset;
}
for (i = 0; i < qfo->spaces[qfo_far_data_space].num_defs; i++) {
for (i = 0; i < qfo->spaces[qfo_far_data_space].num_defs;
i++, xdef++) {
qfo_def_t *def = qfo->spaces[qfo_far_data_space].defs + i;
xdef_data[0].pointer_var = def->type + type_encodings_start;
xdef_data[1].pointer_var = def->offset;
xdef_data += xdef_data_size;
xdef->type = def->type + type_encodings_start;
xdef->ofs = def->offset;
}
for (i = 0; i < qfo->spaces[qfo_entity_space].num_defs;
i++, xdef++) {
qfo_def_t *def = qfo->spaces[qfo_entity_space].defs + i;
xdef->type = def->type + type_encodings_start;
xdef->ofs = def->offset;
}
}
@ -1108,7 +1111,7 @@ qfo_to_sym (qfo_t *qfo, int *size)
pr_auxfunction_t *auxfuncs;
pr_auxfunction_t *aux;
pr_lineno_t *linenos;
ddef_t *locals, *ld;
pr_def_t *locals, *ld;
*size = sizeof (pr_debug_header_t);
sym = calloc (1, *size);
@ -1129,12 +1132,12 @@ qfo_to_sym (qfo_t *qfo, int *size)
*size += sym->num_auxfunctions * sizeof (pr_auxfunction_t);
*size += sym->num_linenos * sizeof (pr_lineno_t);
*size += sym->num_locals * sizeof (ddef_t);
*size += sym->num_locals * sizeof (pr_def_t);
sym = realloc (sym, *size);
auxfuncs = (pr_auxfunction_t *)(sym + 1);
linenos = (pr_lineno_t *)(auxfuncs + sym->num_auxfunctions);
locals = (ddef_t *)(linenos + sym->num_linenos);
locals = (pr_def_t *)(linenos + sym->num_linenos);
sym->auxfunctions = (char *) auxfuncs - (char *) sym;
sym->linenos = (char *) linenos - (char *) sym;
@ -1162,8 +1165,13 @@ qfo_to_sym (qfo_t *qfo, int *size)
qfo->lines[func->line_info].fa.func = aux - auxfuncs;
if (num_locals) {
aux->local_defs = ld - locals;
for (j = 0; j < num_locals; j++)
convert_def (qfo, def++, ld++);
for (j = 0; j < num_locals; j++, def++, ld++) {
ld->type = get_def_type (qfo, def->type);
ld->type = def->type;
ld->ofs = def->offset;
ld->name = def->name;
ld->type_encoding = def->type;
}
}
aux->num_locals = num_locals;
//FIXME check type

View file

@ -256,6 +256,9 @@ convert_qfo (void)
{
int size;
int i;
xdef_t *xdef = 0;
pr_xdefs_t *xdefs = 0;
ddef_t *xdefs_def = 0;
pr.progs = qfo_to_progs (qfo, &size);
@ -264,20 +267,52 @@ convert_qfo (void)
pr.pr_strings = P (char, ofs_strings);
pr.pr_stringsize = pr.progs->numstrings;
pr.pr_functions = P (dfunction_t, ofs_functions);
pr.pr_globaldefs = P (ddef_t, ofs_globaldefs);
pr.pr_fielddefs = P (ddef_t, ofs_fielddefs);
pr.pr_globalddefs = P (ddef_t, ofs_globaldefs);
pr.pr_fieldddefs = P (ddef_t, ofs_fielddefs);
pr.pr_globals = P (pr_type_t, ofs_globals);
pr.globals_size = pr.progs->numglobals;
pr.pr_edict_size = max (1, pr.progs->entityfields) * 4;
pr.pr_edictareasize = 1 * pr.pr_edict_size;
#undef P
pr.pr_globaldefs = malloc ((pr.progs->numglobaldefs
+ pr.progs->numfielddefs)
* sizeof (pr_def_t));
// can't use PR_FindGlobal yet as pr_globaldefs is still uninitialized
for (i = 0; i < (int) pr.progs->numglobaldefs; i++) {
ddef_t *ddef = pr.pr_globalddefs + i;
if (!strcmp (PR_GetString (&pr, ddef->s_name), ".xdefs")) {
xdefs_def = ddef;
break;
}
}
if (xdefs_def) {
xdefs = &G_STRUCT (&pr, pr_xdefs_t, xdefs_def->ofs);
xdef = &G_STRUCT (&pr, xdef_t, xdefs->xdefs);
}
for (i = 0; i < (int) pr.progs->numglobaldefs; i++, xdef++) {
ddef_t *ddef = pr.pr_globalddefs + i;
pr_def_t *def = pr.pr_globaldefs + i;
def->type = ddef->type;
def->ofs = xdefs ? xdef->ofs : ddef->ofs;
def->name = ddef->s_name;
def->type_encoding = xdefs ? xdef->type : 0;
}
for (i = 0; i < (int) pr.progs->numfielddefs; i++, xdef++) {
ddef_t *ddef = pr.pr_fieldddefs + i;
pr_def_t *def = pr.pr_fielddefs + i;
def->type = ddef->type;
def->ofs = xdefs ? xdef->ofs : ddef->ofs;
def->name = ddef->s_name;
def->type_encoding = xdefs ? xdef->type : 0;
}
if (verbosity) {
pr.debug = qfo_to_sym (qfo, &size);
#define P(t,o) ((t *)((char *)pr.debug + pr.debug->o))
pr.auxfunctions = P (pr_auxfunction_t, auxfunctions);
pr.linenos = P (pr_lineno_t, linenos);
pr.local_defs = P (ddef_t, locals);
pr.local_defs = P (pr_def_t, locals);
#undef P
pr.local_defs = calloc (qfo->num_defs, sizeof (ddef_t));