3 # Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
6 # This is based on extension_helper.py by Ian Romanick.
8 # Permission is hereby granted, free of charge, to any person obtaining a
9 # copy of this software and associated documentation files (the "Software"),
10 # to deal in the Software without restriction, including without limitation
11 # on the rights to use, copy, modify, merge, publish, distribute, sub
12 # license, and/or sell copies of the Software, and to permit persons to whom
13 # the Software is furnished to do so, subject to the following conditions:
15 # The above copyright notice and this permission notice (including the next
16 # paragraph) shall be included in all copies or substantial portions of the
19 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
22 # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
29 import sys
, getopt
, string
31 def get_function_spec(func
):
33 # derive parameter signature
34 for p
in func
.parameterIterator():
37 # FIXME: This is a *really* ugly hack. :(
38 tn
= p
.type_expr
.get_base_type_node()
49 for ent
in func
.entry_points
:
50 spec
.append("gl" + ent
)
52 # spec is terminated by an empty string
57 class PrintGlRemap(gl_XML
.gl_print_base
):
59 gl_XML
.gl_print_base
.__init
__(self
)
61 self
.name
= "remap_helper.py (from Mesa)"
62 self
.license
= license
.bsd_license_template
% ("Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>", "Chia-I Wu")
66 def printRealHeader(self
):
67 print '#include "glapi/dispatch.h"'
72 def printBody(self
, api
):
73 print 'struct gl_function_remap {'
74 print ' GLint func_index;'
75 print ' GLint dispatch_offset; /* for sanity check */'
81 print '/* this is internal to remap.c */'
82 print '#ifdef need_MESA_remap_table'
84 print 'static const char _mesa_function_pool[] ='
88 for f
in api
.functionIterateAll():
89 pool_indices
[f
] = index
91 spec
= get_function_spec(f
)
93 # a function has either assigned offset, fixed offset,
96 comments
= "will be remapped"
98 comments
= "offset %d" % f
.offset
102 print ' /* _mesa_function_pool[%d]: %s (%s) */' \
103 % (index
, f
.name
, comments
)
105 print ' "%s\\0"' % line
106 index
+= len(line
) + 1
110 print '/* these functions need to be remapped */'
111 print 'static const struct {'
112 print ' GLint pool_index;'
113 print ' GLint remap_index;'
114 print '} MESA_remap_table_functions[] = {'
115 # output all functions that need to be remapped
116 # iterate by offsets so that they are sorted by remap indices
117 for f
in api
.functionIterateByOffset():
118 if not f
.assign_offset
:
120 print ' { %5d, %s_remap_index },' \
121 % (pool_indices
[f
], f
.name
)
126 abi
= [ "1.0", "1.1", "1.2", "GL_ARB_multitexture" ]
127 extension_functions
= {}
129 # collect non-ABI functions
130 for f
in api
.functionIterateAll():
131 for n
in f
.entry_points
:
132 category
, num
= api
.get_category_for_name(n
)
133 if category
not in abi
:
134 c
= gl_XML
.real_category_name(category
)
135 if not extension_functions
.has_key(c
):
136 extension_functions
[c
] = []
137 extension_functions
[c
].append(f
)
138 extensions
= extension_functions
.keys()
141 # output ABI functions that have alternative names (with ext suffix)
142 print '/* these functions are in the ABI, but have alternative names */'
143 print 'static const struct gl_function_remap MESA_alt_functions[] = {'
144 for ext
in extensions
:
146 for f
in extension_functions
[ext
]:
147 # test if the function is in the ABI
148 if not f
.assign_offset
and f
.offset
>= 0:
152 print ' /* from %s */' % ext
154 print ' { %5d, _gloffset_%s },' \
155 % (pool_indices
[f
], f
.name
)
160 print '#endif /* need_MESA_remap_table */'
163 # output remap helpers for DRI drivers
165 for ext
in extensions
:
168 for f
in extension_functions
[ext
]:
170 # these are handled above
173 # these functions are either in the
174 # abi, or have offset -1
177 print '#if defined(need_%s)' % (ext
)
179 print '/* functions defined in MESA_remap_table_functions are excluded */'
181 # output extension functions that need to be mapped
182 print 'static const struct gl_function_remap %s_functions[] = {' % (ext
)
185 print ' { %5d, _gloffset_%s },' \
186 % (pool_indices
[f
], f
.name
)
188 print ' { %5d, -1 }, /* %s */' % \
189 (pool_indices
[f
], f
.name
)
200 print "Usage: %s [-f input_file_name]" % sys
.argv
[0]
203 if __name__
== '__main__':
204 file_name
= "gl_API.xml"
207 (args
, trail
) = getopt
.getopt(sys
.argv
[1:], "f:")
211 for (arg
,val
) in args
:
215 api
= gl_XML
.parse_GL_API( file_name
)
217 printer
= PrintGlRemap()