de759d6c04b6fa09871690bef7b5561beb89a05b
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
32 def get_function_spec(func
):
34 # derive parameter signature
35 for p
in func
.parameterIterator():
38 # FIXME: This is a *really* ugly hack. :(
39 tn
= p
.type_expr
.get_base_type_node()
50 for ent
in func
.entry_points
:
51 spec
.append("gl" + ent
)
53 # spec is terminated by an empty string
59 class PrintGlRemap(gl_XML
.gl_print_base
):
61 gl_XML
.gl_print_base
.__init
__(self
)
63 self
.name
= "remap_helper.py (from Mesa)"
64 self
.license
= license
.bsd_license_template
% ("Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>", "Chia-I Wu")
68 def printRealHeader(self
):
69 print '#include "main/dispatch.h"'
70 print '#include "main/remap.h"'
75 def printBody(self
, api
):
78 print '/* this is internal to remap.c */'
79 print '#ifndef need_MESA_remap_table'
80 print '#error Only remap.c should include this file!'
81 print '#endif /* need_MESA_remap_table */'
85 print 'static const char _mesa_function_pool[] ='
89 for f
in api
.functionIterateAll():
90 pool_indices
[f
] = index
92 spec
= get_function_spec(f
)
94 # a function has either assigned offset, fixed offset,
97 comments
= "will be remapped"
99 comments
= "offset %d" % f
.offset
103 print ' /* _mesa_function_pool[%d]: %s (%s) */' \
104 % (index
, f
.name
, comments
)
106 print ' "%s\\0"' % line
107 index
+= len(line
) + 1
111 print '/* these functions need to be remapped */'
112 print 'static const struct gl_function_pool_remap MESA_remap_table_functions[] = {'
113 # output all functions that need to be remapped
114 # iterate by offsets so that they are sorted by remap indices
115 for f
in api
.functionIterateByOffset():
116 if not f
.assign_offset
:
118 print ' { %5d, %s_remap_index },' \
119 % (pool_indices
[f
], f
.name
)
127 """Parse input options and return a namsepace."""
128 parser
= argparse
.ArgumentParser()
129 parser
.add_argument('-f', '--filename',
130 default
="gl_API.xml",
131 metavar
="input_file_name",
133 help="An xml description file.")
134 return parser
.parse_args()
141 api
= gl_XML
.parse_GL_API(args
.file_name
)
143 printer
= PrintGlRemap()
147 if __name__
== '__main__':