1 ##########################################################################
3 # Copyright 2010 VMware, Inc.
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ##########################################################################/
31 def is_arg_supported(arg_type):
32 if isinstance(arg_type, (base.Literal, base._String, base.Enum)):
34 if isinstance(arg_type, (base.Alias, base.Flags)):
35 return is_arg_supported(arg_type.type)
39 def is_function_supported(function):
40 for arg_type, arg_name in function.args:
41 if not is_arg_supported(arg_type):
46 def extract_value(arg_type, arg_value):
47 if isinstance(arg_type, base.Literal):
48 return 'Trace::as%s(%s)' % (arg_type.format, value)
49 if isinstance(arg_type, base.Enum):
50 return 'Trace::asSInt(%s)' % (value)
51 if isinstance(arg_type, (base.Alias, base.Flags)):
52 return extract_value(arg_type.type, value)
57 if __name__ == '__main__':
59 print '#include <stdlib.h>'
60 print '#include <string.h>'
61 print '#include <GL/glew.h>'
62 print '#include <GL/glut.h>'
64 print '#include "trace_parser.hpp"'
67 functions = filter(is_function_supported, libgl.functions)
69 for function in functions:
70 print 'static void retrace_%s(Trace::Call &call) {' % function.name
71 for arg_type, arg_name in function.args:
72 print ' %s %s;' % (arg_type, arg_name)
73 for arg_type, arg_name in function.args:
74 value = 'call.get_arg("%s")' % (arg_name,)
75 value = extract_value(arg_type, value)
76 print ' %s = static_cast<%s>(%s);' % (arg_name, arg_type, value)
77 arg_names = ", ".join([arg_name for arg_type, arg_name in function.args])
78 print ' %s(%s);' % (function.name, arg_names)
82 print 'static bool retrace_call(Trace::Call &call) {'
83 for function in functions:
84 print ' if (call.name == "%s") {' % function.name
85 print ' retrace_%s(call);' % function.name
88 print ' std::cerr << "Unsupported call " << call.name << "\\n";'
89 print ' return false;'
93 class Retracer : public Trace::Parser
95 void handle_call(Trace::Call &call) {
102 int main(int argc, char **argv)
104 glutInit(&argc, argv);
105 glutInitWindowPosition( 0, 0 );
106 glutInitWindowSize( 800, 600 );
107 glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE );
108 glutCreateWindow(argv[0]);
110 for (int i = 1; i < argc; ++i) {