3 # (C) Copyright IBM Corporation 2004, 2005
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:
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
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
26 # Ian Romanick <idr@us.ibm.com>
28 from xml
.sax
import saxutils
29 from xml
.sax
import make_parser
30 from xml
.sax
.handler
import feature_namespaces
35 import sys
, getopt
, copy
38 class SizeStubFunctionIterator
:
39 """Iterate over functions that need "size" information.
41 Iterate over the functions that have variable sized data. First the
42 "set"-type functions are iterated followed by the "get"-type
46 def __init__(self
, context
):
54 for f
in gl_XML
.glFunctionIterator(context
):
55 if f
.fn_offset
< 0: break
57 if context
.glx_enum_functions
.has_key(f
.name
):
58 ef
= context
.glx_enum_functions
[f
.name
]
60 set_functions
.append(f
)
62 get_functions
.append(f
)
65 if (context
.which_functions
& PrintGlxSizeStubs_c
.do_set
) != 0:
66 self
.data
+= set_functions
67 elif context
.get_alias_set
:
68 extra_data
= set_functions
70 if (context
.which_functions
& PrintGlxSizeStubs_c
.do_get
) != 0:
71 self
.data
+= get_functions
74 for f
in extra_data
+ self
.data
:
75 sig
= context
.glx_enum_functions
[f
.name
].signature()
77 if not context
.glx_enum_sigs
.has_key(sig
):
78 context
.glx_enum_sigs
[sig
] = f
.name
;
88 if self
.index
== len(self
.data
):
91 f
= self
.data
[ self
.index
]
97 class PrintGlxSizeStubs_common(glX_XML
.GlxProto
):
100 do_get_alias_set
= (1 << 2)
102 def __init__(self
, which_functions
):
103 glX_XML
.GlxProto
.__init
__(self
)
104 self
.license
= license
.bsd_license_template
% ( "(C) Copyright IBM Corporation 2004", "IBM")
106 self
.glx_enum_sigs
= {}
107 self
.name
= "glX_proto_size.py (from Mesa)"
108 self
.which_functions
= which_functions
110 if (((which_functions
& PrintGlxSizeStubs_common
.do_set
) != 0) and ((which_functions
& PrintGlxSizeStubs_common
.do_get
) != 0)) or ((which_functions
& PrintGlxSizeStubs_common
.do_get_alias_set
) != 0):
111 self
.get_alias_set
= 1
113 self
.get_alias_set
= 0
116 def functionIterator(self
):
117 return SizeStubFunctionIterator(self
)
120 class PrintGlxSizeStubs_c(PrintGlxSizeStubs_common
):
121 def printRealHeader(self
):
123 print '#include <GL/gl.h>'
124 print '#include "indirect_size.h"'
127 glX_XML
.printHaveAlias()
131 glX_XML
.printFastcall()
133 glX_XML
.printVisibility( "INTERNAL", "internal" )
136 print '#ifdef HAVE_ALIAS'
137 print '# define ALIAS2(from,to) \\'
138 print ' INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\'
139 print ' __attribute__ ((alias( # to )));'
140 print '# define ALIAS(from,to) ALIAS2( from, __gl ## to ## _size )'
142 print '# define ALIAS(from,to) \\'
143 print ' INTERNAL PURE FASTCALL GLint __gl ## from ## _size( GLenum e ) \\'
144 print ' { return __gl ## to ## _size( e ); }'
150 def printRealFooter(self
):
151 for a
in self
.aliases
:
155 def printFunction(self
, f
):
156 ef
= self
.glx_enum_functions
[f
.name
]
157 n
= self
.glx_enum_sigs
[ ef
.signature() ];
160 a
= 'ALIAS( %s, %s )' % (f
.name
, n
)
161 self
.aliases
.append(a
)
167 class PrintGlxSizeStubs_h(PrintGlxSizeStubs_common
):
168 def printRealHeader(self
):
172 * Prototypes for functions used to determine the number of data elements in
173 * various GLX protocol messages.
175 * \\author Ian Romanick <idr@us.ibm.com>
178 #if !defined( _GLXSIZE_H_ )
184 glX_XML
.printFastcall();
186 glX_XML
.printVisibility( "INTERNAL", "internal" );
189 def printRealFooter(self
):
191 print "# undef INTERNAL"
193 print "# undef FASTCALL"
194 print "#endif /* !defined( _GLXSIZE_H_ ) */"
197 def printFunction(self
, f
):
198 ef
= self
.glx_enum_functions
[f
.name
]
199 print 'extern INTERNAL PURE FASTCALL GLint __gl%s_size(GLenum);' % (f
.name
)
203 print "Usage: %s [-f input_file_name] -m output_mode [--only-get | --only-set] [--get-alias-set]" % sys
.argv
[0]
204 print " -m output_mode Output mode can be one of 'size_c' or 'size_h'."
205 print " --only-get Only emit 'get'-type functions."
206 print " --only-set Only emit 'set'-type functions."
207 print " --get-alias-set When only 'get'-type functions are emitted, allow them"
208 print " to be aliases to 'set'-type funcitons."
210 print "By default, both 'get' and 'set'-type functions are emitted."
214 if __name__
== '__main__':
215 file_name
= "gl_API.xml"
218 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:m:", ["only-get", "only-set", "get-alias-set"])
223 which_functions
= PrintGlxSizeStubs_common
.do_get | PrintGlxSizeStubs_common
.do_set
225 for (arg
,val
) in args
:
230 elif arg
== "--only-get":
231 which_functions
= PrintGlxSizeStubs_common
.do_get
232 elif arg
== "--only-set":
233 which_functions
= PrintGlxSizeStubs_common
.do_set
234 elif arg
== "--get-alias-set":
235 which_functions |
= PrintGlxSizeStubs_common
.do_get_alias_set
238 dh
= PrintGlxSizeStubs_c( which_functions
)
239 elif mode
== "size_h":
240 dh
= PrintGlxSizeStubs_h( which_functions
)
244 parser
= make_parser()
245 parser
.setFeature(feature_namespaces
, 0)
246 parser
.setContentHandler(dh
)