- Add a name to VMFunction so that the disassembly can be more informative.

SVN r3768 (scripting)
This commit is contained in:
Randy Heit 2012-07-17 03:35:03 +00:00
parent d85604da19
commit 644f0c0e05
7 changed files with 53 additions and 23 deletions

View file

@ -549,4 +549,11 @@ xx(Inter_Strife_Bad)
xx(Inter_Strife_Lose) xx(Inter_Strife_Lose)
xx(Inter_Strife_MAP03) xx(Inter_Strife_MAP03)
xx(Inter_Strife_MAP10) xx(Inter_Strife_MAP10)
xx(Multiplayer) xx(Multiplayer)
// Decorate compatibility functions
xx(DecoRandom)
xx(DecoFRandom)
xx(DecoCallLineSpecial)
xx(DecoNameToClass)
xx(DecoFindMultiNameState)

View file

@ -264,6 +264,7 @@ static void FinishThingdef()
{ {
int errorcount = StateParams.ResolveAll(); int errorcount = StateParams.ResolveAll();
unsigned i, j; unsigned i, j;
int codesize = 0;
FILE *dump = fopen("disasm.txt", "w"); FILE *dump = fopen("disasm.txt", "w");
for (i = 0; i < StateTempCalls.Size(); ++i) for (i = 0; i < StateTempCalls.Size(); ++i)
@ -316,6 +317,7 @@ static void FinishThingdef()
VMDumpConstants(dump, sfunc); VMDumpConstants(dump, sfunc);
fprintf(dump, "\nDisassembly @ %p:\n", sfunc->Code); fprintf(dump, "\nDisassembly @ %p:\n", sfunc->Code);
VMDisasm(dump, sfunc->Code, sfunc->CodeSize, sfunc); VMDisasm(dump, sfunc->Code, sfunc->CodeSize, sfunc);
codesize += sfunc->CodeSize;
#endif #endif
} }
for (int k = 0; k < tcall->NumStates; ++k) for (int k = 0; k < tcall->NumStates; ++k)
@ -323,6 +325,9 @@ static void FinishThingdef()
tcall->ActorClass->OwnedStates[tcall->FirstState + k].SetAction(func); tcall->ActorClass->OwnedStates[tcall->FirstState + k].SetAction(func);
} }
} }
#if 1
fprintf(dump, "\n*************************************************************************\n%i code bytes\n", codesize * 4);
#endif
fclose(dump); fclose(dump);
for (i = 0; i < PClassActor::AllActorClasses.Size(); i++) for (i = 0; i < PClassActor::AllActorClasses.Size(); i++)

View file

@ -613,7 +613,7 @@ void InitThingdef()
{ {
AFuncDesc *afunc = (AFuncDesc *)*probe; AFuncDesc *afunc = (AFuncDesc *)*probe;
assert(afunc->VMPointer != NULL); assert(afunc->VMPointer != NULL);
*(afunc->VMPointer) = new VMNativeFunction(afunc->Function); *(afunc->VMPointer) = new VMNativeFunction(afunc->Function, afunc->Name);
AFTable.Push(*afunc); AFTable.Push(*afunc);
} }
AFTable.ShrinkToFit(); AFTable.ShrinkToFit();

View file

