]> git.cworth.org Git - apitrace/commitdiff
Merge branch 'master' into d3dretrace
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 30 Mar 2012 19:41:25 +0000 (20:41 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Fri, 30 Mar 2012 19:41:25 +0000 (20:41 +0100)
Conflicts:
retrace.py

1  2 
CMakeLists.txt
retrace.hpp
retrace.py

diff --combined CMakeLists.txt
index 35d9a7848560cb8d77d89beca9f3b8fc40224848,ed0905510333f44c722cf535f57b095351500679..03208fbf8ce3b4bea46019019684f71e873424f8
@@@ -60,10 -60,6 +60,6 @@@ else (
          include_directories (${X11_INCLUDE_DIR})
          add_definitions (-DHAVE_X11)
      endif ()
-     if (ENABLE_EGL)
-         add_definitions (-DHAVE_EGL)
-     endif ()
  endif ()
  
  
@@@ -510,12 -506,6 +506,6 @@@ if (ENABLE_EGL AND NOT WIN32 AND NOT AP
  
      add_dependencies (egltrace glproc)
  
-     set_property (
-         TARGET egltrace
-         APPEND
-         PROPERTY COMPILE_DEFINITIONS "TRACE_EGL"
-     )
      set_target_properties (egltrace PROPERTIES
          # avoid the default "lib" prefix
          PREFIX ""
@@@ -548,11 -538,11 +538,11 @@@ add_custom_command 
  
  add_custom_command (
      OUTPUT glstate_params.cpp
-     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
-     DEPENDS glstate.py specs/glparams.py specs/gltypes.py specs/stdapi.py
+     COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/glstate_params.py > ${CMAKE_CURRENT_BINARY_DIR}/glstate_params.cpp
+     DEPENDS glstate_params.py specs/glparams.py specs/gltypes.py specs/stdapi.py
  )
  
- set (retrace_sources
+ add_library (retrace_common
      glretrace_gl.cpp
      glretrace_cgl.cpp
      glretrace_glx.cpp
      glretrace_egl.cpp
      glretrace_main.cpp
      glstate.cpp
+     glstate_images.cpp
      glstate_params.cpp
+     glstate_shaders.cpp
      retrace.cpp
      retrace_stdc.cpp
      glws.cpp
  )
  
+ set_property (
+     TARGET retrace_common
+     APPEND
+     PROPERTY COMPILE_DEFINITIONS "RETRACE"
+ )
  if (WIN32 OR APPLE OR X11_FOUND)
      add_executable (glretrace
-         ${retrace_sources}
          ${glws_os}
          glproc_gl.cpp
      )
      )
  
      target_link_libraries (glretrace
+         retrace_common
          common
          ${PNG_LIBRARIES}
          ${ZLIB_LIBRARIES}
@@@ -619,7 -617,6 +617,6 @@@ endif (
  
  if (ENABLE_EGL AND X11_FOUND AND NOT WIN32 AND NOT APPLE)
      add_executable (eglretrace
-         ${retrace_sources}
          glws_egl_xlib.cpp
          glproc_egl.cpp
      )
          TARGET eglretrace
          APPEND
          PROPERTY COMPILE_DEFINITIONS "RETRACE"
-         PROPERTY COMPILE_DEFINITIONS "TRACE_EGL"
      )
  
      target_link_libraries (eglretrace
+         retrace_common
          common
          ${PNG_LIBRARIES}
          ${ZLIB_LIBRARIES}
      install (TARGETS eglretrace RUNTIME DESTINATION bin) 
  endif ()
  
 +if (WIN32 AND DirectX_D3DX9_INCLUDE_DIR)
 +    add_custom_command (
 +        OUTPUT d3dretrace_d3d9.cpp
 +        COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/d3dretrace.py > ${CMAKE_CURRENT_BINARY_DIR}/d3dretrace_d3d9.cpp
 +        DEPENDS d3dretrace.py retrace.py specs/d3d9.py specs/d3d9types.py specs/d3d9caps.py specs/winapi.py specs/stdapi.py
 +    )
 +
 +    include_directories (SYSTEM ${DirectX_D3DX9_INCLUDE_DIR})
 +    add_executable (d3dretrace
 +        retrace.cpp
 +        d3dretrace_main.cpp
 +        d3dretrace_d3d9.cpp
 +    )
 +endif ()
 +
  ##############################################################################
  # CLI
  
diff --combined retrace.hpp
index a4559c730f8baf49d7e8661315315f0b9cdbd61d,dc11bb382243b13c51afe837c7fec40f6664a7de..1b5fdd23cdff7ba01ee17d3164d8697e332f2229
@@@ -1,6 -1,6 +1,6 @@@
  /**************************************************************************
   *
-  * Copyright 2011 Jose Fonseca
+  * Copyright 2011-2012 Jose Fonseca
   * All Rights Reserved.
   *
   * Permission is hereby granted, free of charge, to any person obtaining a copy
  #include <ostream>
  
  #include "trace_model.hpp"
 +#include "trace_parser.hpp"
  
  
  namespace retrace {
  
  
 +extern trace::Parser parser;
 +
 +
  /**
   * Handle map.
   *
@@@ -84,6 -80,53 +84,53 @@@ public
  };
  
  
+ /**
+  * Similar to alloca(), but implemented with malloc.
+  */
+ class ScopedAllocator
+ {
+ private:
+     void *next;
+ public:
+     ScopedAllocator() :
+         next(NULL) {
+     }
+     inline void *
+     alloc(size_t size) {
+         if (!size) {
+             return NULL;
+         }
+         void * * buf = static_cast<void **>(malloc(sizeof(void *) + size));
+         if (!buf) {
+             return NULL;
+         }
+         *buf = next;
+         next = buf;
+         return &buf[1];
+     }
+     template< class T >
+     inline T *
+     alloc(size_t n = 1) {
+         return static_cast<T *>(alloc(sizeof(T) * n));
+     }
+     inline
+     ~ScopedAllocator() {
+         while (next) {
+             void *temp = *static_cast<void **>(next);
+             free(next);
+             next = temp;
+         }
+     }
+ };
  void
  addRegion(unsigned long long address, void *buffer, unsigned long long size);
  
diff --combined retrace.py
index 15cdaf5038e328d05e8646c564670d9ffe8c13fa,1203a0992e4cebde23706c2fc5a90190d420986d..d6e838755c39a02cd6f517af2866f9d0736c6074
@@@ -72,7 -72,7 +72,7 @@@ class ValueDeserializer(stdapi.Visitor)
          print '    const trace::Array *__a%s = dynamic_cast<const trace::Array *>(&%s);' % (array.tag, rvalue)
          print '    if (__a%s) {' % (array.tag)
          length = '__a%s->values.size()' % array.tag
-         print '        %s = new %s[%s];' % (lvalue, array.type, length)
+         print '        %s = _allocator.alloc<%s>(%s);' % (lvalue, array.type, length)
          index = '__j' + array.tag
          print '        for (size_t {i} = 0; {i} < {length}; ++{i}) {{'.format(i = index, length = length)
          try:
@@@ -86,7 -86,7 +86,7 @@@
      def visitPointer(self, pointer, lvalue, rvalue):
          print '    const trace::Array *__a%s = dynamic_cast<const trace::Array *>(&%s);' % (pointer.tag, rvalue)
          print '    if (__a%s) {' % (pointer.tag)
-         print '        %s = new %s;' % (lvalue, pointer.type)
+         print '        %s = _allocator.alloc<%s>();' % (lvalue, pointer.type)
          try:
              self.visit(pointer.type, '%s[0]' % (lvalue,), '*__a%s->values[0]' % (pointer.tag,))
          finally:
@@@ -207,41 -207,13 +207,43 @@@ class Retracer
          print '}'
          print
  
 +    def retraceInterfaceMethod(self, interface, method):
 +        print 'static void retrace_%s__%s(trace::Call &call) {' % (interface.name, method.name)
 +        self.retraceInterfaceMethodBody(interface, method)
 +        print '}'
 +        print
 +
      def retraceFunctionBody(self, function):
          if not function.sideeffects:
              print '    (void)call;'
              return
  
 +        self.deserializeArgs(function)
 +        
 +        self.invokeFunction(function)
 +
 +        self.swizzleValues(function)
 +
 +    def retraceInterfaceMethodBody(self, interface, method):
 +        if not method.sideeffects:
 +            print '    (void)call;'
 +            return
 +
 +        self.deserializeThisPointer(interface)
 +
 +        self.deserializeArgs(method)
 +        
 +        self.invokeInterfaceMethod(interface, method)
 +
 +        self.swizzleValues(method)
 +
 +    def deserializeThisPointer(self, interface):
 +        print '    %s *_this;' % (interface.name,)
 +        # FIXME
 +
 +    def deserializeArgs(self, function):
+         print '    retrace::ScopedAllocator _allocator;'
+         print '    (void)_allocator;'
          success = True
          for arg in function.args:
              arg_type = ConstRemover().visit(arg.type)
              try:
                  self.extractArg(function, arg, arg_type, lvalue, rvalue)
              except NotImplementedError:
 -                success = False
 +                success =  False
                  print '    %s = 0; // FIXME' % arg.name
 +
          if not success:
              print '    if (1) {'
              self.failFunction(function)
 +            if function.name[-1].islower():
 +                sys.stderr.write('warning: unsupported %s call\n' % function.name)
              print '    }'
 -        self.invokeFunction(function)
 +
 +    def swizzleValues(self, function):
          for arg in function.args:
              if arg.output:
                  arg_type = ConstRemover().visit(arg.type)
                  self.regiterSwizzledValue(function.type, lvalue, rvalue)
              except NotImplementedError:
                  print '    // XXX: result'
 -        if not success:
 -            if function.name[-1].islower():
 -                sys.stderr.write('warning: unsupported %s call\n' % function.name)
  
      def failFunction(self, function):
          print '    if (retrace::verbosity >= 0) {'
          else:
              print '    %s(%s);' % (function.name, arg_names)
  
 +    def invokeInterfaceMethod(self, interface, method):
 +        arg_names = ", ".join(method.argNames())
 +        if method.type is not stdapi.Void:
 +            print '    %s __result;' % (method.type)
 +            print '    __result = _this->%s(%s);' % (method.name, arg_names)
 +            print '    (void)__result;'
 +        else:
 +            print '    _this->%s(%s);' % (method.name, arg_names)
 +
      def filterFunction(self, function):
          return True
  
      table_name = 'retrace::callbacks'
  
 -    def retraceFunctions(self, functions):
 -        functions = filter(self.filterFunction, functions)
 -
 -        for function in functions:
 -            self.retraceFunction(function)
 -
 -        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
 -
 -
      def retraceApi(self, api):
  
          print '#include "trace_parser.hpp"'
                  handle_names.add(handle.name)
          print
  
 -        self.retraceFunctions(api.functions)
 +        functions = filter(self.filterFunction, api.functions)
 +        for function in functions:
 +            self.retraceFunction(function)
 +        interfaces = api.getAllInterfaces()
 +        for interface in interfaces:
 +            for method in interface.iterMethods():
 +                self.retraceInterfaceMethod(interface, method)
 +
 +        print 'const retrace::Entry %s[] = {' % self.table_name
 +        for function in functions:
 +            print '    {"%s", &retrace_%s},' % (function.name, function.name)
 +        for interface in interfaces:
 +            for method in interface.iterMethods():
 +                print '    {"%s::%s", &retrace_%s__%s},' % (interface.name, method.name, interface.name, method.name)
 +        print '    {NULL, NULL}'
 +        print '};'
 +        print