]> git.cworth.org Git - apitrace/blob - gl_trace.py
Build D3D wrappers with CMake.
[apitrace] / gl_trace.py
1 #!/usr/bin/python
2
3 # Copyright 2008 VMware, Inc.
4 # Copyright 2004 IBM Corporation
5 # All Rights Reserved.
6 #
7 # Permission is hereby granted, free of charge, to any person obtaining a
8 # copy of this software and associated documentation files (the "Software"),
9 # to deal in the Software without restriction, including without limitation
10 # on the rights to use, copy, modify, merge, publish, distribute, sub
11 # license, and/or sell copies of the Software, and to permit persons to whom
12 # the Software is furnished to do so, subject to the following conditions:
13 #
14 # The above copyright notice and this permission notice (including the next
15 # paragraph) shall be included in all copies or substantial portions of the
16 # Software.
17 #
18 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
21 # THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 # IN THE SOFTWARE.
25
26 import gl_XML
27 import license
28 import sys, getopt
29
30 type_map = {
31    'void': 'Void',
32    'int': 'Int',
33    'float': 'Float',
34 }
35
36 def parse_type(tokens, count = 0):
37     if count:
38         if tokens[-1] == '**':
39             return 'Array(Pointer(%s), "%s")' % (parse_type(tokens[:-1]), count)
40         if tokens[-1] == '*':
41             return 'Array(%s, "%s")' % (parse_type(tokens[:-1]), count)
42     else:
43         if tokens[-1] == '**':
44             return 'Pointer(Pointer(%s))' % parse_type(tokens[:-1])
45         if tokens[-1] == '*':
46             return 'Pointer(%s)' % parse_type(tokens[:-1])
47     if tokens[-1] == 'const':
48         return 'Const(%s)' % parse_type(tokens[:-1])
49     if tokens[0] == 'const':
50         return 'Const(%s)' % parse_type(tokens[1:])
51     assert len(tokens) == 1
52     base = tokens[0]
53     return type_map.get(base, base)
54
55 def get_type(t, count = 0):
56     tokens = t.split()
57
58     return parse_type(tokens, count)
59
60
61 class PrintGlTable(gl_XML.gl_print_base):
62     def __init__(self):
63         gl_XML.gl_print_base.__init__(self)
64
65         #self.header_tag = '_GLAPI_TABLE_H_'
66         self.name = "gl_trace.py (from Mesa)"
67         self.license = license.bsd_license_template % ( \
68 """Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
69 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
70         return
71
72     def printBody(self, api):
73         abi = [ "1.0", "1.1", "1.2", "1.5", "GL_ARB_multitexture" ]
74         for pass_ in range(2):
75             for f in api.functionIterateByOffset():
76                 for name in f.entry_points:
77                     [category, num] = api.get_category_for_name( name )
78                     args = []
79                     for p in f.parameters:
80                         type = get_type(p.type_string(), p.count)
81                         args.append('(%s, "%s")' % (type, p.name))
82                     arg_string = '[' + ', '.join(args) + ']'
83                     if category in abi:
84                         if pass_ == 0:
85                             print '    DllFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string)
86                     else:
87                         if pass_ == 1:
88                             print '    WglFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string)
89
90     def printRealHeader(self):
91         return
92
93     def printRealFooter(self):
94         print ']'
95
96
97 def show_usage():
98     print "Usage: %s [-f input_file_name]" % sys.argv[0]
99     sys.exit(1)
100
101 if __name__ == '__main__':
102     file_name = "gl_API.xml"
103     
104     try:
105         (args, trail) = getopt.getopt(sys.argv[1:], "f:")
106     except Exception,e:
107         show_usage()
108
109     for (arg,val) in args:
110         if arg == "-f":
111             file_name = val
112
113     printer = PrintGlTable()
114
115     api = gl_XML.parse_GL_API( file_name )
116
117     printer.Print( api )