]> git.cworth.org Git - apitrace/blob - apigen/gl_trace.py
Better directory name.
[apitrace] / apigen / gl_trace.py
1 #!/usr/bin/env 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 getopt
27 import os.path
28 import sys
29
30 glapi_path =  os.path.join(os.environ['MESA'], 'src/mapi/glapi/gen')
31 sys.path.insert(0, glapi_path)
32
33 import gl_XML
34 import license
35
36 type_map = {
37    'void': 'Void',
38    'int': 'Int',
39    'float': 'Float',
40 }
41
42 def parse_type(tokens, count = 0):
43     if count:
44         if tokens[-1] == '**':
45             return 'Array(Pointer(%s), "%s")' % (parse_type(tokens[:-1]), count)
46         if tokens[-1] == '*':
47             return 'Array(%s, "%s")' % (parse_type(tokens[:-1]), count)
48     else:
49         if tokens[-1] == '**':
50             return 'Pointer(Pointer(%s))' % parse_type(tokens[:-1])
51         if tokens[-1] == '*':
52             return 'Pointer(%s)' % parse_type(tokens[:-1])
53     if tokens[-1] == 'const':
54         return 'Const(%s)' % parse_type(tokens[:-1])
55     if tokens[0] == 'const':
56         return 'Const(%s)' % parse_type(tokens[1:])
57     assert len(tokens) == 1
58     base = tokens[0]
59     return type_map.get(base, base)
60
61 def get_type(t, count = 0):
62     tokens = t.split()
63
64     return parse_type(tokens, count)
65
66
67 class PrintGlTable(gl_XML.gl_print_base):
68     def __init__(self):
69         gl_XML.gl_print_base.__init__(self)
70
71         #self.header_tag = '_GLAPI_TABLE_H_'
72         self.name = "gl_trace.py (from Mesa)"
73         self.license = license.bsd_license_template % ( \
74 """Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
75 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
76         return
77
78     def printBody(self, api):
79         abi = [ "1.0", "1.1", "1.2", "1.5", "GL_ARB_multitexture" ]
80         for pass_ in range(2):
81             for f in api.functionIterateByOffset():
82                 for name in f.entry_points:
83                     [category, num] = api.get_category_for_name( name )
84                     args = []
85                     for p in f.parameters:
86                         type = get_type(p.type_string(), p.count)
87                         args.append('(%s, "%s")' % (type, p.name))
88                     arg_string = '[' + ', '.join(args) + ']'
89                     if category in abi:
90                         if pass_ == 0:
91                             print '    GlFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string)
92                     else:
93                         if pass_ == 1:
94                             print '    GlFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string)
95
96     def printRealHeader(self):
97         return
98
99     def printRealFooter(self):
100         print ']'
101
102
103 def show_usage():
104     print "Usage: %s [-f input_file_name]" % sys.argv[0]
105     sys.exit(1)
106
107
108 if __name__ == '__main__':
109     file_name = os.path.join(glapi_path, "gl_API.xml")
110
111     try:
112         (args, trail) = getopt.getopt(sys.argv[1:], "f:")
113     except Exception,e:
114         show_usage()
115
116     for (arg,val) in args:
117         if arg == "-f":
118             file_name = val
119
120     printer = PrintGlTable()
121
122     api = gl_XML.parse_GL_API( file_name )
123
124     printer.Print( api )