3 # Copyright 2008 VMware, Inc.
4 # Copyright 2004 IBM Corporation
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:
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
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
36 def parse_type(tokens, count = 0):
38 if tokens[-1] == '**':
39 return 'Array(Pointer(%s), "%s")' % (parse_type(tokens[:-1]), count)
41 return 'Array(%s, "%s")' % (parse_type(tokens[:-1]), count)
43 if tokens[-1] == '**':
44 return 'Pointer(Pointer(%s))' % parse_type(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
53 return type_map.get(base, base)
55 def get_type(t, count = 0):
58 return parse_type(tokens, count)
61 class PrintGlTable(gl_XML.gl_print_base):
63 gl_XML.gl_print_base.__init__(self)
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")
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 )
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) + ']'
85 print ' DllFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string)
88 print ' WglFunction(%s, "gl%s", %s),' % (get_type(f.return_type), name, arg_string)
90 def printRealHeader(self):
93 def printRealFooter(self):
98 print "Usage: %s [-f input_file_name]" % sys.argv[0]
101 if __name__ == '__main__':
102 file_name = "gl_API.xml"
105 (args, trail) = getopt.getopt(sys.argv[1:], "f:")
109 for (arg,val) in args:
113 printer = PrintGlTable()
115 api = gl_XML.parse_GL_API( file_name )