add debugging for compresssed textures
[mesa.git] / src / mesa / glapi / gl_procs.py
1 #!/usr/bin/python2
2
3 # (C) Copyright IBM Corporation 2004
4 # All Rights Reserved.
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # on the rights to use, copy, modify, merge, publish, distribute, sub
10 # license, and/or sell copies of the Software, and to permit persons to whom
11 # the Software is furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice (including the next
14 # paragraph) shall be included in all copies or substantial portions of the
15 # Software.
16 #
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 # IN THE SOFTWARE.
24 #
25 # Authors:
26 # Ian Romanick <idr@us.ibm.com>
27
28 from xml.sax import saxutils
29 from xml.sax import make_parser
30 from xml.sax.handler import feature_namespaces
31
32 import license
33 import gl_XML
34 import sys, getopt
35
36 class PrintGlProcs(gl_XML.FilterGLAPISpecBase):
37 name = "gl_procs.py (from Mesa)"
38
39 def __init__(self, long_strings):
40 self.long_strings = long_strings
41 gl_XML.FilterGLAPISpecBase.__init__(self)
42 self.license = license.bsd_license_template % ( \
43 """Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
44 (C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM")
45
46
47 def printRealHeader(self):
48 print '/* This file is only included by glapi.c and is used for'
49 print ' * the GetProcAddress() function'
50 print ' */'
51 print ''
52 print 'typedef struct {'
53 print ' int Name_offset;'
54 print '#ifdef NEED_FUNCTION_POINTER'
55 print ' void * Address;'
56 print '#endif'
57 print ' unsigned int Offset;'
58 print '} glprocs_table_t;'
59 print ''
60 print '#ifdef NEED_FUNCTION_POINTER'
61 print '# define NAME_FUNC_OFFSET(n,f,o) { n , (void *) f , o }'
62 print '#else'
63 print '# define NAME_FUNC_OFFSET(n,f,o) { n , o }'
64 print '#endif'
65 print ''
66 return
67
68 def printRealFooter(self):
69 print ''
70 print '#undef NAME_FUNC_OFFSET'
71 return
72
73 def printFunctionString(self, f):
74 if self.long_strings:
75 print ' "gl%s\\0"' % (f.name)
76 else:
77 print " 'g','l',",
78 for c in f.name:
79 print "'%s'," % (c),
80
81 print "'\\0',"
82
83 def printFunctionOffset(self, f, offset_of_name):
84 print ' NAME_FUNC_OFFSET( % 5u, gl%s, _gloffset_%s ),' % (offset_of_name, f.name, f.real_name)
85
86
87 def printFunctions(self):
88 print ''
89 if self.long_strings:
90 print 'static const char gl_string_table[] ='
91 else:
92 print 'static const char gl_string_table[] = {'
93
94 keys = self.functions.keys()
95 keys.sort()
96 for k in keys:
97 if k < 0: continue
98 self.printFunctionString(self.functions[k])
99
100 keys.reverse()
101 for k in keys:
102 if k >= -1: continue
103 self.printFunctionString(self.functions[k])
104
105 if self.long_strings:
106 print ' ;'
107 else:
108 print '};'
109
110 print ''
111 print 'static const glprocs_table_t static_functions[] = {'
112
113 keys = self.functions.keys()
114 keys.sort()
115 base_offset = 0
116 for k in keys:
117 if k < 0: continue
118 self.printFunctionOffset(self.functions[k], base_offset)
119
120 # The length of the function's name, plus 2 for "gl",
121 # plus 1 for the NUL.
122
123 base_offset += len(self.functions[k].name) + 3
124
125 keys.reverse()
126 for k in keys:
127 if k >= -1: continue
128 self.printFunctionOffset(self.functions[k], base_offset)
129
130 # The length of the function's name, plus 2 for "gl",
131 # plus 1 for the NUL.
132
133 base_offset += len(self.functions[k].name) + 3
134
135 print ' NAME_FUNC_OFFSET( -1, NULL, -1 )'
136 print '};'
137 return
138
139
140 def show_usage():
141 print "Usage: %s [-f input_file_name] [-m mode]" % sys.argv[0]
142 print "mode can be one of:"
143 print " long - Create code for compilers that can handle very "
144 print " long string constants. (default)"
145 print " short - Create code for compilers that can only handle "
146 print " ANSI C89 string constants."
147 sys.exit(1)
148
149 if __name__ == '__main__':
150 file_name = "gl_API.xml"
151
152 try:
153 (args, trail) = getopt.getopt(sys.argv[1:], "f:m:")
154 except Exception,e:
155 show_usage()
156
157 long_string = 1
158 for (arg,val) in args:
159 if arg == "-f":
160 file_name = val
161 elif arg == "-m":
162 if val == "short":
163 long_string = 0
164 elif val == "long":
165 long_string = 1
166 else:
167 show_usage()
168
169 dh = PrintGlProcs( long_string )
170
171 parser = make_parser()
172 parser.setFeature(feature_namespaces, 0)
173 parser.setContentHandler(dh)
174
175 f = open(file_name)
176
177 dh.printHeader()
178 parser.parse(f)
179 dh.printFooter()