From: José Fonseca Date: Mon, 7 Jul 2008 07:55:52 +0000 (+0900) Subject: Dump arguments. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=a83fb24f670cecc1340abcdfd0369ab84e7b2c99;p=apitrace Dump arguments. --- diff --git a/base.py b/base.py index 889e279..22ffae5 100644 --- a/base.py +++ b/base.py @@ -11,6 +11,9 @@ class Type: def isoutput(self): return False + def dump(self, instance): + raise NotImplementedError + def wrap_instance(self, instance): pass @@ -32,6 +35,9 @@ class Intrinsic(Type): Type.__init__(self, name) self.format = format + def dump(self, instance): + print ' g_pLog->TextF("%s", %s);' % (self.format, instance) + class Const(Type): @@ -39,6 +45,9 @@ class Const(Type): Type.__init__(self, 'C' + type.name) self.type = type + def dump(self, instance): + self.type.dump(instance) + def __str__(self): return "const " + str(self.type) @@ -51,6 +60,12 @@ class Pointer(Type): def __str__(self): return str(self.type) + " *" + + def dump(self, instance): + try: + print ' g_pLog->TextF("%%p", %s);' % instance + except NotImplementedError: + self.type.dump("*" + instance) def wrap_instance(self, instance): self.type.wrap_instance("*" + instance) @@ -59,33 +74,28 @@ class Pointer(Type): self.type.wrap_instance("*" + instance) -class Output(Type): - - def __init__(self, type): - Type.__init__(self, type.name) - self.type = type - - def __str__(self): - return str(self.type) +class OutPointer(Pointer): def isoutput(self): return True - def wrap_instance(self, instance): - self.type.wrap_instance(instance) - - def unwrap_instance(self, instance): - self.type.wrap_instance(instance) - -def OutPointer(type): - return Output(Pointer(type)) - class Enum(Type): def __init__(self, name, values): Type.__init__(self, name) self.values = values + + def dump(self, instance): + print ' switch(%s) {' % instance + for value in self.values: + print ' case %s:' % value + print ' g_pLog->Text("%s");' % value + print ' break;' + print ' default:' + print ' g_pLog->TextF("%%i", %s);' % instance + print ' break;' + print ' }' class Flags(Type): @@ -101,6 +111,17 @@ class Struct(Type): Type.__init__(self, name) self.members = members + def dump(self, instance): + print ' g_pLog->Text("{");' + first = True + for type, name in self.members: + if first: + first = False + else: + print ' g_pLog->Text(", ");' + type.dump('(%s).%s' % (instance, name)) + print ' g_pLog->Text("}");' + class Alias(Type): @@ -108,6 +129,9 @@ class Alias(Type): Type.__init__(self, name) self.type = type + def dump(self, instance): + self.type.dump(instance) + class Function: @@ -192,6 +216,9 @@ class Interface(Type): for type, name in method.args: if not type.isoutput(): type.unwrap_instance(name) + print ' g_pLog->BeginParam("%s", "%s");' % (name, type) + type.dump(name) + print ' g_pLog->EndParam();' print ' %sm_pInstance->%s(%s);' % (result, method.name, ', '.join([str(name) for type, name in method.args])) print ' g_pLog->EndCall();' for type, name in method.args: diff --git a/d3d8.py b/d3d8.py index 4c4c278..42cd10b 100755 --- a/d3d8.py +++ b/d3d8.py @@ -50,7 +50,7 @@ IDirect3DDevice8.methods += [ Method(HRESULT, "TestCooperativeLevel", []), Method(UINT, "GetAvailableTextureMem", []), Method(HRESULT, "ResourceManagerDiscardBytes", [(DWORD, "Bytes")]), - Method(HRESULT, "GetDirect3D", [(Pointer(PDIRECT3D8), "ppD3D8")]), + Method(HRESULT, "GetDirect3D", [(OutPointer(PDIRECT3D8), "ppD3D8")]), Method(HRESULT, "GetDeviceCaps", [(Pointer(D3DCAPS8), "pCaps")]), Method(HRESULT, "GetDisplayMode", [(Pointer(D3DDISPLAYMODE), "pMode")]), Method(HRESULT, "GetCreationParameters", [(Pointer(D3DDEVICE_CREATION_PARAMETERS), "pParameters")]), diff --git a/log.hpp b/log.hpp index df2cdc4..a4b5d25 100644 --- a/log.hpp +++ b/log.hpp @@ -183,9 +183,9 @@ public: NewLine(); } - void BeginParam(const char *type, const char *name) { + void BeginParam(const char *name, const char *type) { Write("\t\t"); - BeginTag("param", "type", type, "name", name); + BeginTag("param", "name", name, "type", type); } void EndParam(void) { @@ -211,4 +211,7 @@ protected: }; +extern Log * g_pLog; + + #endif /* _LOG_HPP_ */ diff --git a/windows.py b/windows.py index 8e8adee..f0bb792 100644 --- a/windows.py +++ b/windows.py @@ -72,7 +72,7 @@ class Dll: def wrap_decl(self): print 'static HINSTANCE g_hDll = NULL;' - print 'static Log * g_pLog = NULL;' + print 'Log * g_pLog = NULL;' print 'static TCHAR g_szDll[MAX_PATH] = {0};' print print 'BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved);' @@ -134,11 +134,11 @@ class Dll: else: print ' %s result;' % function.type result = 'result = ' - print ' if(!g_hDll) {' - print ' g_hDll = LoadLibrary(g_szDll);' - print ' if(!g_hDll)' - print ' ExitProcess(0);' - print ' }' + print ' if(!g_hDll) {' + print ' g_hDll = LoadLibrary(g_szDll);' + print ' if(!g_hDll)' + print ' ExitProcess(0);' + print ' }' print ' pFunction = (%s)GetProcAddress( g_hDll, "%s");' % (type, function.name) print ' if(!pFunction)' print ' ExitProcess(0);'