]> git.cworth.org Git - apitrace/blobdiff - trace.py
Handle vertex attriv locations correctly.
[apitrace] / trace.py
index 95a9807ff160f6d01eeb5a1094da83c64a7265e2..6d8432b826a7bb605192f42742739d31fcf70c2f 100644 (file)
--- a/trace.py
+++ b/trace.py
@@ -27,6 +27,7 @@
 
 
 import stdapi
+from dispatch import Dispatcher
 
 
 def interface_wrap_name(interface):
@@ -72,12 +73,15 @@ class DumpDeclarator(stdapi.OnceVisitor):
     def visit_blob(self, array):
         pass
 
+    __enum_id = 0
+
     def visit_enum(self, enum):
         print 'static void __traceEnum%s(const %s value) {' % (enum.id, enum.expr)
         n = len(enum.values)
         for i in range(n):
             value = enum.values[i]
-            print '    static const Trace::EnumSig sig%u = {%u, "%s", %s};' % (i, enum.vid + i, value, value)
+            print '    static const Trace::EnumSig sig%u = {%u, "%s", %s};' % (i, DumpDeclarator.__enum_id, value, value)
+            DumpDeclarator.__enum_id += 1
         print '    const Trace::EnumSig *sig;'
         print '    switch(value) {'
         for i in range(n):
@@ -89,7 +93,7 @@ class DumpDeclarator(stdapi.OnceVisitor):
         print '        Trace::LiteralSInt(value);'
         print '        return;'
         print '    }'
-        print '        Trace::LiteralEnum(sig);'
+        print '    Trace::LiteralEnum(sig);'
         print '}'
         print
 
@@ -151,7 +155,7 @@ class DumpImplementer(stdapi.Visitor):
         print '    __traceStruct%s(%s);' % (struct.id, instance)
 
     def visit_array(self, array, instance):
-        print '    if(%s) {' % instance
+        print '    if (%s) {' % instance
         index = '__i' + array.type.id
         print '        Trace::BeginArray(%s);' % (array.length,)
         print '        for (int %s = 0; %s < %s; ++%s) {' % (index, index, array.length, index)
@@ -174,7 +178,7 @@ class DumpImplementer(stdapi.Visitor):
         print '    Trace::LiteralBitmask(__bitmask%s_sig, %s);' % (bitmask.id, instance)
 
     def visit_pointer(self, pointer, instance):
-        print '    if(%s) {' % instance
+        print '    if (%s) {' % instance
         print '        Trace::BeginArray(1);'
         print '        Trace::BeginElement();'
         dump_instance(pointer.type, "*" + instance)
@@ -248,7 +252,7 @@ class Wrapper(stdapi.Visitor):
     def visit_interface(self, interface, instance):
         assert instance.startswith('*')
         instance = instance[1:]
-        print "    if(%s)" % instance
+        print "    if (%s)" % instance
         print "        %s = new %s(%s);" % (instance, interface_wrap_name(interface), instance)
 
 
@@ -257,7 +261,7 @@ class Unwrapper(Wrapper):
     def visit_interface(self, interface, instance):
         assert instance.startswith('*')
         instance = instance[1:]
-        print "    if(%s)" % instance
+        print "    if (%s)" % instance
         print "        %s = static_cast<%s *>(%s)->m_pInstance;" % (instance, interface_wrap_name(interface), instance)
 
 
@@ -312,8 +316,15 @@ class Tracer:
     def get_dispatch_function(self, function):
         return '__' + function.name
 
+    def is_public_function(self, function):
+        return True
+
     def trace_function_impl(self, function):
-        print 'extern "C" ' + function.prototype() + ' {'
+        if self.is_public_function(function):
+            print 'extern "C" PUBLIC'
+        else:
+            print 'extern "C" PRIVATE'
+        print function.prototype() + ' {'
         if function.type is not stdapi.Void:
             print '    %s __result;' % function.type
         self.trace_function_impl_body(function)
@@ -350,9 +361,12 @@ class Tracer:
 
     def dump_arg(self, function, arg):
         print '    Trace::BeginArg(%u);' % (arg.index,)
-        dump_instance(arg.type, arg.name)
+        self.dump_arg_instance(function, arg)
         print '    Trace::EndArg();'
 
+    def dump_arg_instance(self, function, arg):
+        dump_instance(arg.type, arg.name)
+
     def wrap_arg(self, function, arg):
         wrap_instance(arg.type, arg.name)
 
@@ -430,17 +444,12 @@ class DllTracer(Tracer):
     def __init__(self, dllname):
         self.dllname = dllname
     
-    def get_function_address(self, function):
-        return '__%s' % (function.name,)
-
     def header(self, api):
-        Tracer.header(self, api)
-
         print '''
 static HINSTANCE g_hDll = NULL;
 
 static PROC
-__GetProcAddress(LPCSTR lpProcName)
+__getPublicProcAddress(LPCSTR lpProcName)
 {
     if (!g_hDll) {
         char szDll[MAX_PATH] = {0};
@@ -460,5 +469,11 @@ __GetProcAddress(LPCSTR lpProcName)
     return GetProcAddress(g_hDll, lpProcName);
 }
 
-    ''' % self.dllname
+#define __abort() OS::Abort()
+''' % self.dllname
+
+        dispatcher = Dispatcher()
+        dispatcher.dispatch_api(api)
+
+        Tracer.header(self, api)