]> git.cworth.org Git - apitrace/blobdiff - wrappers/trace.py
Merge remote-tracking branch 'github/master' into d2d
[apitrace] / wrappers / trace.py
index aab99d793c1ce433bf6ad19d97d7afd89bfbac15..4e52cf652a661fab24931ec65508280e3d84f91e 100644 (file)
@@ -162,12 +162,12 @@ class ValueSerializer(stdapi.Visitor):
         print '    trace::localWriter.write%s(%s);' % (literal.kind, instance)
 
     def visitString(self, string, instance):
-        if string.kind == 'String':
+        if not string.wide:
             cast = 'const char *'
-        elif string.kind == 'WString':
-            cast = 'const wchar_t *'
+            suffix = 'String'
         else:
-            assert False
+            cast = 'const wchar_t *'
+            suffix = 'WString'
         if cast != string.expr:
             # reinterpret_cast is necessary for GLubyte * <=> char *
             instance = 'reinterpret_cast<%s>(%s)' % (cast, instance)
@@ -175,7 +175,7 @@ class ValueSerializer(stdapi.Visitor):
             length = ', %s' % string.length
         else:
             length = ''
-        print '    trace::localWriter.write%s(%s%s);' % (string.kind, instance, length)
+        print '    trace::localWriter.write%s(%s%s);' % (suffix, instance, length)
 
     def visitConst(self, const, instance):
         self.visit(const.type, instance)
@@ -299,6 +299,8 @@ class ValueWrapper(stdapi.Traverser):
         elem_type = pointer.type.mutable()
         if isinstance(elem_type, stdapi.Interface):
             self.visitInterfacePointer(elem_type, instance)
+        elif isinstance(elem_type, stdapi.Alias) and isinstance(elem_type.type, stdapi.Interface):
+            self.visitInterfacePointer(elem_type.type, instance)
         else:
             self.visitPointer(pointer, instance)
     
@@ -320,6 +322,23 @@ class ValueUnwrapper(ValueWrapper):
 
     allocated = False
 
+    def visitStruct(self, struct, instance):
+        if not self.allocated:
+            # Argument is constant. We need to create a non const
+            print '    {'
+            print "        %s * _t = static_cast<%s *>(alloca(sizeof *_t));" % (struct, struct)
+            print '        *_t = %s;' % (instance,)
+            assert instance.startswith('*')
+            print '        %s = _t;' % (instance[1:],)
+            instance = '*_t'
+            self.allocated = True
+            try:
+                return ValueWrapper.visitStruct(self, struct, instance)
+            finally:
+                print '    }'
+        else:
+            return ValueWrapper.visitStruct(self, struct, instance)
+
     def visitArray(self, array, instance):
         if self.allocated or isinstance(instance, stdapi.Interface):
             return ValueWrapper.visitArray(self, array, instance)
@@ -396,6 +415,9 @@ class Tracer:
         print '#else'
         print '#  include <alloca.h> // alloca'
         print '#endif'
+        print
+        print '#include "trace.hpp"'
+        print
 
     def footer(self, api):
         pass
@@ -422,14 +444,16 @@ class Tracer:
         print function.prototype() + ' {'
         if function.type is not stdapi.Void:
             print '    %s _result;' % function.type
-        print '    if (!os::apitrace_enabled()) {'
+
+        # No-op if tracing is disabled
+        print '    if (!trace::isTracingEnabled()) {'
         Tracer.invokeFunction(self, function)
         if function.type is not stdapi.Void:
             print '        return _result;'
         else:
             print '        return;'
         print '    }'
-        print
+
         self.traceFunctionImplBody(function)
         if function.type is not stdapi.Void:
             print '    return _result;'
@@ -690,4 +714,15 @@ class Tracer:
         print '        trace::localWriter.endEnter();'
         print '        trace::localWriter.beginLeave(_call);'
         print '        trace::localWriter.endLeave();'
+    
+    def fake_call(self, function, args):
+        print '            unsigned _fake_call = trace::localWriter.beginEnter(&_%s_sig);' % (function.name,)
+        for arg, instance in zip(function.args, args):
+            assert not arg.output
+            print '            trace::localWriter.beginArg(%u);' % (arg.index,)
+            self.serializeValue(arg.type, instance)
+            print '            trace::localWriter.endArg();'
+        print '            trace::localWriter.endEnter();'
+        print '            trace::localWriter.beginLeave(_fake_call);'
+        print '            trace::localWriter.endLeave();'