]> git.cworth.org Git - apitrace/commitdiff
Use separate functions for dumping.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 9 Jul 2008 03:18:08 +0000 (12:18 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 9 Jul 2008 03:18:08 +0000 (12:18 +0900)
base.py
d3d8caps.py
d3d8types.py
d3d9caps.py
d3d9types.py
log.cpp
log.hpp
windows.py

diff --git a/base.py b/base.py
index 8f91a6dcdcecf55a0d701c2317b392b3c0cfe3b8..d2b4a22dd80d988fd2bec711f04592538239a9f5 100644 (file)
--- a/base.py
+++ b/base.py
 
 """C basic types"""
 
+
+import debug
+
+
+all_types = {}
+
 class Type:
 
     def __init__(self, name):
@@ -30,32 +36,72 @@ class Type:
     def isoutput(self):
         return False
 
+    def decl(self):
+        pass
+
+    def impl(self):
+        pass
+
     def dump(self, instance):
         raise NotImplementedError
     
     def wrap_instance(self, instance):
-        pass
+        pass 
 
     def unwrap_instance(self, instance):
         pass
 
 
-class Void(Type):
+class _Void(Type):
 
     def __init__(self):
         Type.__init__(self, "void")
 
-Void = Void()
+Void = _Void()
 
 
-class Intrinsic(Type):
+class Concrete(Type):
+
+    def __init__(self, name):
+        for char in name:
+            assert char.isalnum() or char == '_'
 
-    def __init__(self, name, format):
         Type.__init__(self, name)
-        self.format = format
+        
+        assert self.name not in all_types
+        if self.name not in all_types:
+            all_types[self.name] = self
 
+    def decl(self):
+        print 'void Dump%s(const %s &value);' % (self.name, str(self))
+    
+    def impl(self):
+        print 'void Dump%s(const %s &value) {' % (self.name, str(self))
+        self._dump("value");
+        print '}'
+        print
+    
+    def _dump(self, instance):
+        raise NotImplementedError
+    
     def dump(self, instance):
+        print '    Dump%s(%s);' % (self.name, instance)
+    
+
+class Intrinsic(Concrete):
+
+    def __init__(self, expr, format, name = None):
+        if name is None:
+            name = expr
+        Concrete.__init__(self, name)
+        self.expr = expr
+        self.format = format
+
+    def _dump(self, instance):
         print '    Log::TextF("%s", %s);' % (self.format, instance)
+        
+    def __str__(self):
+        return self.expr
 
 
 class Const(Type):
@@ -107,13 +153,13 @@ class OutPointer(Pointer):
         return True
 
 
-class Enum(Type):
+class Enum(Concrete):
 
     def __init__(self, name, values):
-        Type.__init__(self, name)
+        Concrete.__init__(self, name)
         self.values = values
     
-    def dump(self, instance):
+    def _dump(self, instance):
         print '    switch(%s) {' % instance
         for value in self.values:
             print '    case %s:' % value
@@ -125,32 +171,36 @@ class Enum(Type):
         print '    }'
 
 
-class Flags(Type):
+class Flags(Concrete):
 
+    __seq = 0
+    
     def __init__(self, type, values):
-        Type.__init__(self, type.name)
+        Flags.__seq += 1
+        Concrete.__init__(self, type.name + str(Flags.__seq))
         self.type = type
         self.values = values
 
-    def dump(self, instance):
-        print '    {'
-        print '        %s l_Value = %s;' % (self.type, instance)
+    def __str__(self):
+        return str(self.type)
+    
+    def _dump(self, instance):
+        print '    %s l_Value = %s;' % (self.type, instance)
         for value in self.values:
-            print '        if((l_Value & %s) == %s) {' % (value, value)
-            print '            Log::Text("%s | ");' % value
-            print '            l_Value &= ~%s;' % value
-            print '        }'
+            print '    if((l_Value & %s) == %s) {' % (value, value)
+            print '        Log::Text("%s | ");' % value
+            print '        l_Value &= ~%s;' % value
+            print '    }'
         self.type.dump("l_Value");
-        print '    }'
 
 
-class Struct(Type):
+class Struct(Concrete):
 
     def __init__(self, name, members):
-        Type.__init__(self, name)
+        Concrete.__init__(self, name)
         self.members = members
 
-    def dump(self, instance):
+    def _dump(self, instance):
         print '    Log::Text("{");'
         first = True
         for type, name in self.members:
@@ -311,7 +361,21 @@ class WrapPointer(Pointer):
         print "    if(%s)" % instance
         print "        %s = static_cast<%s *>(%s)->m_pInstance;" % (instance, self.type.wrap_name(), instance)
 
-String = Intrinsic("char *", "%s")
+
+class _String(Type):
+
+    def __init__(self):
+        Type.__init__(self, "String")
+
+    def __str__(self):
+        return "char *"
+
+    def dump(self, instance):
+        print '    Log::DumpString(%s);' % instance
+
+String = _String()
+
+
 Short = Intrinsic("short", "%i")
 Int = Intrinsic("int", "%i")
 Long = Intrinsic("long", "%li")
@@ -319,6 +383,12 @@ Float = Intrinsic("float", "%f")
 
 
 def wrap():
+    for type in all_types.itervalues():
+        type.decl()
+    print
+    for type in all_types.itervalues():
+        type.impl()
+    print
     for type in towrap:
         type.wrap_pre_decl()
     print
index 6acde2740a62a9131b4136181b83d4d1c2324d5c..f92d86169ff9a2a58ec34c7e809e35ee9ae2a128 100644 (file)
@@ -249,24 +249,27 @@ D3DVTXPCAPS = Flags(DWORD, [
     "D3DVTXPCAPS_NO_VSDT_UBYTE4",
 ])
 
-D3DPS_VERSION = Enum("DWORD", [
-    "D3DPS_VERSION(0,0)",
-    "D3DPS_VERSION(1,0)",
-    "D3DPS_VERSION(1,1)",
-    "D3DPS_VERSION(1,2)",
-    "D3DPS_VERSION(1,3)",
-    "D3DPS_VERSION(1,4)",
-    "D3DPS_VERSION(2,0)",
-    "D3DPS_VERSION(3,0)",
-])
+#D3DPS_VERSION = Enum("DWORD", [
+#    "D3DPS_VERSION(0,0)",
+#    "D3DPS_VERSION(1,0)",
+#    "D3DPS_VERSION(1,1)",
+#    "D3DPS_VERSION(1,2)",
+#    "D3DPS_VERSION(1,3)",
+#    "D3DPS_VERSION(1,4)",
+#    "D3DPS_VERSION(2,0)",
+#    "D3DPS_VERSION(3,0)",
+#])
+D3DPS_VERSION = DWORD
+
+#D3DVS_VERSION = Enum("DWORD", [
+#    "D3DVS_VERSION(0,0)",
+#    "D3DVS_VERSION(1,0)",
+#    "D3DVS_VERSION(1,1)",
+#    "D3DVS_VERSION(2,0)",
+#    "D3DVS_VERSION(3,0)",
+#])
+D3DVS_VERSION = DWORD
 
-D3DVS_VERSION = Enum("DWORD", [
-    "D3DVS_VERSION(0,0)",
-    "D3DVS_VERSION(1,0)",
-    "D3DVS_VERSION(1,1)",
-    "D3DVS_VERSION(2,0)",
-    "D3DVS_VERSION(3,0)",
-])
 
 D3DCAPS8 = Struct("D3DCAPS8", [
     (D3DDEVTYPE, "DeviceType"),
index 6691b0f8265a69c2d12b3df2d20571850b09fc88..0bd1ec4dde9f45969ebe15ca8cfcd3f4dd27cc48 100644 (file)
@@ -248,7 +248,6 @@ D3DTRANSFORMSTATETYPE = Enum("D3DTRANSFORMSTATETYPE", [
 ])
 
 D3DTS = Flags(DWORD, [
-    "D3DTS_WORLDMATRIX(index)",
     "D3DTS_WORLD",
     "D3DTS_WORLD1",
     "D3DTS_WORLD2",
@@ -618,8 +617,7 @@ D3DSHADER_PARAM_REGISTER_TYPE = Enum("D3DSHADER_PARAM_REGISTER_TYPE", [
     "D3DSPR_TEMP",
     "D3DSPR_INPUT",
     "D3DSPR_CONST",
-    "D3DSPR_ADDR",
-    "D3DSPR_TEXTURE",
+    "D3DSPR_ADDR|D3DSPR_TEXTURE",
     "D3DSPR_RASTOUT",
     "D3DSPR_ATTROUT",
     "D3DSPR_TEXCRDOUT",
index b43758b696de730be25330432436aabac624fa87..52a9ec685263c04efd55b960d6c53104617b6a15 100644 (file)
@@ -320,24 +320,26 @@ D3DDTCAPS = Flags(DWORD, [
     "D3DDTCAPS_FLOAT16_4",
 ])
 
-D3DPS_VERSION = Enum("DWORD", [
-    "D3DPS_VERSION(0,0)",
-    "D3DPS_VERSION(1,0)",
-    "D3DPS_VERSION(1,1)",
-    "D3DPS_VERSION(1,2)",
-    "D3DPS_VERSION(1,3)",
-    "D3DPS_VERSION(1,4)",
-    "D3DPS_VERSION(2,0)",
-    "D3DPS_VERSION(3,0)",
-])
-
-D3DVS_VERSION = Enum("DWORD", [
-    "D3DVS_VERSION(0,0)",
-    "D3DVS_VERSION(1,0)",
-    "D3DVS_VERSION(1,1)",
-    "D3DVS_VERSION(2,0)",
-    "D3DVS_VERSION(3,0)",
-])
+#D3DPS_VERSION = Enum("DWORD", [
+#    "D3DPS_VERSION(0,0)",
+#    "D3DPS_VERSION(1,0)",
+#    "D3DPS_VERSION(1,1)",
+#    "D3DPS_VERSION(1,2)",
+#    "D3DPS_VERSION(1,3)",
+#    "D3DPS_VERSION(1,4)",
+#    "D3DPS_VERSION(2,0)",
+#    "D3DPS_VERSION(3,0)",
+#])
+D3DPS_VERSION = DWORD
+
+#D3DVS_VERSION = Enum("DWORD", [
+#    "D3DVS_VERSION(0,0)",
+#    "D3DVS_VERSION(1,0)",
+#    "D3DVS_VERSION(1,1)",
+#    "D3DVS_VERSION(2,0)",
+#    "D3DVS_VERSION(3,0)",
+#])
+D3DVS_VERSION = DWORD
 
 D3DCAPS9 = Struct("D3DCAPS9", [
     (D3DDEVTYPE, "DeviceType"),
index a8ac525b7746caf97ebf1be3a5e9456d8cf712b7..bdbdf46427b4d3c6d3b78443c2517f2e7a700424 100644 (file)
@@ -247,7 +247,6 @@ D3DTRANSFORMSTATETYPE = Enum("D3DTRANSFORMSTATETYPE", [
 ])
 
 D3DTS = Flags(DWORD, [
-    "D3DTS_WORLDMATRIX(index)",
     "D3DTS_WORLD",
     "D3DTS_WORLD1",
     "D3DTS_WORLD2",
@@ -725,12 +724,10 @@ D3DSHADER_PARAM_REGISTER_TYPE = Enum("D3DSHADER_PARAM_REGISTER_TYPE", [
     "D3DSPR_TEMP",
     "D3DSPR_INPUT",
     "D3DSPR_CONST",
-    "D3DSPR_ADDR",
-    "D3DSPR_TEXTURE",
+    "D3DSPR_ADDR|D3DSPR_TEXTURE",
     "D3DSPR_RASTOUT",
     "D3DSPR_ATTROUT",
-    "D3DSPR_TEXCRDOUT",
-    "D3DSPR_OUTPUT",
+    "D3DSPR_TEXCRDOUT|D3DSPR_OUTPUT",
     "D3DSPR_CONSTINT",
     "D3DSPR_COLOROUT",
     "D3DSPR_DEPTHOUT",
@@ -1299,8 +1296,8 @@ D3DCOMPOSERECTDESC = Struct("D3DCOMPOSERECTDESC", [
 D3DCOMPOSERECTDESTINATION = Struct("D3DCOMPOSERECTDESTINATION", [
     (USHORT, "SrcRectIndex"),
     (USHORT, "Reserved"),
-    (Short, "x"),
-    (Short, "y"),
+    (Short, "X"),
+    (Short, "Y"),
 ])
 
 D3DPRESENTSTATS = Struct("D3DPRESENTSTATS", [
diff --git a/log.cpp b/log.cpp
index 9a0ef3f993cf04cad273f66612d1fe969a035417..f4c77465ad2a1851b5d33d7811d7f38db0260272 100644 (file)
--- a/log.cpp
+++ b/log.cpp
@@ -96,7 +96,6 @@ static void Write(const char *szText) {
     }
 }
 
-
 void Open(const TCHAR *szName) {
     _Open(szName, TEXT("xml"));
     Write("<?xml version='1.0' encoding='UTF-8'?>");
@@ -175,13 +174,20 @@ void Text(const char *text) {
     Escape(text);
 }
 
+static void TextChar(char c) {
+    char szText[2];
+    szText[0] = c;
+    szText[1] = 0;
+    Text(szText);
+}
+
 void TextF(const char *format, ...) {
     char szBuffer[4196];
     va_list ap;
     va_start(ap, format);
     vsnprintf(szBuffer, sizeof(szBuffer), format, ap);
     va_end(ap);
-    Escape(szBuffer);
+    Text(szBuffer);
 }
 
 void BeginCall(const char *function) {
@@ -216,5 +222,32 @@ void EndReturn(void) {
     NewLine();
 }
 
+void DumpString(const char *str) {
+    const unsigned char *p = (const unsigned char *)str;
+    Log::Text("\"");
+    unsigned char c;
+    while((c = *p++) != 0) {
+        if(c >= 0x20 && c <= 0x7e)
+            TextChar(c);
+        else if(c == '\t')
+            Text("\\t");
+        else if(c == '\r')
+            Text("\\r");
+        else if(c == '\n')
+            Text("\\n");
+        else {
+            unsigned char octal0 = c & 0x7;
+            unsigned char octal1 = (c >> 3) & 0x7;
+            unsigned char octal2 = (c >> 3) & 0x7;
+            if(octal2)
+                TextF("\\%u%u%u", octal2, octal1, octal0);
+            else if(octal1)
+                TextF("\\%u%u", octal1, octal0);
+            else
+                TextF("\\%u", octal0);
+        }
+    }
+    Log::Text("\"");
+}
 
-} /* namespace Log */
\ No newline at end of file
+} /* namespace Log */
diff --git a/log.hpp b/log.hpp
index 1e75c20d6ce8344564e601c6f9a0ef8990658363..abeebe6f26172cebff42bc808400a01a4d226bc8 100644 (file)
--- a/log.hpp
+++ b/log.hpp
@@ -47,6 +47,8 @@ namespace Log {
     void EndParam(void);
     void BeginReturn(const char *type);
     void EndReturn(void);
+
+    void DumpString(const char *str);
 }
 
 #endif /* _LOG_HPP_ */
index 090e2469edd9eb5567c7a91f29f77496665d20ef..d5041a944e30cf351fc0eb13de0f3d18e536b681 100644 (file)
@@ -48,9 +48,31 @@ HWND = Intrinsic("HWND", "%p")
 HDC = Intrinsic("HDC", "%p")
 HMONITOR = Intrinsic("HMONITOR", "%p")
 
-REFIID = Alias("REFIID", PVOID)
-GUID = Alias("GUID", PVOID)
-LUID = Alias("LUID", PVOID)
+GUID = Struct("GUID", [
+    (DWORD, "Data1"),
+    (WORD, "Data2"),
+    (WORD, "Data3"),
+    (BYTE, "Data4[0]"),
+    (BYTE, "Data4[1]"),
+    (BYTE, "Data4[2]"),
+    (BYTE, "Data4[3]"),
+    (BYTE, "Data4[4]"),
+    (BYTE, "Data4[5]"),
+    (BYTE, "Data4[6]"),
+    (BYTE, "Data4[7]"),
+])
+
+#REFGUID = Alias("REFGUID", Pointer(GUID))
+REFGUID = Alias("REFGUID", GUID)
+
+IID = Alias("IID", GUID)
+#REFIID = Alias("REFIID", Pointer(IID))
+REFIID = Alias("REFIID", IID)
+
+LUID = Struct("LUID", [
+    (DWORD, "LowPart"),
+    (LONG, "HighPart"),
+])
 
 POINT = Struct("POINT", (
   (LONG, "x"),
@@ -71,8 +93,19 @@ PALETTEENTRY = Struct("PALETTEENTRY", (
   (BYTE, "peFlags"), 
 )) 
 
-RGNDATA = Struct("RGNDATA", ())
-REFGUID = Alias("REFGUID", PVOID)
+
+RGNDATAHEADER = Struct("RGNDATAHEADER", [
+    (DWORD, "dwSize"),
+    (DWORD, "iType"),
+    (DWORD, "nCount"),
+    (DWORD, "nRgnSize"),
+    (RECT, "rcBound"),
+])
+
+RGNDATA = Struct("RGNDATA", [
+    (RGNDATAHEADER, "rdh"),
+    #(Char, "Buffer[1]"),
+])
 
 
 IUnknown = Interface("IUnknown")