]> git.cworth.org Git - apitrace/blobdiff - retrace.py
Split gltrace.cpp code into multiple files.
[apitrace] / retrace.py
index c68179b7a6a0a9156ac4c2cb784bbb57ad1cce92..7fcae527222b3a038866a3882f45a4143ff07edd 100644 (file)
@@ -99,7 +99,7 @@ class ValueExtractor(stdapi.Visitor):
 
     def visit_handle(self, handle, lvalue, rvalue):
         self.visit(handle.type, lvalue, handle_entry(handle, rvalue));
-        print '    if (verbosity >= 2)'
+        print '    if (retrace::verbosity >= 2)'
         print '        std::cout << "%s " << static_cast<%s>(%s) << " <- " << %s << "\\n";' % (handle.name, handle.type, rvalue, lvalue)
     
     def visit_blob(self, blob, lvalue, rvalue):
@@ -150,7 +150,7 @@ class ValueWrapper(stdapi.Visitor):
             rvalue = "static_cast<%s>(%s)" % (handle.type, rvalue)
             entry = handle_entry(handle, rvalue) 
             print "    %s = %s;" % (entry, lvalue)
-            print '    if (verbosity >= 2)'
+            print '    if (retrace::verbosity >= 2)'
             print '        std::cout << "{handle.name} " << {rvalue} << " -> " << {lvalue} << "\\n";'.format(**locals())
         else:
             i = '__h' + handle.id
@@ -159,7 +159,7 @@ 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 (verbosity >= 2)'
+            print '        if (retrace::verbosity >= 2)'
             print '            std::cout << "{handle.name} " << ({rvalue}) << " -> " << ({lvalue}) << "\\n";'.format(**locals())
             print '    }'
     
@@ -174,6 +174,11 @@ class Retracer:
 
     def retrace_function(self, function):
         print 'static void retrace_%s(Trace::Call &call) {' % function.name
+        self.retrace_function_body(function)
+        print '}'
+        print
+
+    def retrace_function_body(self, function):
         success = True
         for arg in function.args:
             arg_type = ConstRemover().visit(arg.type)
@@ -205,11 +210,9 @@ class Retracer:
                 ValueWrapper().visit(function.type, lvalue, rvalue)
             except NotImplementedError:
                 print '   // FIXME: result'
-        print '}'
-        print
 
     def fail_function(self, function):
-        print '    if (verbosity >= 0)'
+        print '    if (retrace::verbosity >= 0)'
         print '        std::cerr << "warning: unsupported call %s\\n";' % function.name
         print '    return;'
 
@@ -234,10 +237,10 @@ class Retracer:
             if function.sideeffects:
                 self.retrace_function(function)
 
-        print 'static bool retrace_call(Trace::Call &call) {'
+        print 'bool retrace::retrace_call(Trace::Call &call) {'
         print '    const char *name = call.name().c_str();'
         print
-        print '    if (verbosity >= 1) {'
+        print '    if (retrace::verbosity >= 1) {'
         print '        std::cout << call;'
         print '        std::cout.flush();'
         print '    };'
@@ -253,7 +256,7 @@ class Retracer:
     
         string_switch('name', func_dict.keys(), handle_case)
 
-        print '    if (verbosity >= 0)'
+        print '    if (retrace::verbosity >= 0)'
         print '        std::cerr << "warning: unknown call " << call.name() << "\\n";'
         print '    return false;'
         print '}'
@@ -263,6 +266,7 @@ class Retracer:
     def retrace_api(self, api):
 
         print '#include "trace_parser.hpp"'
+        print '#include "retrace.hpp"'
         print
 
         types = api.all_types()
@@ -271,15 +275,12 @@ class Retracer:
         for handle in handles:
             if handle.name not in handle_names:
                 if handle.key is None:
-                    print 'static std::map<%s, %s> __%s_map;' % (handle.type, handle.type, handle.name)
+                    print 'static retrace::map<%s> __%s_map;' % (handle.type, handle.name)
                 else:
                     key_name, key_type = handle.key
-                    print 'static std::map<%s, std::map<%s, %s> > __%s_map;' % (key_type, handle.type, handle.type, handle.name)
+                    print 'static std::map<%s, retrace::map<%s> > __%s_map;' % (key_type, handle.type, handle.name)
                 handle_names.add(handle.name)
         print
 
-        print 'int verbosity = 0;'
-        print
-
         self.retrace_functions(api.functions)