2007-01-15 12:09:25 -08:00
|
|
|
/*
|
|
|
|
This file is part of Warzone 2100.
|
|
|
|
Copyright (C) 1999-2004 Eidos Interactive
|
|
|
|
Copyright (C) 2005-2007 Warzone Resurrection Project
|
|
|
|
|
|
|
|
Warzone 2100 is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Warzone 2100 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Warzone 2100; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2007-06-28 10:47:08 -07:00
|
|
|
/*
|
|
|
|
* CodePrint.c
|
|
|
|
*
|
|
|
|
* Routines for displaying compiled scripts
|
|
|
|
*/
|
|
|
|
|
2006-06-02 12:34:58 -07:00
|
|
|
#include "lib/framework/frame.h"
|
2007-06-28 10:47:08 -07:00
|
|
|
#include "interp.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "codeprint.h"
|
|
|
|
#include "script.h"
|
|
|
|
|
|
|
|
/* Display a value type */
|
|
|
|
void cpPrintType(INTERP_TYPE type)
|
|
|
|
{
|
|
|
|
UDWORD i;
|
|
|
|
BOOL ref = FALSE;
|
|
|
|
|
|
|
|
if (type & VAL_REF)
|
|
|
|
{
|
|
|
|
ref = TRUE;
|
2006-11-02 11:26:55 -08:00
|
|
|
type = (INTERP_TYPE)(type & ~VAL_REF);
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case VAL_BOOL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "BOOL" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_INT:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "INT" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
/* case VAL_FLOAT:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "FLOAT" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;*/
|
|
|
|
case VAL_STRING:
|
2006-11-03 13:35:50 -08:00
|
|
|
debug( LOG_NEVER, "char" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_TRIGGER:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "TRIGGER" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_EVENT:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "EVENT" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_VOID:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "VOID" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// See if it is a user defined type
|
|
|
|
if (asScrTypeTab)
|
|
|
|
{
|
|
|
|
for(i=0; asScrTypeTab[i].typeID != 0; i++)
|
|
|
|
{
|
|
|
|
if (asScrTypeTab[i].typeID == type)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%s", asScrTypeTab[i].pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( FALSE, "cpPrintType: Unknown type" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ref)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, " REF" );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Display a value */
|
|
|
|
void cpPrintVal(INTERP_VAL *psVal)
|
|
|
|
{
|
|
|
|
UDWORD i;
|
|
|
|
|
|
|
|
if (psVal->type & VAL_REF)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "type: " );
|
2007-06-28 10:47:08 -07:00
|
|
|
cpPrintType(psVal->type);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, " value: %x", psVal->v.ival );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(psVal->type)
|
|
|
|
{
|
|
|
|
case VAL_BOOL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "type: BOOL value: %s", psVal->v.bval ? "true" : "false" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_INT:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "type: INT value: %d", psVal->v.ival );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
/* case VAL_FLOAT:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "type: FLOAT value: %f", psVal->v.fval );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;*/
|
|
|
|
case VAL_STRING:
|
2006-11-03 13:35:50 -08:00
|
|
|
debug( LOG_NEVER, "type: char value: %s", psVal->v.sval );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_TRIGGER:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "type: TRIGGER value: %d", psVal->v.ival );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_EVENT:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "type: EVENT value: %d", psVal->v.ival );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// See if it is a user defined type
|
|
|
|
if (asScrTypeTab)
|
|
|
|
{
|
|
|
|
for(i=0; asScrTypeTab[i].typeID != 0; i++)
|
|
|
|
{
|
|
|
|
if (asScrTypeTab[i].typeID == psVal->type)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "type: %s value: %x", asScrTypeTab[i].pIdent, psVal->v.ival );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( FALSE, "cpPrintVal: Unknown value type" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Display a value from a program that has been packed with an opcode */
|
2006-11-17 03:25:03 -08:00
|
|
|
void cpPrintPackedVal(INTERP_VAL *ip)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
2006-11-17 03:25:03 -08:00
|
|
|
INTERP_TYPE type = (INTERP_TYPE)(ip->v.ival & OPCODE_DATAMASK);
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD i;
|
2006-11-17 03:25:03 -08:00
|
|
|
INTERP_VAL data;
|
|
|
|
|
|
|
|
/* copy value */
|
|
|
|
memcpy(&data, (INTERP_VAL *)(ip + 1), sizeof(INTERP_VAL));
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
if (type & VAL_REF)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "type: " );
|
2007-06-28 10:47:08 -07:00
|
|
|
cpPrintType(type);
|
2007-02-19 06:10:44 -08:00
|
|
|
debug( LOG_NEVER, " value: %x", data.type );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case VAL_BOOL:
|
2006-11-17 03:25:03 -08:00
|
|
|
debug( LOG_NEVER, "BOOL : %s", data.v.bval ? "true" : "false" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_INT:
|
2006-11-17 03:25:03 -08:00
|
|
|
debug( LOG_NEVER, "INT : %d", data.v.ival);
|
|
|
|
break;
|
|
|
|
case VAL_FLOAT:
|
|
|
|
debug( LOG_NEVER, "FLOAT : %f", data.v.fval );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_STRING:
|
2006-11-17 03:25:03 -08:00
|
|
|
debug( LOG_NEVER, "char : %s", data.v.sval );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_TRIGGER:
|
2006-11-17 03:25:03 -08:00
|
|
|
debug( LOG_NEVER, "TRIGGER : %d", data.v.ival );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case VAL_EVENT:
|
2006-11-17 03:25:03 -08:00
|
|
|
debug( LOG_NEVER, "EVENT : %d", data.v.ival );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// See if it is a user defined type
|
|
|
|
if (asScrTypeTab)
|
|
|
|
{
|
|
|
|
for(i=0; asScrTypeTab[i].typeID != 0; i++)
|
|
|
|
{
|
|
|
|
if (asScrTypeTab[i].typeID == type)
|
|
|
|
{
|
2007-02-19 06:10:44 -08:00
|
|
|
debug( LOG_NEVER, "type: %s value: %x", asScrTypeTab[i].pIdent, data.v.ival );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( FALSE, "cpPrintVal: Unknown value type" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Display a maths operator */
|
|
|
|
void cpPrintMathsOp(UDWORD opcode)
|
|
|
|
{
|
|
|
|
switch (opcode)
|
|
|
|
{
|
|
|
|
case OP_ADD:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "ADD" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_SUB:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "SUB" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_MUL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "MUL" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_DIV:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "DIV" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_NEG:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "NEG" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
2006-12-02 15:27:00 -08:00
|
|
|
case OP_DEC:
|
|
|
|
debug( LOG_NEVER, "DED" );
|
|
|
|
break;
|
|
|
|
case OP_INC:
|
|
|
|
debug( LOG_NEVER, "INC" );
|
|
|
|
break;
|
2007-06-28 10:47:08 -07:00
|
|
|
case OP_AND:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "AND" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_OR:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "OR" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_NOT:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "NOT" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_EQUAL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "EQUAL" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_NOTEQUAL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "NOT_EQUAL" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_GREATEREQUAL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "GRT_EQUAL" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_LESSEQUAL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "LESS_EQUAL" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_GREATER:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "GREATER" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_LESS:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "LESS" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
default:
|
2006-08-23 05:58:48 -07:00
|
|
|
ASSERT( FALSE, "cpPrintMathsOp: unknown operator" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Print a function name */
|
|
|
|
void cpPrintFunc(SCRIPT_FUNC pFunc)
|
|
|
|
{
|
|
|
|
SDWORD i;
|
|
|
|
|
|
|
|
// Search the instinct functions
|
|
|
|
if (asScrInstinctTab)
|
|
|
|
{
|
|
|
|
for(i = 0; asScrInstinctTab[i].pFunc != NULL; i++)
|
|
|
|
{
|
|
|
|
if (asScrInstinctTab[i].pFunc == pFunc)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%s", asScrInstinctTab[i].pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search the callback functions
|
|
|
|
if (asScrCallbackTab)
|
|
|
|
{
|
|
|
|
for(i = 0; asScrCallbackTab[i].type != 0; i++)
|
|
|
|
{
|
|
|
|
if (asScrCallbackTab[i].pFunc == pFunc)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%s", asScrCallbackTab[i].pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Print a variable access function name */
|
|
|
|
void cpPrintVarFunc(SCRIPT_VARFUNC pFunc, UDWORD index)
|
|
|
|
{
|
|
|
|
SDWORD i;
|
|
|
|
|
|
|
|
// Search the external variable functions
|
|
|
|
if (asScrExternalTab)
|
|
|
|
{
|
|
|
|
for(i = 0; asScrExternalTab[i].pIdent != NULL; i++)
|
|
|
|
{
|
2006-06-02 12:34:58 -07:00
|
|
|
if (asScrExternalTab[i].set == pFunc &&
|
2007-06-28 10:47:08 -07:00
|
|
|
asScrExternalTab[i].index == index)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%s (set)", asScrExternalTab[i].pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
2006-06-02 12:34:58 -07:00
|
|
|
else if (asScrExternalTab[i].get == pFunc &&
|
2007-06-28 10:47:08 -07:00
|
|
|
asScrExternalTab[i].index == index)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%s (get)", asScrExternalTab[i].pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Search the object functions
|
|
|
|
if (asScrObjectVarTab)
|
|
|
|
{
|
|
|
|
for(i = 0; asScrObjectVarTab[i].pIdent != NULL; i++)
|
|
|
|
{
|
2006-06-02 12:34:58 -07:00
|
|
|
if (asScrObjectVarTab[i].set == pFunc &&
|
2007-06-28 10:47:08 -07:00
|
|
|
asScrObjectVarTab[i].index == index)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%s (set)", asScrObjectVarTab[i].pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
2006-06-02 12:34:58 -07:00
|
|
|
else if (asScrObjectVarTab[i].get == pFunc &&
|
2007-06-28 10:47:08 -07:00
|
|
|
asScrObjectVarTab[i].index == index)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%s (get)", asScrObjectVarTab[i].pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Print the array information */
|
2006-11-17 03:25:03 -08:00
|
|
|
static void cpPrintArrayInfo(INTERP_VAL **pip, SCRIPT_CODE *psProg)
|
2007-06-28 10:47:08 -07:00
|
|
|
{
|
|
|
|
SDWORD i, dimensions;//, elements[VAR_MAX_DIMENSIONS];
|
|
|
|
// SDWORD elementDWords;
|
|
|
|
// UBYTE *pElem;
|
2006-11-17 03:25:03 -08:00
|
|
|
INTERP_VAL *ip = *pip;
|
2007-06-28 10:47:08 -07:00
|
|
|
UDWORD base;
|
|
|
|
|
|
|
|
// get the base index of the array
|
2006-11-17 03:25:03 -08:00
|
|
|
base = ip->v.ival & ARRAY_BASE_MASK;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// get the number of dimensions
|
2006-11-17 03:25:03 -08:00
|
|
|
dimensions = (ip->v.ival & ARRAY_DIMENSION_MASK) >> ARRAY_DIMENSION_SHIFT;
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
// get the number of elements for each dimension
|
|
|
|
/* pElem = (UBYTE *) (ip + 1);
|
|
|
|
for(i=0; i<dimensions; i+=1)
|
|
|
|
{
|
|
|
|
elements[i] = *pElem;
|
|
|
|
|
|
|
|
pElem += 1;
|
|
|
|
}*/
|
|
|
|
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%d->", base );
|
2007-06-28 10:47:08 -07:00
|
|
|
for(i=0; i<psProg->psArrayInfo[base].dimensions; i+= 1)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "[%d]", psProg->psArrayInfo[base].elements[i] );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
// calculate the number of DWORDs needed to store the number of elements for each dimension of the array
|
|
|
|
// elementDWords = (dimensions - 1)/4 + 1;
|
|
|
|
|
2006-11-17 03:25:03 -08:00
|
|
|
// update the instruction pointer
|
2007-06-28 10:47:08 -07:00
|
|
|
*pip += 1;// + elementDWords;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Display the contents of a program in readable form */
|
|
|
|
void cpPrintProgram(SCRIPT_CODE *psProg)
|
|
|
|
{
|
2006-11-17 03:25:03 -08:00
|
|
|
INTERP_VAL *ip, *end;
|
2007-06-28 10:47:08 -07:00
|
|
|
OPCODE opcode;
|
|
|
|
UDWORD data, i, dim;
|
|
|
|
SCRIPT_DEBUG *psCurrDebug=NULL;
|
|
|
|
BOOL debugInfo, triggerCode;
|
|
|
|
UDWORD jumpOffset;
|
|
|
|
VAR_DEBUG *psCurrVar;
|
|
|
|
ARRAY_DATA *psCurrArray;
|
|
|
|
ARRAY_DEBUG *psCurrArrayDebug;
|
|
|
|
|
2007-04-03 06:20:41 -07:00
|
|
|
ASSERT( psProg != NULL,
|
2006-08-23 05:58:48 -07:00
|
|
|
"cpPrintProgram: Invalid program pointer" );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
|
|
|
debugInfo = psProg->psDebug != NULL;
|
|
|
|
|
|
|
|
if (debugInfo)
|
|
|
|
{
|
|
|
|
// Print out the global variables
|
|
|
|
if (psProg->numGlobals > 0)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "index storage type variable name\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
psCurrVar = psProg->psVarDebug;
|
|
|
|
for(i=0; i<psProg->numGlobals; i++)
|
|
|
|
{
|
2007-03-15 16:17:09 -07:00
|
|
|
debug( LOG_NEVER, "%-6d %s %-4d %s\n", (int)(psCurrVar - psProg->psVarDebug), psCurrVar->storage == ST_PUBLIC ? "Public " : "Private", psProg->pGlobals[i], psCurrVar->pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
psCurrVar++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (psProg->numArrays > 0)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\narrays\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
psCurrArray = psProg->psArrayInfo;
|
|
|
|
psCurrArrayDebug = psProg->psArrayDebug;
|
|
|
|
for(i=0; i<psProg->numArrays; i++)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%-6d %s %-4d %s", i, psCurrArrayDebug->storage == ST_PUBLIC ? "Public " : "Private", psCurrArray->type, psCurrArrayDebug->pIdent );
|
2007-06-28 10:47:08 -07:00
|
|
|
for(dim=0; dim < psCurrArray->dimensions; dim += 1)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "[%d]", psCurrArray->elements[dim] );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
psCurrArray++;
|
|
|
|
psCurrArrayDebug++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\nindex line offset\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
psCurrDebug = psProg->psDebug;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "index offset\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Find the first trigger with code
|
|
|
|
for(jumpOffset = 0; jumpOffset < psProg->numTriggers; jumpOffset++)
|
|
|
|
{
|
|
|
|
if (psProg->psTriggerData[jumpOffset].type == TR_CODE)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ip = psProg->pCode;
|
|
|
|
triggerCode = psProg->numTriggers > 0 ? TRUE : FALSE;
|
2006-11-17 03:25:03 -08:00
|
|
|
end = (INTERP_VAL *)(((UBYTE *)ip) + psProg->size);
|
|
|
|
opcode = (OPCODE)(ip->v.ival >> OPCODE_SHIFT);
|
|
|
|
data = (ip->v.ival & OPCODE_DATAMASK);
|
2007-06-28 10:47:08 -07:00
|
|
|
while (ip < end)
|
|
|
|
{
|
|
|
|
// display a label if there is one
|
|
|
|
if (debugInfo)
|
|
|
|
{
|
|
|
|
if ((UDWORD)(ip - psProg->pCode) == psCurrDebug->offset &&
|
|
|
|
psCurrDebug->pLabel != NULL)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%s\n", psCurrDebug->pLabel );
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the trigger/event index
|
|
|
|
if (triggerCode)
|
|
|
|
{
|
|
|
|
if (ip - psProg->pCode == psProg->pTriggerTab[jumpOffset])
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%-6d", jumpOffset );
|
2007-06-28 10:47:08 -07:00
|
|
|
jumpOffset+= 1;
|
|
|
|
// Find the next trigger with code
|
|
|
|
while(jumpOffset < psProg->numTriggers)
|
|
|
|
{
|
|
|
|
if (psProg->psTriggerData[jumpOffset].type == TR_CODE)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
jumpOffset++;
|
|
|
|
}
|
|
|
|
if (jumpOffset >= psProg->numTriggers)
|
|
|
|
{
|
|
|
|
// Got to the end of the triggers
|
|
|
|
triggerCode = FALSE;
|
|
|
|
jumpOffset = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (ip - psProg->pCode == psProg->pEventTab[jumpOffset])
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%-6d", jumpOffset );
|
2007-06-28 10:47:08 -07:00
|
|
|
jumpOffset+= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the line number
|
|
|
|
if (debugInfo)
|
|
|
|
{
|
|
|
|
if ((UDWORD)(ip - psProg->pCode) == psCurrDebug->offset)
|
|
|
|
{
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "%-6d", psCurrDebug->line );
|
2007-06-28 10:47:08 -07:00
|
|
|
psCurrDebug++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Display the code offset
|
2007-03-15 16:17:09 -07:00
|
|
|
debug( LOG_NEVER, "%-6d", (int)(ip - psProg->pCode) );
|
2007-06-28 10:47:08 -07:00
|
|
|
switch (opcode)
|
|
|
|
{
|
|
|
|
case OP_PUSH:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "PUSH" );
|
2007-06-28 10:47:08 -07:00
|
|
|
cpPrintPackedVal(ip);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_PUSHREF:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "PUSHREF" );
|
2007-06-28 10:47:08 -07:00
|
|
|
cpPrintPackedVal(ip);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_POP:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "POP\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_PUSHGLOBAL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "PUSHGLOBAL %d\n", data );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_POPGLOBAL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "POPGLOBAL %d\n", data );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_PUSHARRAYGLOBAL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "PUSHARRAYGLOBAL" );
|
2007-06-28 10:47:08 -07:00
|
|
|
cpPrintArrayInfo(&ip, psProg);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_POPARRAYGLOBAL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "POPARRAYGLOBAL" );
|
2007-06-28 10:47:08 -07:00
|
|
|
cpPrintArrayInfo(&ip, psProg);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
case OP_CALL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "CALL" );
|
2006-11-17 03:25:03 -08:00
|
|
|
cpPrintFunc( ((INTERP_VAL *)(ip+1))->v.pFuncExtern );
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_VARCALL:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "VARCALL" );
|
2006-11-17 03:25:03 -08:00
|
|
|
cpPrintVarFunc( ((INTERP_VAL *)(ip+1))->v.pObjGetSet, data);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "(%d)\n", data );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_JUMP:
|
2007-03-15 16:17:09 -07:00
|
|
|
debug( LOG_NEVER, "JUMP %d (%d)\n", (SWORD)data, (int)(ip - psProg->pCode + (SWORD)data) );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_JUMPTRUE:
|
2007-03-15 16:17:09 -07:00
|
|
|
debug( LOG_NEVER, "JUMPTRUE %d (%d)\n", (SWORD)data, (int)(ip - psProg->pCode + (SWORD)data) );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_JUMPFALSE:
|
2007-03-15 16:17:09 -07:00
|
|
|
debug( LOG_NEVER, "JUMPFALSE %d (%d)\n", (SWORD)data, (int)(ip - psProg->pCode + (SWORD)data) );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_BINARYOP:
|
|
|
|
case OP_UNARYOP:
|
|
|
|
cpPrintMathsOp(data);
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_EXIT:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "EXIT\n" );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
case OP_PAUSE:
|
2006-08-22 07:28:49 -07:00
|
|
|
debug( LOG_NEVER, "PAUSE %d\n", data );
|
2007-06-28 10:47:08 -07:00
|
|
|
ip += aOpSize[opcode];
|
|
|
|
break;
|
|
|
|
default:
|
2007-02-19 06:10:44 -08:00
|
|
|
ASSERT( FALSE,"cpPrintProgram: Unknown opcode: %x", ip->type );
|
2007-06-28 10:47:08 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-04-03 06:20:41 -07:00
|
|
|
ASSERT( (ip <= end) || ip != NULL,
|
2006-08-23 05:58:48 -07:00
|
|
|
"cpPrintProgram: instruction pointer no longer valid" );
|
2007-06-28 10:47:08 -07:00
|
|
|
|
2006-11-17 03:25:03 -08:00
|
|
|
opcode = (OPCODE)(ip->v.ival >> OPCODE_SHIFT);
|
|
|
|
data = ip->v.ival & OPCODE_DATAMASK;
|
2007-06-28 10:47:08 -07:00
|
|
|
}
|
|
|
|
}
|