]> git.cworth.org Git - apitrace/blobdiff - glretrace.py
Less opaqueness.
[apitrace] / glretrace.py
index 8a0a68a19802c69ce3fa1d898ba32bf66eef2c69..8f65b81a825a70d5c5cb918c3d6c61c6dd801321 100644 (file)
@@ -82,7 +82,7 @@ class ValueExtractor(base.Visitor):
         print '    %s = static_cast<%s>((%s).blob());' % (lvalue, blob, rvalue)
     
     def visit_string(self, string, lvalue, rvalue):
-        print '    %s = (%s).string();' % (lvalue, rvalue)
+        print '    %s = (%s)((%s).string());' % (lvalue, string.expr, rvalue)
 
 
 
@@ -132,12 +132,13 @@ def retrace_function(function):
     print 'static void retrace_%s(Trace::Call &call) {' % function.name
     success = True
     for arg in function.args:
-        arg.type = ConstRemover().visit(arg.type)
-        print '    %s %s;' % (arg.type, arg.name)
+        arg_type = ConstRemover().visit(arg.type)
+        print '    // %s ->  %s' % (arg.type, arg_type)
+        print '    %s %s;' % (arg_type, arg.name)
         rvalue = 'call.arg("%s")' % (arg.name,)
         lvalue = arg.name
         try:
-            ValueExtractor().visit(arg.type, lvalue, rvalue)
+            ValueExtractor().visit(arg_type, lvalue, rvalue)
         except NotImplementedError:
             success = False
             print '    %s = 0; // FIXME' % arg.name
@@ -145,16 +146,27 @@ def retrace_function(function):
         print '    std::cerr << "warning: unsupported call %s\\n";' % function.name
         print '    return;'
     arg_names = ", ".join([arg.name for arg in function.args])
-    print '    %s(%s);' % (function.name, arg_names)
+    if function.type is not base.Void:
+        print '    %s __result;' % (function.type)
+        print '    __result = %s(%s);' % (function.name, arg_names)
+    else:
+        print '    %s(%s);' % (function.name, arg_names)
     for arg in function.args:
         if arg.output:
-            arg.type = ConstRemover().visit(arg.type)
+            arg_type = ConstRemover().visit(arg.type)
             rvalue = 'call.arg("%s")' % (arg.name,)
             lvalue = arg.name
             try:
-                ValueWrapper().visit(arg.type, lvalue, rvalue)
+                ValueWrapper().visit(arg_type, lvalue, rvalue)
             except NotImplementedError:
                 print '   // FIXME: %s' % arg.name
+    if function.type is not base.Void:
+        rvalue = '*call.ret'
+        lvalue = '__result'
+        try:
+            ValueWrapper().visit(function.type, lvalue, rvalue)
+        except NotImplementedError:
+            print '   // FIXME: result'
     print '}'
     print
 
@@ -186,6 +198,17 @@ def retrace_functions(functions):
     print
 
 
+def retrace_api(api):
+    types = api.all_types()
+
+    handles = [type for type in types if isinstance(type, base.Handle)]
+    for handle in handles:
+        print 'static std::map<%s, %s> __%s_map;' % (handle.type, handle.type, handle.name)
+    print
+
+    retrace_functions(api.functions)
+
+
 if __name__ == '__main__':
     print
     print '#include <stdlib.h>'
@@ -195,12 +218,7 @@ if __name__ == '__main__':
     print
     print '#include "trace_parser.hpp"'
     print
-    for name in ['texture', 'framebuffer', 'renderbuffer']:
-        print 'static std::map<GLuint, GLuint> __%s_map;' % name
-    print
-
-    retrace_functions(glapi.glapi.functions)
-
+    retrace_api(glapi.glapi)
     print '''
 
 Trace::Parser parser;