]> git.cworth.org Git - apitrace/commitdiff
Dump arguments.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Mon, 7 Jul 2008 07:55:52 +0000 (16:55 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Mon, 7 Jul 2008 07:55:52 +0000 (16:55 +0900)
base.py
d3d8.py
log.hpp
windows.py

diff --git a/base.py b/base.py
index 889e279f3f081a4bb904d1cd51b3c42d9640a926..22ffae5f9d571105a5c173fae02ab08784046935 100644 (file)
--- 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 4c4c278d00570889a0e7e7fb85d38b3f2dd1c1fc..42cd10b31c37953e29335b78cf13203f6093659f 100755 (executable)
--- 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 df2cdc4395cd6a15ab1a2710c4861f6a8eb6f4e1..a4b5d2594f3835c31529dffcbf10852ba2d89014 100644 (file)
--- 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_ */
index 8e8adee903dc651178ca7f6d8d89f653760952e9..f0bb7929f5de4ca703cee6f6758fe5eeaa1ece1f 100644 (file)
@@ -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);'