@ -2487,11 +2487,11 @@ ExpEmit FxRandom::Emit(VMFunctionBuilder *build)
// Find the DecoRandom function. If not found, create it and install it // Find the DecoRandom function. If not found, create it and install it
// in Actor. // in Actor.
VMFunction *callfunc; VMFunction *callfunc;
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoRandom", false); PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoRandom, false);
if (sym == NULL) if (sym == NULL)
{ {
PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoRandom"); PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoRandom);
VMNativeFunction *calldec = new VMNativeFunction(DecoRandom); VMNativeFunction *calldec = new VMNativeFunction(DecoRandom, NAME_DecoRandom);
symfunc->Function = calldec; symfunc->Function = calldec;
sym = symfunc; sym = symfunc;
RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym); RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym);
@ -2593,11 +2593,11 @@ ExpEmit FxFRandom::Emit(VMFunctionBuilder *build)
// Find the DecoFRandom function. If not found, create it and install it // Find the DecoFRandom function. If not found, create it and install it
// in Actor. // in Actor.
VMFunction *callfunc; VMFunction *callfunc;
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoFRandom", false); PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoFRandom, false);
if (sym == NULL) if (sym == NULL)
{ {
PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoFRandom"); PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoFRandom);
VMNativeFunction *calldec = new VMNativeFunction(DecoFRandom); VMNativeFunction *calldec = new VMNativeFunction(DecoFRandom, NAME_DecoFRandom);
symfunc->Function = calldec; symfunc->Function = calldec;
sym = symfunc; sym = symfunc;
RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym); RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym);
@ -2683,11 +2683,11 @@ ExpEmit FxRandom2::Emit(VMFunctionBuilder *build)
// Find the DecoRandom function. If not found, create it and install it // Find the DecoRandom function. If not found, create it and install it
// in Actor. // in Actor.
VMFunction *callfunc; VMFunction *callfunc;
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoRandom", false); PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoRandom, false);
if (sym == NULL) if (sym == NULL)
{ {
PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoRandom"); PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoRandom);
VMNativeFunction *calldec = new VMNativeFunction(DecoRandom); VMNativeFunction *calldec = new VMNativeFunction(DecoRandom, NAME_DecoRandom);
symfunc->Function = calldec; symfunc->Function = calldec;
sym = symfunc; sym = symfunc;
RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym); RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym);
@ -3530,11 +3530,11 @@ ExpEmit FxActionSpecialCall::Emit(VMFunctionBuilder *build)
// Find the DecoCallLineSpecial function. If not found, create it and install it // Find the DecoCallLineSpecial function. If not found, create it and install it
// in Actor. // in Actor.
VMFunction *callfunc; VMFunction *callfunc;
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoCallLineSpecial", false); PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoCallLineSpecial, false);
if (sym == NULL) if (sym == NULL)
{ {
PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoCallLineSpecial"); PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoCallLineSpecial);
VMNativeFunction *calldec = new VMNativeFunction(DecoCallLineSpecial); VMNativeFunction *calldec = new VMNativeFunction(DecoCallLineSpecial, NAME_DecoCallLineSpecial);
symfunc->Function = calldec; symfunc->Function = calldec;
sym = symfunc; sym = symfunc;
RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym); RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym);
@ -3795,11 +3795,11 @@ ExpEmit FxClassTypeCast::Emit(VMFunctionBuilder *build)
// Find the DecoNameToClass function. If not found, create it and install it // Find the DecoNameToClass function. If not found, create it and install it
// in Actor. // in Actor.
VMFunction *callfunc; VMFunction *callfunc;
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoNameToClass", false); PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoNameToClass, false);
if (sym == NULL) if (sym == NULL)
{ {
PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoNameToClass"); PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoNameToClass);
VMNativeFunction *calldec = new VMNativeFunction(DecoNameToClass); VMNativeFunction *calldec = new VMNativeFunction(DecoNameToClass, NAME_DecoNameToClass);
symfunc->Function = calldec; symfunc->Function = calldec;
sym = symfunc; sym = symfunc;
RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym); RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym);
@ -3995,11 +3995,11 @@ ExpEmit FxMultiNameState::Emit(VMFunctionBuilder *build)
// Find the DecoFindMultiNameState function. If not found, create it and install it // Find the DecoFindMultiNameState function. If not found, create it and install it
// in Actor. // in Actor.
VMFunction *callfunc; VMFunction *callfunc;
PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoFindMultiNameState", false); PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoNameToClass, false);
if (sym == NULL) if (sym == NULL)
{ {
PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoFindMultiNameState"); PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoNameToClass);
VMNativeFunction *calldec = new VMNativeFunction(DecoFindMultiNameState); VMNativeFunction *calldec = new VMNativeFunction(DecoFindMultiNameState, NAME_DecoNameToClass);
symfunc->Function = calldec; symfunc->Function = calldec;
sym = symfunc; sym = symfunc;
RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym); RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym);

