From: José Fonseca Date: Wed, 9 Jul 2008 03:18:08 +0000 (+0900) Subject: Use separate functions for dumping. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=8a56d146f4b08bfce07c0ec3c18a7601801f59d5;p=apitrace Use separate functions for dumping. --- diff --git a/base.py b/base.py index 8f91a6d..d2b4a22 100644 --- a/base.py +++ b/base.py @@ -19,6 +19,12 @@ """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 diff --git a/d3d8caps.py b/d3d8caps.py index 6acde27..f92d861 100644 --- a/d3d8caps.py +++ b/d3d8caps.py @@ -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"), diff --git a/d3d8types.py b/d3d8types.py index 6691b0f..0bd1ec4 100644 --- a/d3d8types.py +++ b/d3d8types.py @@ -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", diff --git a/d3d9caps.py b/d3d9caps.py index b43758b..52a9ec6 100644 --- a/d3d9caps.py +++ b/d3d9caps.py @@ -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"), diff --git a/d3d9types.py b/d3d9types.py index a8ac525..bdbdf46 100644 --- a/d3d9types.py +++ b/d3d9types.py @@ -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 9a0ef3f..f4c7746 100644 --- 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(""); @@ -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 1e75c20..abeebe6 100644 --- 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_ */ diff --git a/windows.py b/windows.py index 090e246..d5041a9 100644 --- a/windows.py +++ b/windows.py @@ -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")