2009-09-16 01:39:44 +00:00
|
|
|
#include "vm.h"
|
2009-10-15 21:23:59 +00:00
|
|
|
#include "c_console.h"
|
2009-09-16 01:39:44 +00:00
|
|
|
|
|
|
|
#define LI MODE_AI | MODE_BCJOINT | MODE_BCIMMS
|
|
|
|
#define LKI MODE_AI | MODE_BCJOINT | MODE_BCKI
|
|
|
|
#define LKF MODE_AF | MODE_BCJOINT | MODE_BCKF
|
|
|
|
#define LKS MODE_AS | MODE_BCJOINT | MODE_BCKS
|
|
|
|
#define LKP MODE_AP | MODE_BCJOINT | MODE_BCKP
|
|
|
|
#define LFP MODE_AP | MODE_BUNUSED | MODE_CUNUSED
|
|
|
|
|
|
|
|
#define RIRPKI MODE_AI | MODE_BP | MODE_CKI
|
|
|
|
#define RIRPRI MODE_AI | MODE_BP | MODE_CI
|
|
|
|
#define RFRPKI MODE_AF | MODE_BP | MODE_CKI
|
|
|
|
#define RFRPRI MODE_AF | MODE_BP | MODE_CI
|
|
|
|
#define RSRPKI MODE_AS | MODE_BP | MODE_CKI
|
|
|
|
#define RSRPRI MODE_AS | MODE_BP | MODE_CI
|
|
|
|
#define RPRPKI MODE_AP | MODE_BP | MODE_CKI
|
|
|
|
#define RPRPRI MODE_AP | MODE_BP | MODE_CI
|
|
|
|
#define RVRPKI MODE_AV | MODE_BP | MODE_CKI
|
|
|
|
#define RVRPRI MODE_AV | MODE_BP | MODE_CI
|
|
|
|
#define RIRPI8 MODE_AI | MODE_BP | MODE_CIMMZ
|
|
|
|
|
|
|
|
#define RPRIKI MODE_AP | MODE_BI | MODE_CKI
|
|
|
|
#define RPRIRI MODE_AP | MODE_BI | MODE_CI
|
|
|
|
#define RPRFKI MODE_AP | MODE_BF | MODE_CKI
|
|
|
|
#define RPRFRI MODE_AP | MODE_BF | MODE_CI
|
|
|
|
#define RPRSKI MODE_AP | MODE_BS | MODE_CKI
|
|
|
|
#define RPRSRI MODE_AP | MODE_BS | MODE_CI
|
|
|
|
#define RPRPKI MODE_AP | MODE_BP | MODE_CKI
|
|
|
|
#define RPRPRI MODE_AP | MODE_BP | MODE_CI
|
|
|
|
#define RPRVKI MODE_AP | MODE_BV | MODE_CKI
|
|
|
|
#define RPRVRI MODE_AP | MODE_BV | MODE_CI
|
|
|
|
#define RPRII8 MODE_AP | MODE_BI | MODE_CIMMZ
|
|
|
|
|
|
|
|
#define RIRI MODE_AI | MODE_BI | MODE_CUNUSED
|
|
|
|
#define RFRF MODE_AF | MODE_BF | MODE_CUNUSED
|
|
|
|
#define RSRS MODE_AS | MODE_BS | MODE_CUNUSED
|
|
|
|
#define RPRP MODE_AP | MODE_BP | MODE_CUNUSED
|
|
|
|
#define RXRXI8 MODE_AX | MODE_BX | MODE_CIMMZ
|
|
|
|
#define RPRPRP MODE_AP | MODE_BP | MODE_CP
|
|
|
|
#define RPRPKP MODE_AP | MODE_BP | MODE_CKP
|
|
|
|
|
|
|
|
#define RII16 MODE_AI | MODE_BCJOINT | MODE_BCIMMS
|
|
|
|
#define I24 MODE_ABCJOINT
|
|
|
|
#define I8 MODE_AIMMZ | MODE_BUNUSED | MODE_CUNUSED
|
|
|
|
#define __BCP MODE_AUNUSED | MODE_BCJOINT | MODE_BCPARAM
|
|
|
|
#define RPI8I8 MODE_AP | MODE_BIMMZ | MODE_CIMMZ
|
|
|
|
#define KPI8I8 MODE_AKP | MODE_BIMMZ | MODE_CIMMZ
|
|
|
|
#define I8BCP MODE_AIMMZ | MODE_BCJOINT | MODE_BCPARAM
|
|
|
|
#define THROW MODE_AIMMZ | MODE_BCTHROW
|
|
|
|
#define CATCH MODE_AIMMZ | MODE_BCCATCH
|
|
|
|
#define CAST MODE_AX | MODE_BX | MODE_CIMMZ | MODE_BCCAST
|
|
|
|
|
|
|
|
#define RSRSRS MODE_AS | MODE_BS | MODE_CS
|
|
|
|
#define RIRS MODE_AI | MODE_BS | MODE_CUNUSED
|
|
|
|
#define I8RXRX MODE_AIMMZ | MODE_BX | MODE_CX
|
|
|
|
|
|
|
|
#define RIRIRI MODE_AI | MODE_BI | MODE_CI
|
|
|
|
#define RIRII8 MODE_AI | MODE_BI | MODE_CIMMZ
|
|
|
|
#define RIRIKI MODE_AI | MODE_BI | MODE_CKI
|
|
|
|
#define RIKIRI MODE_AI | MODE_BKI | MODE_CI
|
|
|
|
#define RIKII8 MODE_AI | MODE_BKI | MODE_CIMMZ
|
|
|
|
#define RIRIIs MODE_AI | MODE_BI | MODE_CIMMS
|
|
|
|
#define RIRI MODE_AI | MODE_BI | MODE_CUNUSED
|
|
|
|
#define I8RIRI MODE_AIMMZ | MODE_BI | MODE_CI
|
|
|
|
#define I8RIKI MODE_AIMMZ | MODE_BI | MODE_CKI
|
|
|
|
#define I8KIRI MODE_AIMMZ | MODE_BKI | MODE_CI
|
|
|
|
|
|
|
|
#define RFRFRF MODE_AF | MODE_BF | MODE_CF
|
|
|
|
#define RFRFKF MODE_AF | MODE_BF | MODE_CKF
|
|
|
|
#define RFKFRF MODE_AF | MODE_BKF | MODE_CF
|
|
|
|
#define I8RFRF MODE_AIMMZ | MODE_BF | MODE_CF
|
|
|
|
#define I8RFKF MODE_AIMMZ | MODE_BF | MODE_CKF
|
|
|
|
#define I8KFRF MODE_AIMMZ | MODE_BKF | MODE_CF
|
|
|
|
#define RFRFI8 MODE_AF | MODE_BF | MODE_CIMMZ
|
|
|
|
|
|
|
|
#define RVRV MODE_AV | MODE_BV | MODE_CUNUSED
|
|
|
|
#define RVRVRV MODE_AV | MODE_BV | MODE_CV
|
|
|
|
#define RVRVKV MODE_AV | MODE_BV | MODE_CKV
|
|
|
|
#define RVKVRV MODE_AV | MODE_BKV | MODE_CV
|
|
|
|
#define RFRV MODE_AF | MODE_BV | MODE_CUNUSED
|
|
|
|
#define I8RVRV MODE_AIMMZ | MODE_BV | MODE_CV
|
|
|
|
#define I8RVKV MODE_AIMMZ | MODE_BV | MODE_CKV
|
|
|
|
|
|
|
|
#define RPRPRI MODE_AP | MODE_BP | MODE_CI
|
|
|
|
#define RPRPKI MODE_AP | MODE_BP | MODE_CKI
|
|
|
|
#define RIRPRP MODE_AI | MODE_BP | MODE_CP
|
|
|
|
#define I8RPRP MODE_AIMMZ | MODE_BP | MODE_CP
|
|
|
|
#define I8RPKP MODE_AIMMZ | MODE_BP | MODE_CKP
|
|
|
|
|
|
|
|
const VMOpInfo OpInfo[NUM_OPS] =
|
|
|
|
{
|
|
|
|
#define xx(op, name, mode) { #name, mode }
|
|
|
|
#include "vmops.h"
|
|
|
|
};
|
|
|
|
|
2009-10-15 21:23:59 +00:00
|
|
|
static int print_reg(FILE *out, int col, int arg, int mode, int immshift, const VMScriptFunction *func);
|
2009-09-16 01:39:44 +00:00
|
|
|
|
2009-10-15 21:23:59 +00:00
|
|
|
static int printf_wrapper(FILE *f, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list argptr;
|
|
|
|
int count;
|
|
|
|
|
|
|
|
va_start(argptr, fmt);
|
|
|
|
if (f == NULL)
|
|
|
|
{
|
|
|
|
count = VPrintf(PRINT_HIGH, fmt, argptr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
count = vfprintf(f, fmt, argptr);
|
|
|
|
}
|
|
|
|
va_end(argptr);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
void VMDumpConstants(FILE *out, const VMScriptFunction *func)
|
2009-10-15 03:58:23 +00:00
|
|
|
{
|
|
|
|
char tmp[21];
|
|
|
|
int i, j, k, kk;
|
|
|
|
|
|
|
|
if (func->KonstD != NULL && func->NumKonstD != 0)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "\nConstant integers:\n");
|
2009-10-15 03:58:23 +00:00
|
|
|
kk = (func->NumKonstD + 3) / 4;
|
|
|
|
for (i = 0; i < kk; ++i)
|
|
|
|
{
|
|
|
|
for (j = 0, k = i; j < 4 && k < func->NumKonstD; j++, k += kk)
|
|
|
|
{
|
|
|
|
mysnprintf(tmp, countof(tmp), "%3d. %d", k, func->KonstD[k]);
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "%-20s", tmp);
|
2009-10-15 03:58:23 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "\n");
|
2009-10-15 03:58:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (func->KonstF != NULL && func->NumKonstF != 0)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "\nConstant floats:\n");
|
2009-10-15 03:58:23 +00:00
|
|
|
kk = (func->NumKonstF + 3) / 4;
|
|
|
|
for (i = 0; i < kk; ++i)
|
|
|
|
{
|
|
|
|
for (j = 0, k = i; j < 4 && k < func->NumKonstF; j++, k += kk)
|
|
|
|
{
|
|
|
|
mysnprintf(tmp, countof(tmp), "%3d. %.16f", k, func->KonstF[k]);
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "%-20s", tmp);
|
2009-10-15 03:58:23 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "\n");
|
2009-10-15 03:58:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (func->KonstA != NULL && func->NumKonstA != 0)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "\nConstant addresses:\n");
|
2009-10-15 03:58:23 +00:00
|
|
|
kk = (func->NumKonstA + 3) / 4;
|
|
|
|
for (i = 0; i < kk; ++i)
|
|
|
|
{
|
|
|
|
for (j = 0, k = i; j < 4 && k < func->NumKonstA; j++, k += kk)
|
|
|
|
{
|
2010-02-14 19:59:21 +00:00
|
|
|
mysnprintf(tmp, countof(tmp), "%3d. %p:%d", k, func->KonstA[k], func->KonstATags()[k]);
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "%-20s", tmp);
|
2009-10-15 03:58:23 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "\n");
|
2009-10-15 03:58:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (func->KonstS != NULL && func->NumKonstS != 0)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "\nConstant strings:\n");
|
2009-10-15 03:58:23 +00:00
|
|
|
for (i = 0; i < func->NumKonstS; ++i)
|
|
|
|
{
|
2009-10-17 01:38:54 +00:00
|
|
|
printf_wrapper(out, "%3d. %s\n", i, func->KonstS[i].GetChars());
|
2009-10-15 03:58:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-17 00:33:23 +00:00
|
|
|
void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction *func)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
2012-07-17 03:35:03 +00:00
|
|
|
VMFunction *callfunc;
|
|
|
|
const char *callname;
|
2009-09-16 01:39:44 +00:00
|
|
|
const char *name;
|
|
|
|
int col;
|
|
|
|
int mode;
|
|
|
|
int a;
|
|
|
|
|
2009-10-17 00:33:23 +00:00
|
|
|
for (int i = 0; i < codesize; ++i)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
name = OpInfo[code[i].op].Name;
|
|
|
|
mode = OpInfo[code[i].op].Mode;
|
|
|
|
a = code[i].a;
|
2009-09-16 01:39:44 +00:00
|
|
|
|
|
|
|
// String comparison encodes everything in a single instruction.
|
2009-10-17 00:33:23 +00:00
|
|
|
if (code[i].op == OP_CMPS)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
|
|
|
switch (a & CMP_METHOD_MASK)
|
|
|
|
{
|
|
|
|
case CMP_EQ: name = "eq"; break;
|
|
|
|
case CMP_LT: name = "lt"; break;
|
|
|
|
case CMP_LE: name = "le"; break;
|
|
|
|
}
|
|
|
|
mode = MODE_AIMMZ;
|
|
|
|
mode |= (a & CMP_BK) ? MODE_BKS : MODE_BS;
|
|
|
|
mode |= (a & CMP_CK) ? MODE_CKS : MODE_CS;
|
|
|
|
a &= CMP_CHECK | CMP_APPROX;
|
|
|
|
}
|
|
|
|
|
2009-10-17 00:33:23 +00:00
|
|
|
printf_wrapper(out, "%08x: %02x%02x%02x%02x %-8s", i << 2, code[i].op, code[i].a, code[i].b, code[i].c, name);
|
2009-09-16 01:39:44 +00:00
|
|
|
col = 0;
|
2009-10-17 00:33:23 +00:00
|
|
|
switch (code[i].op)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
|
|
|
case OP_JMP:
|
|
|
|
case OP_TRY:
|
2009-10-17 00:33:23 +00:00
|
|
|
col = printf_wrapper(out, "%08x", i + 4 + (code[i].i24 << 2));
|
2009-09-16 01:39:44 +00:00
|
|
|
break;
|
|
|
|
|
2009-10-15 21:59:37 +00:00
|
|
|
case OP_PARAMI:
|
2009-10-17 00:33:23 +00:00
|
|
|
col = printf_wrapper(out, "%d", code[i].i24);
|
2009-10-15 21:59:37 +00:00
|
|
|
break;
|
|
|
|
|
2012-07-17 03:35:03 +00:00
|
|
|
case OP_CALL_K:
|
|
|
|
callfunc = (VMFunction *)func->KonstA[code[i].a].o;
|
|
|
|
callname = callfunc->Name != NAME_None ? callfunc->Name : "[anonfunc]";
|
|
|
|
col = printf_wrapper(out, "%.23s,%d,%d", callname, code[i].b, code[i].c);
|
|
|
|
break;
|
|
|
|
|
2009-09-16 01:39:44 +00:00
|
|
|
case OP_RET:
|
2009-10-17 00:33:23 +00:00
|
|
|
if (code[i].b != REGT_NIL)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
if ((code[i].b & REGT_FINAL) && a == 0)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
col = print_reg(out, 0, code[i].i16u, MODE_PARAM, 16, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
col = print_reg(out, 0, a, (mode & MODE_ATYPE) >> MODE_ASHIFT, 24, func);
|
2009-10-17 00:33:23 +00:00
|
|
|
col += print_reg(out, col, code[i].i16u, MODE_PARAM, 16, func);
|
|
|
|
if (code[i].b & REGT_FINAL)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
col += printf_wrapper(out, " [final]");
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if ((mode & MODE_BCTYPE) == MODE_BCCAST)
|
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
switch (code[i].c)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
|
|
|
case CAST_I2F:
|
|
|
|
mode = MODE_AF | MODE_BI | MODE_CUNUSED;
|
|
|
|
break;
|
|
|
|
case CAST_I2S:
|
|
|
|
mode = MODE_AS | MODE_BI | MODE_CUNUSED;
|
|
|
|
break;
|
|
|
|
case CAST_F2I:
|
|
|
|
mode = MODE_AI | MODE_BF | MODE_CUNUSED;
|
|
|
|
break;
|
|
|
|
case CAST_F2S:
|
|
|
|
mode = MODE_AS | MODE_BF | MODE_CUNUSED;
|
|
|
|
break;
|
|
|
|
case CAST_P2S:
|
|
|
|
mode = MODE_AS | MODE_BP | MODE_CUNUSED;
|
|
|
|
break;
|
|
|
|
case CAST_S2I:
|
|
|
|
mode = MODE_AI | MODE_BS | MODE_CUNUSED;
|
|
|
|
break;
|
|
|
|
case CAST_S2F:
|
|
|
|
mode = MODE_AF | MODE_BS | MODE_CUNUSED;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mode = MODE_AX | MODE_BX | MODE_CIMMZ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
col = print_reg(out, 0, a, (mode & MODE_ATYPE) >> MODE_ASHIFT, 24, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
if ((mode & MODE_BCTYPE) == MODE_BCTHROW)
|
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
mode = (code[i].a == 0) ? (MODE_BP | MODE_CUNUSED) : (MODE_BKP | MODE_CUNUSED);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
else if ((mode & MODE_BCTYPE) == MODE_BCCATCH)
|
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
switch (code[i].a)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
mode = MODE_BUNUSED | MODE_CUNUSED;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
mode = MODE_BUNUSED | MODE_CP;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
mode = MODE_BP | MODE_CP;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
mode = MODE_BKP | MODE_CP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mode = MODE_BIMMZ | MODE_CIMMZ;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((mode & (MODE_BTYPE | MODE_CTYPE)) == MODE_BCJOINT)
|
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
col += print_reg(out, col, code[i].i16u, (mode & MODE_BCTYPE) >> MODE_BCSHIFT, 16, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
col += print_reg(out, col, code[i].b, (mode & MODE_BTYPE) >> MODE_BSHIFT, 24, func);
|
|
|
|
col += print_reg(out, col, code[i].c, (mode & MODE_CTYPE) >> MODE_CSHIFT, 24, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (col > 30)
|
|
|
|
{
|
|
|
|
col = 30;
|
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
printf_wrapper(out, "%*c", 30 - col, ';');
|
2009-10-17 00:33:23 +00:00
|
|
|
if (code[i].op == OP_JMP || code[i].op == OP_TRY || code[i].op == OP_PARAMI)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
printf_wrapper(out, "%d\n", code[i].i24);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
2012-07-17 03:35:03 +00:00
|
|
|
else if (code[i].op == OP_CALL_K)
|
|
|
|
{
|
|
|
|
printf_wrapper(out, "%d,%d,%d [%p]\n", code[i].a, code[i].b, code[i].c, callfunc);
|
|
|
|
}
|
2009-09-16 01:39:44 +00:00
|
|
|
else
|
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
printf_wrapper(out, "%d,%d,%d\n", code[i].a, code[i].b, code[i].c);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-10-15 21:23:59 +00:00
|
|
|
static int print_reg(FILE *out, int col, int arg, int mode, int immshift, const VMScriptFunction *func)
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
|
|
|
if (mode == MODE_UNUSED)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (col > 0)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
col = printf_wrapper(out, ",");
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
switch(mode)
|
|
|
|
{
|
|
|
|
case MODE_I:
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "d%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
case MODE_F:
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "f%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
case MODE_S:
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "s%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
case MODE_P:
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "a%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
case MODE_V:
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "v%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
|
|
|
|
case MODE_KI:
|
|
|
|
if (func != NULL)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "%d", func->KonstD[arg]);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
return printf_wrapper(out, "kd%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
case MODE_KF:
|
|
|
|
if (func != NULL)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "%f", func->KonstF[arg]);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "kf%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
case MODE_KS:
|
|
|
|
if (func != NULL)
|
|
|
|
{
|
2009-10-17 01:38:54 +00:00
|
|
|
return col+printf_wrapper(out, "\"%.27s\"", func->KonstS[arg].GetChars());
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "ks%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
case MODE_KP:
|
|
|
|
if (func != NULL)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "%p", func->KonstA[arg]);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "ka%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
case MODE_KV:
|
|
|
|
if (func != NULL)
|
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "(%f,%f,%f)", func->KonstF[arg], func->KonstF[arg+1], func->KonstF[arg+2]);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "kv%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
|
|
|
|
case MODE_IMMS:
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "%d", (arg << immshift) >> immshift);
|
2009-09-16 01:39:44 +00:00
|
|
|
|
|
|
|
case MODE_IMMZ:
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
|
|
|
|
case MODE_PARAM:
|
|
|
|
{
|
2009-10-17 00:33:23 +00:00
|
|
|
int regtype, regnum;
|
|
|
|
#ifdef __BIG_ENDIAN__
|
|
|
|
regtype = (arg >> 8) & 255;
|
|
|
|
regnum = arg & 255;
|
|
|
|
#else
|
|
|
|
regtype = arg & 255;
|
|
|
|
regnum = (arg >> 8) & 255;
|
|
|
|
#endif
|
|
|
|
switch (regtype & (REGT_TYPE | REGT_KONST | REGT_MULTIREG))
|
2009-09-16 01:39:44 +00:00
|
|
|
{
|
|
|
|
case REGT_INT:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+printf_wrapper(out, "d%d", regnum);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_FLOAT:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+printf_wrapper(out, "f%d", regnum);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_STRING:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+printf_wrapper(out, "s%d", regnum);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_POINTER:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+printf_wrapper(out, "a%d", regnum);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_FLOAT | REGT_MULTIREG:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+printf_wrapper(out, "v%d", regnum);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_INT | REGT_KONST:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+print_reg(out, 0, regnum, MODE_KI, 0, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_FLOAT | REGT_KONST:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+print_reg(out, 0, regnum, MODE_KF, 0, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_STRING | REGT_KONST:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+print_reg(out, 0, regnum, MODE_KS, 0, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_POINTER | REGT_KONST:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+print_reg(out, 0, regnum, MODE_KP, 0, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
case REGT_FLOAT | REGT_MULTIREG | REGT_KONST:
|
2009-10-17 00:33:23 +00:00
|
|
|
return col+print_reg(out, 0, regnum, MODE_KV, 0, func);
|
2009-09-16 01:39:44 +00:00
|
|
|
default:
|
2009-10-17 00:33:23 +00:00
|
|
|
if (regtype == REGT_NIL)
|
2009-10-15 03:58:23 +00:00
|
|
|
{
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "nil");
|
2009-10-15 03:58:23 +00:00
|
|
|
}
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "param[t=%d,%c,%c,n=%d]",
|
2009-10-17 00:33:23 +00:00
|
|
|
regtype & REGT_TYPE,
|
|
|
|
regtype & REGT_KONST ? 'k' : 'r',
|
|
|
|
regtype & REGT_MULTIREG ? 'm' : 's',
|
|
|
|
regnum);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2009-10-15 21:23:59 +00:00
|
|
|
return col+printf_wrapper(out, "$%d", arg);
|
2009-09-16 01:39:44 +00:00
|
|
|
}
|
|
|
|
return col;
|
|
|
|
}
|