View file

@ -149,6 +149,10 @@ class VMFunction : public DObject
DECLARE_ABSTRACT_CLASS(VMFunction, DObject); DECLARE_ABSTRACT_CLASS(VMFunction, DObject);
public: public:
bool Native; bool Native;
FName Name;
VMFunction() : Native(false), Name(NAME_None) {}
VMFunction(FName name) : Native(false), Name(name) {}
}; };
enum EVMOpMode enum EVMOpMode
@ -712,7 +716,7 @@ struct VMRegisters
struct VMException : public DObject struct VMException : public DObject
{ {
DECLARE_CLASS(VMFunction, DObject); DECLARE_CLASS(VMException, DObject);
}; };
union FVoidObj union FVoidObj
@ -725,7 +729,7 @@ class VMScriptFunction : public VMFunction
{ {
DECLARE_CLASS(VMScriptFunction, VMFunction); DECLARE_CLASS(VMScriptFunction, VMFunction);
public: public:
VMScriptFunction(); VMScriptFunction(FName name=NAME_None);
~VMScriptFunction(); ~VMScriptFunction();
size_t PropagateMark(); size_t PropagateMark();
void Alloc(int numops, int numkonstd, int numkonstf, int numkonsts, int numkonsta); void Alloc(int numops, int numkonstd, int numkonstf, int numkonsts, int numkonsta);
@ -788,6 +792,7 @@ public:
VMNativeFunction() : NativeCall(NULL) { Native = true; } VMNativeFunction() : NativeCall(NULL) { Native = true; }
VMNativeFunction(NativeCallType call) : NativeCall(call) { Native = true; } VMNativeFunction(NativeCallType call) : NativeCall(call) { Native = true; }
VMNativeFunction(NativeCallType call, FName name) : VMFunction(name), NativeCall(call) { Native = true; }
// Return value is the number of results. // Return value is the number of results.
NativeCallType NativeCall; NativeCallType NativeCall;

View file

@ -173,6 +173,8 @@ void VMDumpConstants(FILE *out, const VMScriptFunction *func)
void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction *func) void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction *func)
{ {
VMFunction *callfunc;
const char *callname;
const char *name; const char *name;
int col; int col;
int mode; int mode;
@ -212,6 +214,12 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction
col = printf_wrapper(out, "%d", code[i].i24); col = printf_wrapper(out, "%d", code[i].i24);
break; break;
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;
case OP_RET: case OP_RET:
if (code[i].b != REGT_NIL) if (code[i].b != REGT_NIL)
{ {
@ -308,6 +316,10 @@ void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction
{ {
printf_wrapper(out, "%d\n", code[i].i24); printf_wrapper(out, "%d\n", code[i].i24);
} }
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);
}
else else
{ {
printf_wrapper(out, "%d,%d,%d\n", code[i].a, code[i].b, code[i].c); printf_wrapper(out, "%d,%d,%d\n", code[i].a, code[i].b, code[i].c);

View file

@ -6,9 +6,10 @@ IMPLEMENT_ABSTRACT_CLASS(VMFunction)
IMPLEMENT_CLASS(VMScriptFunction) IMPLEMENT_CLASS(VMScriptFunction)
IMPLEMENT_CLASS(VMNativeFunction) IMPLEMENT_CLASS(VMNativeFunction)
VMScriptFunction::VMScriptFunction() VMScriptFunction::VMScriptFunction(FName name)
{ {
Native = false; Native = false;
Name = name;
Code = NULL; Code = NULL;
KonstD = NULL; KonstD = NULL;
KonstF = NULL; KonstF = NULL;