]> git.cworth.org Git - apitrace/blob - glretrace.py
Remove unused functions.
[apitrace] / glretrace.py
1 ##########################################################################
2 #
3 # Copyright 2010 VMware, Inc.
4 # All Rights Reserved.
5 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
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
22 # THE SOFTWARE.
23 #
24 ##########################################################################/
25
26
27 import base
28 from glx import libgl
29
30
31 class ValueExtractor(base.Visitor):
32
33     def visit_literal(self, type, lvalue, rvalue):
34         #print '    %s = static_cast<%s>(Trace::as%s(%s));' % (lvalue, type, type.format, rvalue)
35         print '    %s = Trace::as%s(%s);' % (lvalue, type.format, rvalue)
36
37     def visit_alias(self, type, lvalue, rvalue):
38         self.visit(type.type, lvalue, rvalue)
39     
40     def visit_enum(self, type, lvalue, rvalue):
41         #print '    %s = static_cast<%s>(Trace::as%s(%s));' % (lvalue, type, 'SInt', rvalue)
42         print '    %s = Trace::as%s(%s);' % (lvalue, 'SInt', rvalue)
43
44     def visit_bitmask(self, type, lvalue, rvalue):
45         self.visit(type.type, lvalue, rvalue)
46
47
48
49 def retrace_function(function):
50     print 'static void retrace_%s(Trace::Call &call) {' % function.name
51     if not function.name.startswith('glX'):
52         success = True
53         for arg_type, arg_name in function.args:
54             print '    %s %s;' % (arg_type, arg_name)
55         for arg_type, arg_name in function.args:
56             rvalue = 'call.arg("%s")' % (arg_name,)
57             lvalue = arg_name
58             try:
59                 ValueExtractor().visit(arg_type, lvalue, rvalue)
60             except NotImplementedError:
61                 success = False
62                 print '    %s = 0; // FIXME' % arg_name
63         if not success:
64             print '    std::cerr << "warning: unsupported call %s\\n";' % function.name
65             print '    return;'
66         arg_names = ", ".join([arg_name for arg_type, arg_name in function.args])
67         print '    %s(%s);' % (function.name, arg_names)
68     print '}'
69     print
70
71
72 if __name__ == '__main__':
73     print
74     print '#include <stdlib.h>'
75     print '#include <string.h>'
76     print '#include <GL/glew.h>'
77     print '#include <GL/glut.h>'
78     print
79     print '#include "trace_parser.hpp"'
80     print
81
82     for function in libgl.functions:
83         retrace_function(function)
84
85     print 'static bool retrace_call(Trace::Call &call) {'
86     for function in libgl.functions:
87         print '    if (call.name == "%s") {' % function.name
88         print '        retrace_%s(call);' % function.name
89         print '        return true;'
90         print '    }'
91     print '    std::cerr << "warning: unsupported call " << call.name << "\\n";'
92     print '    return false;'
93     print '}'
94     print '''
95
96 class Retracer : public Trace::Parser
97 {
98     void handle_call(Trace::Call &call) {
99         std::cout << call;
100         std::cout.flush();
101         retrace_call(call);
102     }
103 };
104
105 int main(int argc, char **argv)
106 {
107    glutInit(&argc, argv);
108    glutInitWindowPosition( 0, 0 );
109    glutInitWindowSize( 800, 600 );
110    glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE );
111    glutCreateWindow(argv[0]);
112    glewInit();
113    for (int i = 1; i < argc; ++i) {
114       Retracer p;
115       p.parse(argv[i]);
116       glutMainLoop();
117    }
118    return 0;
119 }
120
121 '''