2 # Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>
5 # This is based on extension_helper.py by Ian Romanick.
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:
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
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 # IBM 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
26 from __future__
import print_function
34 def get_function_spec(func
):
36 # derive parameter signature
37 for p
in func
.parameterIterator():
40 # FIXME: This is a *really* ugly hack. :(
41 tn
= p
.type_expr
.get_base_type_node()
52 for ent
in func
.entry_points
:
53 spec
.append("gl" + ent
)
55 # spec is terminated by an empty string
61 class PrintGlRemap(gl_XML
.gl_print_base
):
63 gl_XML
.gl_print_base
.__init
__(self
)
65 self
.name
= "remap_helper.py (from Mesa)"
66 self
.license
= license
.bsd_license_template
% ("Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>", "Chia-I Wu")
70 def printRealHeader(self
):
71 print('#include "main/dispatch.h"')
72 print('#include "main/remap.h"')
77 def printBody(self
, api
):
80 print('/* this is internal to remap.c */')
81 print('#ifndef need_MESA_remap_table')
82 print('#error Only remap.c should include this file!')
83 print('#endif /* need_MESA_remap_table */')
87 print('static const char _mesa_function_pool[] =')
91 for f
in api
.functionIterateAll():
92 pool_indices
[f
] = index
94 spec
= get_function_spec(f
)
96 # a function has either assigned offset, fixed offset,
99 comments
= "will be remapped"
101 comments
= "offset %d" % f
.offset
105 print(' /* _mesa_function_pool[%d]: %s (%s) */' \
106 % (index
, f
.name
, comments
))
108 print(' "%s\\0"' % line
)
109 index
+= len(line
) + 1
113 print('/* these functions need to be remapped */')
114 print('static const struct gl_function_pool_remap 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
))
129 """Parse input options and return a namsepace."""
130 parser
= argparse
.ArgumentParser()
131 parser
.add_argument('-f', '--filename',
132 default
="gl_API.xml",
133 metavar
="input_file_name",
135 help="An xml description file.")
136 return parser
.parse_args()
143 api
= gl_XML
.parse_GL_API(args
.file_name
)
145 printer
= PrintGlRemap()
149 if __name__
== '__main__':