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
33 def get_function_spec(func
):
35 # derive parameter signature
36 for p
in func
.parameterIterator():
39 # FIXME: This is a *really* ugly hack. :(
40 tn
= p
.type_expr
.get_base_type_node()
51 for ent
in func
.entry_points
:
52 spec
.append("gl" + ent
)
54 # spec is terminated by an empty string
60 class PrintGlRemap(gl_XML
.gl_print_base
):
62 gl_XML
.gl_print_base
.__init
__(self
)
64 self
.name
= "remap_helper.py (from Mesa)"
65 self
.license
= license
.bsd_license_template
% ("Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>", "Chia-I Wu")
69 def printRealHeader(self
):
70 print '#include "main/dispatch.h"'
71 print '#include "main/remap.h"'
76 def printBody(self
, api
):
79 print '/* this is internal to remap.c */'
80 print '#ifndef need_MESA_remap_table'
81 print '#error Only remap.c should include this file!'
82 print '#endif /* need_MESA_remap_table */'
86 print 'static const char _mesa_function_pool[] ='
90 for f
in api
.functionIterateAll():
91 pool_indices
[f
] = index
93 spec
= get_function_spec(f
)
95 # a function has either assigned offset, fixed offset,
98 comments
= "will be remapped"
100 comments
= "offset %d" % f
.offset
104 print ' /* _mesa_function_pool[%d]: %s (%s) */' \
105 % (index
, f
.name
, comments
)
107 print ' "%s\\0"' % line
108 index
+= len(line
) + 1
112 print '/* these functions need to be remapped */'
113 print 'static const struct gl_function_pool_remap MESA_remap_table_functions[] = {'
114 # output all functions that need to be remapped
115 # iterate by offsets so that they are sorted by remap indices
116 for f
in api
.functionIterateByOffset():
117 if not f
.assign_offset
:
119 print ' { %5d, %s_remap_index },' \
120 % (pool_indices
[f
], f
.name
)
128 """Parse input options and return a namsepace."""
129 parser
= argparse
.ArgumentParser()
130 parser
.add_argument('-f', '--filename',
131 default
="gl_API.xml",
132 metavar
="input_file_name",
134 help="An xml description file.")
135 return parser
.parse_args()
142 api
= gl_XML
.parse_GL_API(args
.file_name
)
144 printer
= PrintGlRemap()
148 if __name__
== '__main__':