From 644f0c0e05e820a1777dc429a514312542dbb125 Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 17 Jul 2012 03:35:03 +0000 Subject: [PATCH] - Add a name to VMFunction so that the disassembly can be more informative. SVN r3768 (scripting) --- src/namedef.h | 9 ++++++- src/thingdef/thingdef.cpp | 5 ++++ src/thingdef/thingdef_data.cpp | 2 +- src/thingdef/thingdef_expression.cpp | 36 ++++++++++++++-------------- src/zscript/vm.h | 9 +++++-- src/zscript/vmdisasm.cpp | 12 ++++++++++ src/zscript/vmframe.cpp | 3 ++- 7 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/namedef.h b/src/namedef.h index a46863ce3..95a5aca9a 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -549,4 +549,11 @@ xx(Inter_Strife_Bad) xx(Inter_Strife_Lose) xx(Inter_Strife_MAP03) xx(Inter_Strife_MAP10) -xx(Multiplayer) \ No newline at end of file +xx(Multiplayer) + +// Decorate compatibility functions +xx(DecoRandom) +xx(DecoFRandom) +xx(DecoCallLineSpecial) +xx(DecoNameToClass) +xx(DecoFindMultiNameState) diff --git a/src/thingdef/thingdef.cpp b/src/thingdef/thingdef.cpp index b4bf28ccc..3b68851c8 100644 --- a/src/thingdef/thingdef.cpp +++ b/src/thingdef/thingdef.cpp @@ -264,6 +264,7 @@ static void FinishThingdef() { int errorcount = StateParams.ResolveAll(); unsigned i, j; + int codesize = 0; FILE *dump = fopen("disasm.txt", "w"); for (i = 0; i < StateTempCalls.Size(); ++i) @@ -316,6 +317,7 @@ static void FinishThingdef() VMDumpConstants(dump, sfunc); fprintf(dump, "\nDisassembly @ %p:\n", sfunc->Code); VMDisasm(dump, sfunc->Code, sfunc->CodeSize, sfunc); + codesize += sfunc->CodeSize; #endif } for (int k = 0; k < tcall->NumStates; ++k) @@ -323,6 +325,9 @@ static void FinishThingdef() tcall->ActorClass->OwnedStates[tcall->FirstState + k].SetAction(func); } } +#if 1 + fprintf(dump, "\n*************************************************************************\n%i code bytes\n", codesize * 4); +#endif fclose(dump); for (i = 0; i < PClassActor::AllActorClasses.Size(); i++) diff --git a/src/thingdef/thingdef_data.cpp b/src/thingdef/thingdef_data.cpp index 114c8a0b1..f60e69c40 100644 --- a/src/thingdef/thingdef_data.cpp +++ b/src/thingdef/thingdef_data.cpp @@ -613,7 +613,7 @@ void InitThingdef() { AFuncDesc *afunc = (AFuncDesc *)*probe; assert(afunc->VMPointer != NULL); - *(afunc->VMPointer) = new VMNativeFunction(afunc->Function); + *(afunc->VMPointer) = new VMNativeFunction(afunc->Function, afunc->Name); AFTable.Push(*afunc); } AFTable.ShrinkToFit(); diff --git a/src/thingdef/thingdef_expression.cpp b/src/thingdef/thingdef_expression.cpp index 9f17e5678..7699750a2 100644 --- a/src/thingdef/thingdef_expression.cpp +++ b/src/thingdef/thingdef_expression.cpp @@ -2487,11 +2487,11 @@ ExpEmit FxRandom::Emit(VMFunctionBuilder *build) // Find the DecoRandom function. If not found, create it and install it // in Actor. VMFunction *callfunc; - PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoRandom", false); + PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoRandom, false); if (sym == NULL) { - PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoRandom"); - VMNativeFunction *calldec = new VMNativeFunction(DecoRandom); + PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoRandom); + VMNativeFunction *calldec = new VMNativeFunction(DecoRandom, NAME_DecoRandom); symfunc->Function = calldec; sym = symfunc; 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 // in Actor. VMFunction *callfunc; - PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoFRandom", false); + PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoFRandom, false); if (sym == NULL) { - PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoFRandom"); - VMNativeFunction *calldec = new VMNativeFunction(DecoFRandom); + PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoFRandom); + VMNativeFunction *calldec = new VMNativeFunction(DecoFRandom, NAME_DecoFRandom); symfunc->Function = calldec; sym = symfunc; 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 // in Actor. VMFunction *callfunc; - PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoRandom", false); + PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoRandom, false); if (sym == NULL) { - PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoRandom"); - VMNativeFunction *calldec = new VMNativeFunction(DecoRandom); + PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoRandom); + VMNativeFunction *calldec = new VMNativeFunction(DecoRandom, NAME_DecoRandom); symfunc->Function = calldec; sym = symfunc; 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 // in Actor. VMFunction *callfunc; - PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoCallLineSpecial", false); + PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoCallLineSpecial, false); if (sym == NULL) { - PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoCallLineSpecial"); - VMNativeFunction *calldec = new VMNativeFunction(DecoCallLineSpecial); + PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoCallLineSpecial); + VMNativeFunction *calldec = new VMNativeFunction(DecoCallLineSpecial, NAME_DecoCallLineSpecial); symfunc->Function = calldec; sym = symfunc; 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 // in Actor. VMFunction *callfunc; - PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoNameToClass", false); + PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoNameToClass, false); if (sym == NULL) { - PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoNameToClass"); - VMNativeFunction *calldec = new VMNativeFunction(DecoNameToClass); + PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoNameToClass); + VMNativeFunction *calldec = new VMNativeFunction(DecoNameToClass, NAME_DecoNameToClass); symfunc->Function = calldec; sym = symfunc; 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 // in Actor. VMFunction *callfunc; - PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol("DecoFindMultiNameState", false); + PSymbol *sym = RUNTIME_CLASS(AActor)->Symbols.FindSymbol(NAME_DecoNameToClass, false); if (sym == NULL) { - PSymbolVMFunction *symfunc = new PSymbolVMFunction("DecoFindMultiNameState"); - VMNativeFunction *calldec = new VMNativeFunction(DecoFindMultiNameState); + PSymbolVMFunction *symfunc = new PSymbolVMFunction(NAME_DecoNameToClass); + VMNativeFunction *calldec = new VMNativeFunction(DecoFindMultiNameState, NAME_DecoNameToClass); symfunc->Function = calldec; sym = symfunc; RUNTIME_CLASS(AActor)->Symbols.AddSymbol(sym); diff --git a/src/zscript/vm.h b/src/zscript/vm.h index 41284f912..256578a8e 100644 --- a/src/zscript/vm.h +++ b/src/zscript/vm.h @@ -149,6 +149,10 @@ class VMFunction : public DObject DECLARE_ABSTRACT_CLASS(VMFunction, DObject); public: bool Native; + FName Name; + + VMFunction() : Native(false), Name(NAME_None) {} + VMFunction(FName name) : Native(false), Name(name) {} }; enum EVMOpMode @@ -712,7 +716,7 @@ struct VMRegisters struct VMException : public DObject { - DECLARE_CLASS(VMFunction, DObject); + DECLARE_CLASS(VMException, DObject); }; union FVoidObj @@ -725,7 +729,7 @@ class VMScriptFunction : public VMFunction { DECLARE_CLASS(VMScriptFunction, VMFunction); public: - VMScriptFunction(); + VMScriptFunction(FName name=NAME_None); ~VMScriptFunction(); size_t PropagateMark(); void Alloc(int numops, int numkonstd, int numkonstf, int numkonsts, int numkonsta); @@ -788,6 +792,7 @@ public: VMNativeFunction() : NativeCall(NULL) { 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. NativeCallType NativeCall; diff --git a/src/zscript/vmdisasm.cpp b/src/zscript/vmdisasm.cpp index 5e7d4e0cc..e81b4087b 100644 --- a/src/zscript/vmdisasm.cpp +++ b/src/zscript/vmdisasm.cpp @@ -173,6 +173,8 @@ void VMDumpConstants(FILE *out, const VMScriptFunction *func) void VMDisasm(FILE *out, const VMOP *code, int codesize, const VMScriptFunction *func) { + VMFunction *callfunc; + const char *callname; const char *name; int col; 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); 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: 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); } + 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 { printf_wrapper(out, "%d,%d,%d\n", code[i].a, code[i].b, code[i].c); diff --git a/src/zscript/vmframe.cpp b/src/zscript/vmframe.cpp index fdf2d42cc..0c2cacfc2 100644 --- a/src/zscript/vmframe.cpp +++ b/src/zscript/vmframe.cpp @@ -6,9 +6,10 @@ IMPLEMENT_ABSTRACT_CLASS(VMFunction) IMPLEMENT_CLASS(VMScriptFunction) IMPLEMENT_CLASS(VMNativeFunction) -VMScriptFunction::VMScriptFunction() +VMScriptFunction::VMScriptFunction(FName name) { Native = false; + Name = name; Code = NULL; KonstD = NULL; KonstF = NULL;