mesa/es: Remove unused code in es_generator.py.
[mesa.git] / src / mesa / es / main / es_generator.py
1 #*************************************************************************
2 # Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
3 # All Rights Reserved.
4 #
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
11 #
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
14 #
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # TUNGSTEN GRAPHICS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
20 # OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
22 #*************************************************************************
23
24
25 import sys, os
26 import APIspecutil as apiutil
27
28 # These dictionary entries are used for automatic conversion.
29 # The string will be used as a format string with the conversion
30 # variable.
31 Converters = {
32 'GLfloat': {
33 'GLdouble': "(GLdouble) (%s)",
34 'GLfixed' : "(GLint) (%s * 65536)",
35 },
36 'GLfixed': {
37 'GLfloat': "(GLfloat) (%s / 65536.0f)",
38 'GLdouble': "(GLdouble) (%s / 65536.0)",
39 },
40 'GLdouble': {
41 'GLfloat': "(GLfloat) (%s)",
42 'GLfixed': "(GLfixed) (%s * 65536)",
43 },
44 'GLclampf': {
45 'GLclampd': "(GLclampd) (%s)",
46 'GLclampx': "(GLclampx) (%s * 65536)",
47 },
48 'GLclampx': {
49 'GLclampf': "(GLclampf) (%s / 65536.0f)",
50 'GLclampd': "(GLclampd) (%s / 65536.0)",
51 },
52 'GLubyte': {
53 'GLfloat': "(GLfloat) (%s / 255.0f)",
54 },
55 }
56
57 def GetBaseType(type):
58 typeTokens = type.split(' ')
59 baseType = None
60 typeModifiers = []
61 for t in typeTokens:
62 if t in ['const', '*']:
63 typeModifiers.append(t)
64 else:
65 baseType = t
66 return (baseType, typeModifiers)
67
68 def ConvertValue(value, fromType, toType):
69 """Returns a string that represents the given parameter string,
70 type-converted if necessary."""
71
72 if not Converters.has_key(fromType):
73 print >> sys.stderr, "No base converter for type '%s' found. Ignoring." % fromType
74 return value
75
76 if not Converters[fromType].has_key(toType):
77 print >> sys.stderr, "No converter found for type '%s' to type '%s'. Ignoring." % (fromType, toType)
78 return value
79
80 # This part is simple. Return the proper conversion.
81 conversionString = Converters[fromType][toType]
82 return conversionString % value
83
84 FormatStrings = {
85 'GLenum' : '0x%x',
86 'GLfloat' : '%f',
87 'GLint' : '%d',
88 'GLbitfield' : '0x%x',
89 }
90 def GetFormatString(type):
91 if FormatStrings.has_key(type):
92 return FormatStrings[type]
93 else:
94 return None
95
96
97 ######################################################################
98 # Version-specific values to be used in the main script
99 # header: which header file to include
100 # api: what text specifies an API-level function
101 VersionSpecificValues = {
102 'GLES1.1' : {
103 'description' : 'GLES1.1 functions',
104 'header' : 'GLES/gl.h',
105 'extheader' : 'GLES/glext.h',
106 },
107 'GLES2.0': {
108 'description' : 'GLES2.0 functions',
109 'header' : 'GLES2/gl2.h',
110 'extheader' : 'GLES2/gl2ext.h',
111 }
112 }
113
114
115 ######################################################################
116 # Main code for the script begins here.
117
118 # Get the name of the program (without the directory part) for use in
119 # error messages.
120 program = os.path.basename(sys.argv[0])
121
122 # Set default values
123 verbose = 0
124 functionList = "APIspec.xml"
125 version = "GLES1.1"
126
127 # Allow for command-line switches
128 import getopt, time
129 options = "hvV:S:"
130 try:
131 optlist, args = getopt.getopt(sys.argv[1:], options)
132 except getopt.GetoptError, message:
133 sys.stderr.write("%s: %s. Use -h for help.\n" % (program, message))
134 sys.exit(1)
135
136 for option, optarg in optlist:
137 if option == "-h":
138 sys.stderr.write("Usage: %s [-%s]\n" % (program, options))
139 sys.stderr.write("Parse an API specification file and generate wrapper functions for a given GLES version\n")
140 sys.stderr.write("-h gives help\n")
141 sys.stderr.write("-v is verbose\n")
142 sys.stderr.write("-V specifies GLES version to generate [%s]:\n" % version)
143 for key in VersionSpecificValues.keys():
144 sys.stderr.write(" %s - %s\n" % (key, VersionSpecificValues[key]['description']))
145 sys.stderr.write("-S specifies API specification file to use [%s]\n" % functionList)
146 sys.exit(1)
147 elif option == "-v":
148 verbose += 1
149 elif option == "-V":
150 version = optarg
151 elif option == "-S":
152 functionList = optarg
153
154 # Beyond switches, we support no further command-line arguments
155 if len(args) > 0:
156 sys.stderr.write("%s: only switch arguments are supported - use -h for help\n" % program)
157 sys.exit(1)
158
159 # If we don't have a valid version, abort.
160 if not VersionSpecificValues.has_key(version):
161 sys.stderr.write("%s: version '%s' is not valid - use -h for help\n" % (program, version))
162 sys.exit(1)
163
164 # Grab the version-specific items we need to use
165 versionHeader = VersionSpecificValues[version]['header']
166 versionExtHeader = VersionSpecificValues[version]['extheader']
167
168 # If we get to here, we're good to go. The "version" parameter
169 # directs GetDispatchedFunctions to only allow functions from
170 # that "category" (version in our parlance). This allows
171 # functions with different declarations in different categories
172 # to exist (glTexImage2D, for example, is different between
173 # GLES1 and GLES2).
174 keys = apiutil.GetAllFunctions(functionList, version)
175
176 allSpecials = apiutil.AllSpecials()
177
178 print """/* DO NOT EDIT *************************************************
179 * THIS FILE AUTOMATICALLY GENERATED BY THE %s SCRIPT
180 * API specification file: %s
181 * GLES version: %s
182 * date: %s
183 */
184 """ % (program, functionList, version, time.strftime("%Y-%m-%d %H:%M:%S"))
185
186 # The headers we choose are version-specific.
187 print """
188 #include "%s"
189 #include "%s"
190 """ % (versionHeader, versionExtHeader)
191
192 # Everyone needs these types.
193 print """
194 /* These types are needed for the Mesa veneer, but are not defined in
195 * the standard GLES headers.
196 */
197 typedef double GLdouble;
198 typedef double GLclampd;
199
200 /* This type is normally in glext.h, but needed here */
201 typedef char GLchar;
202
203 /* Mesa error handling requires these */
204 extern void *_mesa_get_current_context(void);
205 extern void _mesa_error(void *ctx, GLenum error, const char *fmtString, ... );
206
207 #include "main/compiler.h"
208 #include "main/api_exec.h"
209
210 #include "glapi/dispatch.h"
211
212 typedef void (*_glapi_proc)(void); /* generic function pointer */
213 """
214
215 # Finally we get to the all-important functions
216 print """/*************************************************************
217 * Generated functions begin here
218 */
219 """
220 for funcName in keys:
221 if verbose > 0: sys.stderr.write("%s: processing function %s\n" % (program, funcName))
222
223 # start figuring out what this function will look like.
224 returnType = apiutil.ReturnType(funcName)
225 props = apiutil.Properties(funcName)
226 params = apiutil.Parameters(funcName)
227 declarationString = apiutil.MakeDeclarationString(params)
228
229 # In case of error, a function may have to return. Make
230 # sure we have valid return values in this case.
231 if returnType == "void":
232 errorReturn = "return"
233 elif returnType == "GLboolean":
234 errorReturn = "return GL_FALSE"
235 else:
236 errorReturn = "return (%s) 0" % returnType
237
238 # These are the output of this large calculation block.
239 # passthroughDeclarationString: a typed set of parameters that
240 # will be used to create the "extern" reference for the
241 # underlying Mesa or support function. Note that as generated
242 # these have an extra ", " at the beginning, which will be
243 # removed before use.
244 #
245 # passthroughDeclarationString: an untyped list of parameters
246 # that will be used to call the underlying Mesa or support
247 # function (including references to converted parameters).
248 # This will also be generated with an extra ", " at the
249 # beginning, which will be removed before use.
250 #
251 # variables: C code to create any local variables determined to
252 # be necessary.
253 # conversionCodeOutgoing: C code to convert application parameters
254 # to a necessary type before calling the underlying support code.
255 # May be empty if no conversion is required.
256 # conversionCodeIncoming: C code to do the converse: convert
257 # values returned by underlying Mesa code to the types needed
258 # by the application.
259 # Note that *either* the conversionCodeIncoming will be used (for
260 # generated query functions), *or* the conversionCodeOutgoing will
261 # be used (for generated non-query functions), never both.
262 passthroughFuncName = ""
263 passthroughDeclarationString = ""
264 passthroughCallString = ""
265 variables = []
266 conversionCodeOutgoing = []
267 conversionCodeIncoming = []
268 switchCode = []
269
270 # Calculate the name of the underlying support function to call.
271 # By default, the passthrough function is named _mesa_<funcName>.
272 # We're allowed to override the prefix and/or the function name
273 # for each function record, though. The "ConversionFunction"
274 # utility is poorly named, BTW...
275 aliasprefix = apiutil.AliasPrefix(funcName)
276 alias = apiutil.ConversionFunction(funcName)
277 if not alias:
278 # There may still be a Mesa alias for the function
279 if apiutil.Alias(funcName):
280 passthroughFuncName = "%s%s" % (aliasprefix, apiutil.Alias(funcName))
281 else:
282 passthroughFuncName = "%s%s" % (aliasprefix, funcName)
283 else: # a specific alias is provided
284 passthroughFuncName = "%s%s" % (aliasprefix, alias)
285
286 # Look at every parameter: each one may have only specific
287 # allowed values, or dependent parameters to check, or
288 # variant-sized vector arrays to calculate
289 for (paramName, paramType, paramMaxVecSize, paramConvertToType, paramValidValues, paramValueConversion) in params:
290 # We'll need this below if we're doing conversions
291 (paramBaseType, paramTypeModifiers) = GetBaseType(paramType)
292
293 # Conversion management.
294 # We'll handle three cases, easiest to hardest: a parameter
295 # that doesn't require conversion, a scalar parameter that
296 # requires conversion, and a vector parameter that requires
297 # conversion.
298 if paramConvertToType == None:
299 # Unconverted parameters are easy, whether they're vector
300 # or scalar - just add them to the call list. No conversions
301 # or anything to worry about.
302 passthroughDeclarationString += ", %s %s" % (paramType, paramName)
303 passthroughCallString += ", %s" % paramName
304
305 elif paramMaxVecSize == 0: # a scalar parameter that needs conversion
306 # A scalar to hold a converted parameter
307 variables.append(" %s converted_%s;" % (paramConvertToType, paramName))
308
309 # Outgoing conversion depends on whether we have to conditionally
310 # perform value conversion.
311 if paramValueConversion == "none":
312 conversionCodeOutgoing.append(" converted_%s = (%s) %s;" % (paramName, paramConvertToType, paramName))
313 elif paramValueConversion == "some":
314 # We'll need a conditional variable to keep track of
315 # whether we're converting values or not.
316 if (" int convert_%s_value = 1;" % paramName) not in variables:
317 variables.append(" int convert_%s_value = 1;" % paramName)
318
319 # Write code based on that conditional.
320 conversionCodeOutgoing.append(" if (convert_%s_value) {" % paramName)
321 conversionCodeOutgoing.append(" converted_%s = %s;" % (paramName, ConvertValue(paramName, paramBaseType, paramConvertToType)))
322 conversionCodeOutgoing.append(" } else {")
323 conversionCodeOutgoing.append(" converted_%s = (%s) %s;" % (paramName, paramConvertToType, paramName))
324 conversionCodeOutgoing.append(" }")
325 else: # paramValueConversion == "all"
326 conversionCodeOutgoing.append(" converted_%s = %s;" % (paramName, ConvertValue(paramName, paramBaseType, paramConvertToType)))
327
328 # Note that there can be no incoming conversion for a
329 # scalar parameter; changing the scalar will only change
330 # the local value, and won't ultimately change anything
331 # that passes back to the application.
332
333 # Call strings. The unusual " ".join() call will join the
334 # array of parameter modifiers with spaces as separators.
335 passthroughDeclarationString += ", %s %s %s" % (paramConvertToType, " ".join(paramTypeModifiers), paramName)
336 passthroughCallString += ", converted_%s" % paramName
337
338 else: # a vector parameter that needs conversion
339 # We'll need an index variable for conversions
340 if " register unsigned int i;" not in variables:
341 variables.append(" register unsigned int i;")
342
343 # This variable will hold the (possibly variant) size of
344 # this array needing conversion. By default, we'll set
345 # it to the maximal size (which is correct for functions
346 # with a constant-sized vector parameter); for true
347 # variant arrays, we'll modify it with other code.
348 variables.append(" unsigned int n_%s = %d;" % (paramName, paramMaxVecSize))
349
350 # This array will hold the actual converted values.
351 variables.append(" %s converted_%s[%d];" % (paramConvertToType, paramName, paramMaxVecSize))
352
353 # Again, we choose the conversion code based on whether we
354 # have to always convert values, never convert values, or
355 # conditionally convert values.
356 if paramValueConversion == "none":
357 conversionCodeOutgoing.append(" for (i = 0; i < n_%s; i++) {" % paramName)
358 conversionCodeOutgoing.append(" converted_%s[i] = (%s) %s[i];" % (paramName, paramConvertToType, paramName))
359 conversionCodeOutgoing.append(" }")
360 elif paramValueConversion == "some":
361 # We'll need a conditional variable to keep track of
362 # whether we're converting values or not.
363 if (" int convert_%s_value = 1;" % paramName) not in variables:
364 variables.append(" int convert_%s_value = 1;" % paramName)
365 # Write code based on that conditional.
366 conversionCodeOutgoing.append(" if (convert_%s_value) {" % paramName)
367 conversionCodeOutgoing.append(" for (i = 0; i < n_%s; i++) {" % paramName)
368 conversionCodeOutgoing.append(" converted_%s[i] = %s;" % (paramName, ConvertValue("%s[i]" % paramName, paramBaseType, paramConvertToType)))
369 conversionCodeOutgoing.append(" }")
370 conversionCodeOutgoing.append(" } else {")
371 conversionCodeOutgoing.append(" for (i = 0; i < n_%s; i++) {" % paramName)
372 conversionCodeOutgoing.append(" converted_%s[i] = (%s) %s[i];" % (paramName, paramConvertToType, paramName))
373 conversionCodeOutgoing.append(" }")
374 conversionCodeOutgoing.append(" }")
375 else: # paramValueConversion == "all"
376 conversionCodeOutgoing.append(" for (i = 0; i < n_%s; i++) {" % paramName)
377 conversionCodeOutgoing.append(" converted_%s[i] = %s;" % (paramName, ConvertValue("%s[i]" % paramName, paramBaseType, paramConvertToType)))
378
379 conversionCodeOutgoing.append(" }")
380
381 # If instead we need an incoming conversion (i.e. results
382 # from Mesa have to be converted before handing back
383 # to the application), this is it. Fortunately, we don't
384 # have to worry about conditional value conversion - the
385 # functions that do (e.g. glGetFixedv()) are handled
386 # specially, outside this code generation.
387 #
388 # Whether we use incoming conversion or outgoing conversion
389 # is determined later - we only ever use one or the other.
390
391 if paramValueConversion == "none":
392 conversionCodeIncoming.append(" for (i = 0; i < n_%s; i++) {" % paramName)
393 conversionCodeIncoming.append(" %s[i] = (%s) converted_%s[i];" % (paramName, paramConvertToType, paramName))
394 conversionCodeIncoming.append(" }")
395 elif paramValueConversion == "some":
396 # We'll need a conditional variable to keep track of
397 # whether we're converting values or not.
398 if (" int convert_%s_value = 1;" % paramName) not in variables:
399 variables.append(" int convert_%s_value = 1;" % paramName)
400
401 # Write code based on that conditional.
402 conversionCodeIncoming.append(" if (convert_%s_value) {" % paramName)
403 conversionCodeIncoming.append(" for (i = 0; i < n_%s; i++) {" % paramName)
404 conversionCodeIncoming.append(" %s[i] = %s;" % (paramName, ConvertValue("converted_%s[i]" % paramName, paramConvertToType, paramBaseType)))
405 conversionCodeIncoming.append(" }")
406 conversionCodeIncoming.append(" } else {")
407 conversionCodeIncoming.append(" for (i = 0; i < n_%s; i++) {" % paramName)
408 conversionCodeIncoming.append(" %s[i] = (%s) converted_%s[i];" % (paramName, paramBaseType, paramName))
409 conversionCodeIncoming.append(" }")
410 conversionCodeIncoming.append(" }")
411 else: # paramValueConversion == "all"
412 conversionCodeIncoming.append(" for (i = 0; i < n_%s; i++) {" % paramName)
413 conversionCodeIncoming.append(" %s[i] = %s;" % (paramName, ConvertValue("converted_%s[i]" % paramName, paramConvertToType, paramBaseType)))
414 conversionCodeIncoming.append(" }")
415
416 # Call strings. The unusual " ".join() call will join the
417 # array of parameter modifiers with spaces as separators.
418 passthroughDeclarationString += ", %s %s %s" % (paramConvertToType, " ".join(paramTypeModifiers), paramName)
419 passthroughCallString += ", converted_%s" % paramName
420
421 # endif conversion management
422
423 # Parameter checking. If the parameter has a specific list of
424 # valid values, we have to make sure that the passed-in values
425 # match these, or we make an error.
426 if len(paramValidValues) > 0:
427 # We're about to make a big switch statement with an
428 # error at the end. By default, the error is GL_INVALID_ENUM,
429 # unless we find a "case" statement in the middle with a
430 # non-GLenum value.
431 errorDefaultCase = "GL_INVALID_ENUM"
432
433 # This parameter has specific valid values. Make a big
434 # switch statement to handle it. Note that the original
435 # parameters are always what is checked, not the
436 # converted parameters.
437 switchCode.append(" switch(%s) {" % paramName)
438
439 for valueIndex in range(len(paramValidValues)):
440 (paramValue, dependentVecSize, dependentParamName, dependentValidValues, errorCode, valueConvert) = paramValidValues[valueIndex]
441
442 # We're going to need information on the dependent param
443 # as well.
444 if dependentParamName:
445 depParamIndex = apiutil.FindParamIndex(params, dependentParamName)
446 if depParamIndex == None:
447 sys.stderr.write("%s: can't find dependent param '%s' for function '%s'\n" % (program, dependentParamName, funcName))
448
449 (depParamName, depParamType, depParamMaxVecSize, depParamConvertToType, depParamValidValues, depParamValueConversion) = params[depParamIndex]
450 else:
451 (depParamName, depParamType, depParamMaxVecSize, depParamConvertToType, depParamValidValues, depParamValueConversion) = (None, None, None, None, [], None)
452
453 # This is a sneaky trick. It's valid syntax for a parameter
454 # that is *not* going to be converted to be declared
455 # with a dependent vector size; but in this case, the
456 # dependent vector size is unused and unnecessary.
457 # So check for this and ignore the dependent vector size
458 # if the parameter is not going to be converted.
459 if depParamConvertToType:
460 usedDependentVecSize = dependentVecSize
461 else:
462 usedDependentVecSize = None
463
464 # We'll peek ahead at the next parameter, to see whether
465 # we can combine cases
466 if valueIndex + 1 < len(paramValidValues) :
467 (nextParamValue, nextDependentVecSize, nextDependentParamName, nextDependentValidValues, nextErrorCode, nextValueConvert) = paramValidValues[valueIndex + 1]
468 if depParamConvertToType:
469 usedNextDependentVecSize = nextDependentVecSize
470 else:
471 usedNextDependentVecSize = None
472
473 # Create a case for this value. As a mnemonic,
474 # if we have a dependent vector size that we're ignoring,
475 # add it as a comment.
476 if usedDependentVecSize == None and dependentVecSize != None:
477 switchCode.append(" case %s: /* size %s */" % (paramValue, dependentVecSize))
478 else:
479 switchCode.append(" case %s:" % paramValue)
480
481 # If this is not a GLenum case, then switch our error
482 # if no value is matched to be GL_INVALID_VALUE instead
483 # of GL_INVALID_ENUM. (Yes, this does get confused
484 # if there are both values and GLenums in the same
485 # switch statement, which shouldn't happen.)
486 if paramValue[0:3] != "GL_":
487 errorDefaultCase = "GL_INVALID_VALUE"
488
489 # If all the remaining parameters are identical to the
490 # next set, then we're done - we'll just create the
491 # official code on the next pass through, and the two
492 # cases will share the code.
493 if valueIndex + 1 < len(paramValidValues) and usedDependentVecSize == usedNextDependentVecSize and dependentParamName == nextDependentParamName and dependentValidValues == nextDependentValidValues and errorCode == nextErrorCode and valueConvert == nextValueConvert:
494 continue
495
496 # Otherwise, we'll have to generate code for this case.
497 # Start off with a check: if there is a dependent parameter,
498 # and a list of valid values for that parameter, we need
499 # to generate an error if something other than one
500 # of those values is passed.
501 if len(dependentValidValues) > 0:
502 conditional=""
503
504 # If the parameter being checked is actually an array,
505 # check only its first element.
506 if depParamMaxVecSize == 0:
507 valueToCheck = dependentParamName
508 else:
509 valueToCheck = "%s[0]" % dependentParamName
510
511 for v in dependentValidValues:
512 conditional += " && %s != %s" % (valueToCheck, v)
513 switchCode.append(" if (%s) {" % conditional[4:])
514 if errorCode == None:
515 errorCode = "GL_INVALID_ENUM"
516 switchCode.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s=0x%s)", %s);' % (errorCode, funcName, paramName, "%x", paramName))
517 switchCode.append(" %s;" % errorReturn)
518 switchCode.append(" }")
519 # endif there are dependent valid values
520
521 # The dependent parameter may require conditional
522 # value conversion. If it does, and we don't want
523 # to convert values, we'll have to generate code for that
524 if depParamValueConversion == "some" and valueConvert == "noconvert":
525 switchCode.append(" convert_%s_value = 0;" % dependentParamName)
526
527 # If there's a dependent vector size for this parameter
528 # that we're actually going to use (i.e. we need conversion),
529 # mark it.
530 if usedDependentVecSize:
531 switchCode.append(" n_%s = %s;" % (dependentParamName, dependentVecSize))
532
533 # In all cases, break out of the switch if any valid
534 # value is found.
535 switchCode.append(" break;")
536
537
538 # Need a default case to catch all the other, invalid
539 # parameter values. These will all generate errors.
540 switchCode.append(" default:")
541 if errorCode == None:
542 errorCode = "GL_INVALID_ENUM"
543 formatString = GetFormatString(paramType)
544 if formatString == None:
545 switchCode.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s)");' % (errorCode, funcName, paramName))
546 else:
547 switchCode.append(' _mesa_error(_mesa_get_current_context(), %s, "gl%s(%s=%s)", %s);' % (errorCode, funcName, paramName, formatString, paramName))
548 switchCode.append(" %s;" % errorReturn)
549
550 # End of our switch code.
551 switchCode.append(" }")
552
553 # endfor every recognized parameter value
554
555 # endfor every param
556
557 # Here, the passthroughDeclarationString and passthroughCallString
558 # are complete; remove the extra ", " at the front of each.
559 passthroughDeclarationString = passthroughDeclarationString[2:]
560 passthroughCallString = passthroughCallString[2:]
561
562 # The Mesa functions are scattered across all the Mesa
563 # header files. The easiest way to manage declarations
564 # is to create them ourselves.
565 if funcName not in allSpecials:
566 print "extern %s GLAPIENTRY %s(%s);" % (returnType, passthroughFuncName, passthroughDeclarationString)
567
568 # A function may be a core function (i.e. it exists in
569 # the core specification), a core addition (extension
570 # functions added officially to the core), a required
571 # extension (usually an extension for an earlier version
572 # that has been officially adopted), or an optional extension.
573 #
574 # Core functions have a simple category (e.g. "GLES1.1");
575 # we generate only a simple callback for them.
576 #
577 # Core additions have two category listings, one simple
578 # and one compound (e.g. ["GLES1.1", "GLES1.1:OES_fixed_point"]).
579 # We generate the core function, and also an extension function.
580 #
581 # Required extensions and implemented optional extensions
582 # have a single compound category "GLES1.1:OES_point_size_array".
583 # For these we generate just the extension function.
584 for categorySpec in apiutil.Categories(funcName):
585 compoundCategory = categorySpec.split(":")
586
587 # This category isn't for us, if the base category doesn't match
588 # our version
589 if compoundCategory[0] != version:
590 continue
591
592 # Otherwise, determine if we're writing code for a core
593 # function (no suffix) or an extension function.
594 if len(compoundCategory) == 1:
595 # This is a core function
596 extensionName = None
597 fullFuncName = "_es_" + funcName
598 else:
599 # This is an extension function. We'll need to append
600 # the extension suffix.
601 extensionName = compoundCategory[1]
602 extensionSuffix = extensionName.split("_")[0]
603 fullFuncName = "_es_" + funcName + extensionSuffix
604
605 # Now the generated function. The text used to mark an API-level
606 # function, oddly, is version-specific.
607 if extensionName:
608 print "/* Extension %s */" % extensionName
609
610 if funcName in allSpecials:
611 print "/* this function is special and is defined elsewhere */"
612 print "extern %s %s(%s);" % (returnType, fullFuncName, declarationString)
613 print
614 continue
615
616 print "static %s %s(%s)" % (returnType, fullFuncName, declarationString)
617 print "{"
618
619 # Start printing our code pieces. Start with any local
620 # variables we need. This unusual syntax joins the
621 # lines in the variables[] array with the "\n" separator.
622 if len(variables) > 0:
623 print "\n".join(variables) + "\n"
624
625 # If there's any sort of parameter checking or variable
626 # array sizing, the switch code will contain it.
627 if len(switchCode) > 0:
628 print "\n".join(switchCode) + "\n"
629
630 # In the case of an outgoing conversion (i.e. parameters must
631 # be converted before calling the underlying Mesa function),
632 # use the appropriate code.
633 if "get" not in props and len(conversionCodeOutgoing) > 0:
634 print "\n".join(conversionCodeOutgoing) + "\n"
635
636 # Call the Mesa function. Note that there are very few functions
637 # that return a value (i.e. returnType is not "void"), and that
638 # none of them require incoming translation; so we're safe
639 # to generate code that directly returns in those cases,
640 # even though it's not completely independent.
641
642 if returnType == "void":
643 print " %s(%s);" % (passthroughFuncName, passthroughCallString)
644 else:
645 print " return %s(%s);" % (passthroughFuncName, passthroughCallString)
646
647 # If the function is one that returns values (i.e. "get" in props),
648 # it might return values of a different type than we need, that
649 # require conversion before passing back to the application.
650 if "get" in props and len(conversionCodeIncoming) > 0:
651 print "\n".join(conversionCodeIncoming)
652
653 # All done.
654 print "}"
655 print
656 # end for each category provided for a function
657
658 # end for each function
659
660 print "void"
661 print "_mesa_init_exec_table(struct _glapi_table *exec)"
662 print "{"
663 for func in keys:
664 for spec in apiutil.Categories(func):
665 ext = spec.split(":")
666 # version does not match
667 if ext.pop(0) != version:
668 continue
669 entry = func
670 if ext:
671 suffix = ext[0].split("_")[0]
672 entry += suffix
673 print " SET_%s(exec, _es_%s);" % (entry, entry)
674 print "}"