]> git.cworth.org Git - apitrace/blob - helpers/glsize.py
Remove dead code.
[apitrace] / helpers / glsize.py
1 #!/usr/bin/env python
2
3 # Copyright 2010 VMware, Inc.
4 # Copyright 2004, 2005 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 # Authors:
27 #    Jose Fonseca <jfonseca@vmware.com>
28 #    Ian Romanick <idr@us.ibm.com>
29
30 import os.path
31 import sys
32
33 glapi_path =  os.path.join(os.environ['MESA'], 'src/mapi/glapi/gen')
34 sys.path.insert(0, glapi_path)
35
36 import gl_XML, glX_XML
37 import license
38 import getopt, copy, string
39
40
41 class glx_enum_function:
42     def __init__(self, func_name, enum_dict):
43         self.name = func_name
44         self.mode = 1
45         self.sig = None
46
47         # "enums" is a set of lists.  The element in the set is the
48         # value of the enum.  The list is the list of names for that
49         # value.  For example, [0x8126] = {"POINT_SIZE_MIN",
50         # "POINT_SIZE_MIN_ARB", "POINT_SIZE_MIN_EXT",
51         # "POINT_SIZE_MIN_SGIS"}.
52
53         self.enums = {}
54
55         # "count" is indexed by count values.  Each element of count
56         # is a list of index to "enums" that have that number of
57         # associated data elements.  For example, [4] = 
58         # {GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION,
59         # GL_AMBIENT_AND_DIFFUSE} (the enum names are used here,
60         # but the actual hexadecimal values would be in the array).
61
62         self.count = {}
63
64
65         # Fill self.count and self.enums using the dictionary of enums
66         # that was passed in.  The generic Get functions (e.g.,
67         # GetBooleanv and friends) are handled specially here.  In
68         # the data the generic Get functions are refered to as "Get".
69
70         if func_name in ["GetIntegerv", "GetBooleanv", "GetFloatv", "GetDoublev"]:
71             match_name = "Get"
72         else:
73             match_name = func_name
74
75         mode_set = 0
76         for enum_name in enum_dict:
77             e = enum_dict[ enum_name ]
78
79             if e.functions.has_key( match_name ):
80                 [count, mode] = e.functions[ match_name ]
81
82                 if mode_set and mode != self.mode:
83                     raise RuntimeError("Not all enums for %s have the same mode." % (func_name))
84
85                 self.mode = mode
86
87                 if self.enums.has_key( e.value ):
88                     if e.name not in self.enums[ e.value ]:
89                         self.enums[ e.value ].append( e )
90                 else:
91                     if not self.count.has_key( count ):
92                         self.count[ count ] = []
93
94                     self.enums[ e.value ] = [ e ]
95                     self.count[ count ].append( e.value )
96
97
98         return
99
100
101     def signature( self ):
102         if self.sig == None:
103             self.sig = ""
104             for i in self.count:
105                 if i == None:
106                     raise RuntimeError("i is None.  WTF?")
107
108                 self.count[i].sort()
109                 for e in self.count[i]:
110                     self.sig += "%04x,%d," % (e, i)
111
112         return self.sig
113
114
115     def PrintUsingSwitch(self, name):
116         """Emit the body of the __gl*_size function using a 
117         switch-statement."""
118
119         print '    switch (pname) {'
120
121         for c in self.count:
122             for e in self.count[c]:
123                 first = 1
124
125                 # There may be multiple enums with the same
126                 # value.  This happens has extensions are
127                 # promoted from vendor-specific or EXT to
128                 # ARB and to the core.  Emit the first one as
129                 # a case label, and emit the others as
130                 # commented-out case labels.
131
132                 list = {}
133                 for enum_obj in self.enums[e]:
134                     list[ enum_obj.priority() ] = enum_obj.name
135
136                 keys = list.keys()
137                 keys.sort()
138                 for k in keys:
139                     j = list[k]
140                     if first:
141                         print '    case GL_%s:' % (j)
142                         first = 0
143                     else:
144                         print '/*  case GL_%s:*/' % (j)
145                     
146             if c == -1:
147                 print '        return __gl%s_variable_size(pname);' % (name)
148             else:
149                 print '        return %u;' % (c)
150                     
151         print '    default:' 
152         print '        assert(0);' 
153         print '        return 1;'
154         print '    }'
155
156
157     def Print(self, name):
158         print 'static inline size_t'
159         print '__gl%s_size(GLenum pname)' % (name)
160         print '{'
161
162         self.PrintUsingSwitch(name)
163
164         print '}'
165         print ''
166
167
168 class glx_server_enum_function(glx_enum_function):
169     def __init__(self, func, enum_dict):
170         glx_enum_function.__init__(self, func.name, enum_dict)
171         
172         self.function = func
173         return
174
175
176     def signature( self ):
177         if self.sig == None:
178             sig = glx_enum_function.signature(self)
179
180             p = self.function.variable_length_parameter()
181             if p:
182                 sig += "%u" % (p.size())
183
184             self.sig = sig
185
186         return self.sig;
187
188
189     def Print(self, name, printer):
190         f = self.function
191         printer.common_func_print_just_header( f )
192
193         fixup = []
194         
195         foo = {}
196         for param_name in f.count_parameter_list:
197             o = f.offset_of( param_name )
198             foo[o] = param_name
199
200         for param_name in f.counter_list:
201             o = f.offset_of( param_name )
202             foo[o] = param_name
203
204         keys = foo.keys()
205         keys.sort()
206         for o in keys:
207             p = f.parameters_by_name[ foo[o] ]
208
209             printer.common_emit_one_arg(p, "pc", 0)
210             fixup.append( p.name )
211
212
213         print '    GLsizei compsize;'
214         print ''
215
216         printer.common_emit_fixups(fixup)
217
218         print ''
219         print '    compsize = __gl%s_size(%s);' % (f.name, string.join(f.count_parameter_list, ","))
220         p = f.variable_length_parameter()
221         print '    return __GLX_PAD(%s);' % (p.size_string())
222
223         print '}'
224         print ''
225
226
227 class PrintGlxSizeStubs_c(gl_XML.gl_print_base):
228
229     def __init__(self):
230         gl_XML.gl_print_base.__init__(self)
231
232         self.name = "glX_proto_size.py (from Mesa)"
233         self.license = license.bsd_license_template % ( "Copyright 2010 VMware, Inc.\nCopyright 2004 IBM Corporation", "AUTHORS")
234
235     def printRealHeader(self):
236         print
237         print
238         print '#include <cassert>'
239         print
240         print '#include "glimports.hpp"'
241         print
242         print
243
244     def printBody(self, api):
245         enum_sigs = {}
246
247         for func in api.functionIterateByOffset():
248             ef = glx_enum_function( func.name, api.enums_by_name )
249             if len(ef.enums) == 0:
250                 continue
251
252             if True:
253                 sig = ef.signature()
254                 if enum_sigs.has_key( sig ):
255                     alias_name, real_name = func.name, enum_sigs[ sig ]
256                     print '#define __gl%s_size __gl%s_size' % (alias_name, real_name)
257                     print
258                 else:
259                     enum_sigs[ sig ] = func.name
260                     ef.Print( func.name )
261
262
263 def show_usage():
264     print "Usage: %s [-f input_file_name] [--only-get | --only-set] [--get-alias-set]" % sys.argv[0]
265     sys.exit(1)
266
267
268 if __name__ == '__main__':
269     file_name = os.path.join(glapi_path, "gl_API.xml")
270
271     try:
272         (args, trail) = getopt.getopt(sys.argv[1:], "f:h:", ["header-tag"])
273     except Exception,e:
274         show_usage()
275
276     header_tag = None
277
278     for (arg,val) in args:
279         if arg == "-f":
280             file_name = val
281         elif (arg == '-h') or (arg == "--header-tag"):
282             header_tag = val
283
284     printer = PrintGlxSizeStubs_c()
285
286     api = gl_XML.parse_GL_API( file_name, glX_XML.glx_item_factory() )
287
288
289     printer.Print( api )