]> git.cworth.org Git - apitrace/blobdiff - retrace.py
Fix a crash when loading multiple frames at once.
[apitrace] / retrace.py
index 9e42be38b874edd0f25404f7773e6cad2975a311..9092f351366a2377231761c962e2c1daec382879 100644 (file)
@@ -26,9 +26,8 @@
 
 """Generic retracing code generator."""
 
-import stdapi
-import glapi
-from codegen import *
+import specs.stdapi as stdapi
+import specs.glapi as glapi
 
 
 class ConstRemover(stdapi.Rebuilder):
@@ -95,8 +94,9 @@ class ValueExtractor(stdapi.Visitor):
     def visit_handle(self, handle, lvalue, rvalue):
         OpaqueValueExtractor().visit(handle.type, lvalue, rvalue);
         new_lvalue = handle_entry(handle, lvalue)
-        print '    if (retrace::verbosity >= 2)'
+        print '    if (retrace::verbosity >= 2) {'
         print '        std::cout << "%s " << size_t(%s) << " <- " << size_t(%s) << "\\n";' % (handle.name, lvalue, new_lvalue)
+        print '    }'
         print '    %s = %s;' % (lvalue, new_lvalue)
     
     def visit_blob(self, blob, lvalue, rvalue):
@@ -157,8 +157,9 @@ class ValueWrapper(stdapi.Visitor):
             rvalue = "__orig_result"
             entry = handle_entry(handle, rvalue) 
             print "    %s = %s;" % (entry, lvalue)
-            print '    if (retrace::verbosity >= 2)'
+            print '    if (retrace::verbosity >= 2) {'
             print '        std::cout << "{handle.name} " << {rvalue} << " -> " << {lvalue} << "\\n";'.format(**locals())
+            print '    }'
         else:
             i = '__h' + handle.id
             lvalue = "%s + %s" % (lvalue, i)
@@ -166,8 +167,9 @@ class ValueWrapper(stdapi.Visitor):
             entry = handle_entry(handle, rvalue) 
             print '    for ({handle.type} {i} = 0; {i} < {handle.range}; ++{i}) {{'.format(**locals())
             print '        {entry} = {lvalue};'.format(**locals())
-            print '        if (retrace::verbosity >= 2)'
+            print '        if (retrace::verbosity >= 2) {'
             print '            std::cout << "{handle.name} " << ({rvalue}) << " -> " << ({lvalue}) << "\\n";'.format(**locals())
+            print '        }'
             print '    }'
     
     def visit_blob(self, blob, lvalue, rvalue):
@@ -186,6 +188,10 @@ class Retracer:
         print
 
     def retrace_function_body(self, function):
+        if not function.sideeffects:
+            print '    (void)call;'
+            return
+
         success = True
         for arg in function.args:
             arg_type = ConstRemover().visit(arg.type)
@@ -199,7 +205,9 @@ class Retracer:
                 success = False
                 print '    %s = 0; // FIXME' % arg.name
         if not success:
+            print '    if (1) {'
             self.fail_function(function)
+            print '    }'
         self.call_function(function)
         for arg in function.args:
             if arg.output:
@@ -225,41 +233,35 @@ class Retracer:
 
     def extract_arg(self, function, arg, arg_type, lvalue, rvalue):
         ValueExtractor().visit(arg_type, lvalue, rvalue)
+    
+    def extract_opaque_arg(self, function, arg, arg_type, lvalue, rvalue):
+        OpaqueValueExtractor().visit(arg_type, lvalue, rvalue)
 
     def call_function(self, function):
         arg_names = ", ".join([arg.name for arg in function.args])
         if function.type is not stdapi.Void:
             print '    %s __result;' % (function.type)
             print '    __result = %s(%s);' % (function.name, arg_names)
+            print '    (void)__result;'
         else:
             print '    %s(%s);' % (function.name, arg_names)
 
     def filter_function(self, function):
         return True
 
+    table_name = 'retrace::callbacks'
+
     def retrace_functions(self, functions):
         functions = filter(self.filter_function, functions)
 
         for function in functions:
-            if function.sideeffects:
-                self.retrace_function(function)
+            self.retrace_function(function)
 
-        print 'void retrace::retrace_call(Trace::Call &call) {'
-        print '    const char *name = call.name().c_str();'
-        print
-
-        func_dict = dict([(function.name, function) for function in functions])
-
-        def handle_case(function_name):
-            function = func_dict[function_name]
-            if function.sideeffects:
-                print '        retrace_%s(call);' % function.name
-            print '        return;'
-    
-        string_switch('name', func_dict.keys(), handle_case)
-
-        print '    retrace_unknown(call);'
-        print '}'
+        print 'const retrace::Entry %s[] = {' % self.table_name
+        for function in functions:
+            print '    {"%s", &retrace_%s},' % (function.name, function.name)
+        print '    {NULL, NULL}'
+        print '};'
         print