Slightly better decompiler behaviours.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@5651 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2020-03-15 06:58:03 +00:00
parent 2152eda3d0
commit 5016371660
3 changed files with 67 additions and 59 deletions

View file

@ -1705,7 +1705,7 @@ void DecompileIndent(int c)
void DecompileOpcode(dfunction_t *df, int a, int b, int c, char *opcode, QCC_type_t *typ1, QCC_type_t *typ2, QCC_type_t *typ3, int usebrackets, int *indent)
{
static char line[512];
static char line[8192];
char *arg1, *arg2, *arg3;
arg1 = DecompileGet(df, a, typ1);
arg2 = DecompileGet(df, b, typ2);
@ -1897,20 +1897,18 @@ void DecompileDecompileStatement(dfunction_t * df, dstatement_t * s, int *indent
if ((k->op >= OP_CALL0 && k->op <= OP_CALL8) || (k->op >= OP_CALL1H && k->op <= OP_CALL8H))
{
//well, this is it.
int fn;
int fn = ((int*)pr_globals)[k->a];
dfunction_t *cf = &functions[fn];
int bi = DecompileBuiltin(cf);
int pn;
dfunction_t *cf;
QCC_ddef_t *def;
int bi = DecompileBuiltin(df);
fn = ((int*)pr_globals)[k->a];
cf = &functions[fn];
if (bi) //builtins don't have this info.
{
if (bi)
{ //builtins don't have valid parm_start values
QCC_type_t **p = builtins[bi].params[(s->b-ofs_parms[0])/ofs_size];
parmtype = p?*p:NULL;
}
else
{
{ //qc functions do, though.
fn = cf->parm_start;
for (pn = 0; pn < (s->b-ofs_parms[0])/ofs_size; pn++)
fn += cf->parm_size[pn];
@ -2286,6 +2284,9 @@ void DecompileDecompileStatement(dfunction_t * df, dstatement_t * s, int *indent
QCC_CatVFile(Decompileofile, "{\n");
(*indent)++;
//FIXME: look for the next control statement (ignoring writes to temps, maybe allow functions too if the following statement reads OFS_RETURN)
//if its an IFNOT (optionally with its own else) that ends at our else then output this as "}\nelse " instead
}
else
{
@ -2514,6 +2515,7 @@ const char *GetMatchingField(QCC_ddef_t *field)
int i;
QCC_ddef_t *def;
int ld, lf;
const char *ret = NULL;
def = NULL;
@ -2526,21 +2528,22 @@ const char *GetMatchingField(QCC_ddef_t *field)
if (((int*)pr_globals)[def->ofs] == field->ofs)
{
if (!strcmp(strings+def->s_name, strings+field->s_name))
break; //found ourself, give up.
return NULL; //found ourself, give up.
lf = strlen(strings + field->s_name);
ld = strlen(strings + def->s_name);
if (lf - 2 == ld)
{
if ((strings + field->s_name)[lf-2] == '_')
if ((strings + field->s_name)[lf-2] == '_' && (strings + field->s_name)[lf-1] == 'x')
if (!strncmp(strings + field->s_name, strings + def->s_name, ld))
break;
return NULL; //vector found foo_x
}
return def->s_name+strings;
if (!ret)
ret = def->s_name+strings;
}
}
}
return NULL;
return ret;
}
QCC_ddef_t *GetField(const char *name)
@ -3100,9 +3103,10 @@ void DecompileDecompileFunctions(const char *origcopyright)
unsigned int o;
dfunction_t *d;
pbool bogusname;
vfile_t *f;
vfile_t *f = NULL;
char fname[512];
int lastglob = 1;
int lastfileofs = 0;
QCC_ddef_t *def;
DecompileCalcProfiles();
@ -3148,6 +3152,9 @@ void DecompileDecompileFunctions(const char *origcopyright)
{
d = &functions[i];
if (d->s_file != lastfileofs || f == NULL)
{
lastfileofs = d->s_file;
fname[0] = '\0';
if (d->s_file <= strofs && d->s_file >= 0)
sprintf(fname, "%s", strings + d->s_file);
@ -3201,6 +3208,7 @@ void DecompileDecompileFunctions(const char *origcopyright)
printf("Fatal Error - Could not open \"%s\" for output.\n", fname);
exit(1);
}
}
Decompileofile = f;
DecompileFunction(strings + d->s_name, &lastglob);
}

View file

@ -6589,7 +6589,7 @@ static QCC_sref_t QCC_PR_ParseFunctionCall (QCC_ref_t *funcref) //warning, the f
if (arg == 0)
{
// save information for model and sound caching
if (!strncmp(funcname,"precache_", 9) && e->cast->type == ev_string && e->type == REF_GLOBAL)
if (!strncmp(funcname,"precache_", 9) && e->cast->type == ev_string && e->base.cast->type == ev_string && e->type == REF_GLOBAL)
{
const QCC_eval_t *eval = QCC_SRef_EvalConst(e->base);
if (eval)

View file

@ -1083,7 +1083,7 @@ vfile_t *QCC_AddVFile(const char *name, void *data, size_t size)
void QCC_CatVFile(vfile_t *f, const char *fmt, ...)
{
va_list argptr;
char msg[8192];
char msg[65536];
size_t n;
va_start (argptr,fmt);
@ -1103,7 +1103,7 @@ void QCC_CatVFile(vfile_t *f, const char *fmt, ...)
void QCC_InsertVFile(vfile_t *f, size_t pos, const char *fmt, ...)
{
va_list argptr;
char msg[8192];
char msg[65536];
size_t n;
va_start (argptr,fmt);
QC_vsnprintf (msg,sizeof(msg)-1, fmt, argptr);