summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylanx.c.baker@intel.com>2014-11-20 15:37:42 -0800
committerDylan Baker <baker.dylan.c@gmail.com>2015-06-22 14:13:36 -0700
commitf102cc07acc2cbfb6d4891da133f7ec719cfde37 (patch)
treef07ae7d8ceec4d94e102fbe746255df0e36ca39d
parentcb15229bbe747b9d801b4d1956463bfdc8404f06 (diff)
glapi: remap_helper.py: Use mako to generate glapi_mapi_tmp.h
This patch converts another function to use mako instead of print. It comes with the same warnings at the previous makoizing patches, there are small changes, some small differences that only a human will notice. There is one major comment omission that is worth mentioning, the comments in the MESA_alt_functions struct identifying which function is aliased are not longer generated. These could be added back in, but would require turning some lazy code into eager code, for the purpose of printing a comment. I felt that the advantages of using the lazy operators was more valuable than the comments, but if others object I will change it.
-rw-r--r--src/mapi/glapi/gen/Makefile.am5
-rw-r--r--src/mapi/glapi/gen/SConscript2
-rw-r--r--src/mapi/glapi/gen/remap_helper.py173
-rw-r--r--src/mapi/glapi/gen/templates/glapi_mapi_tmp.h.mako103
4 files changed, 142 insertions, 141 deletions
diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am
index 618d4602d5..2ba06e4175 100644
--- a/src/mapi/glapi/gen/Makefile.am
+++ b/src/mapi/glapi/gen/Makefile.am
@@ -277,8 +277,9 @@ $(MESA_DIR)/main/dispatch.h: gl_table.py $(COMMON) templates/dispatch.h.mako
$(PYTHON_GEN) $< -f $(srcdir)/gl_and_es_API.xml -m remap_table \
| $(INDENT) $(INDENT_FLAGS) > $@
-$(MESA_DIR)/main/remap_helper.h: remap_helper.py $(COMMON)
- $(PYTHON_GEN) $< -f $(srcdir)/gl_and_es_API.xml > $@
+$(MESA_DIR)/main/remap_helper.h: remap_helper.py $(COMMON) templates/glapi_mapi_tmp.h.mako
+ $(PYTHON_GEN) $< -f $(srcdir)/gl_and_es_API.xml \
+ | $(INDENT) $(INDENT_FLAGS) > $@
######################################################################
diff --git a/src/mapi/glapi/gen/SConscript b/src/mapi/glapi/gen/SConscript
index 4e8b5d7a5b..ea026735bc 100644
--- a/src/mapi/glapi/gen/SConscript
+++ b/src/mapi/glapi/gen/SConscript
@@ -44,7 +44,7 @@ env.CodeGenerate(
env.CodeGenerate(
target = '../../../mesa/main/remap_helper.h',
script = 'remap_helper.py',
- source = sources,
+ source = sources + ['templates/glapi_mapi_tmp.h.mako'],
command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET'
)
diff --git a/src/mapi/glapi/gen/remap_helper.py b/src/mapi/glapi/gen/remap_helper.py
index 94ae1936d2..735c35a450 100644
--- a/src/mapi/glapi/gen/remap_helper.py
+++ b/src/mapi/glapi/gen/remap_helper.py
@@ -24,146 +24,44 @@
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
# IN THE SOFTWARE.
+import sys
import argparse
+import collections
-import license
import gl_XML
+from python import templates
-def get_function_spec(func):
- sig = ""
- # derive parameter signature
- for p in func.parameterIterator():
- if p.is_padding:
- continue
- # FIXME: This is a *really* ugly hack. :(
- tn = p.type_expr.get_base_type_node()
- if p.is_pointer():
- sig += 'p'
- elif tn.integer:
- sig += 'i'
- elif tn.size == 4:
- sig += 'f'
- else:
- sig += 'd'
-
- spec = [sig]
- for ent in func.entry_points:
- spec.append("gl" + ent)
-
- # spec is terminated by an empty string
- spec.append('')
-
- return spec
-
-
-class PrintGlRemap(gl_XML.gl_print_base):
- def __init__(self):
- gl_XML.gl_print_base.__init__(self)
-
- self.name = "remap_helper.py (from Mesa)"
- self.license = license.bsd_license_template % ("Copyright (C) 2009 Chia-I Wu <olv@0xlab.org>", "Chia-I Wu")
- return
-
-
- def printRealHeader(self):
- print '#include "main/dispatch.h"'
- print '#include "main/remap.h"'
- print ''
- return
-
-
- def printBody(self, api):
- pool_indices = {}
-
- print '/* this is internal to remap.c */'
- print '#ifndef need_MESA_remap_table'
- print '#error Only remap.c should include this file!'
- print '#endif /* need_MESA_remap_table */'
- print ''
-
- print ''
- print 'static const char _mesa_function_pool[] ='
-
- # output string pool
- index = 0;
- for f in api.functionIterateAll():
- pool_indices[f] = index
-
- spec = get_function_spec(f)
-
- # a function has either assigned offset, fixed offset,
- # or no offset
- if f.assign_offset:
- comments = "will be remapped"
- elif f.offset > 0:
- comments = "offset %d" % f.offset
- else:
- comments = "dynamic"
-
- print ' /* _mesa_function_pool[%d]: %s (%s) */' \
- % (index, f.name, comments)
- for line in spec:
- print ' "%s\\0"' % line
- index += len(line) + 1
- print ' ;'
- print ''
-
- print '/* these functions need to be remapped */'
- print 'static const struct gl_function_pool_remap MESA_remap_table_functions[] = {'
- # output all functions that need to be remapped
- # iterate by offsets so that they are sorted by remap indices
- for f in api.functionIterateByOffset():
- if not f.assign_offset:
- continue
- print ' { %5d, %s_remap_index },' \
- % (pool_indices[f], f.name)
- print ' { -1, -1 }'
- print '};'
- print ''
-
- # collect functions by versions/extensions
- extension_functions = {}
- abi_extensions = []
- for f in api.functionIterateAll():
- for n in f.entry_points:
- category, num = api.get_category_for_name(n)
- # consider only GL_VERSION_X_Y or extensions
- c = gl_XML.real_category_name(category)
- if c.startswith("GL_"):
- if not extension_functions.has_key(c):
- extension_functions[c] = []
- extension_functions[c].append(f)
- # remember the ext names of the ABI
- if (f.is_abi() and n == f.name and
- c not in abi_extensions):
- abi_extensions.append(c)
- # ignore the ABI itself
- for ext in abi_extensions:
- extension_functions.pop(ext)
-
- extensions = extension_functions.keys()
- extensions.sort()
-
- # output ABI functions that have alternative names (with ext suffix)
- print '/* these functions are in the ABI, but have alternative names */'
- print 'static const struct gl_function_remap MESA_alt_functions[] = {'
- for ext in extensions:
- funcs = []
- for f in extension_functions[ext]:
- # test if the function is in the ABI and has alt names
- if f.is_abi() and len(f.entry_points) > 1:
- funcs.append(f)
- if not funcs:
- continue
- print ' /* from %s */' % ext
- for f in funcs:
- print ' { %5d, _gloffset_%s },' \
- % (pool_indices[f], f.name)
- print ' { -1, -1 }'
- print '};'
- print ''
- return
+def generate(api):
+ """Generate glapi_mapi_tmp.h."""
+ template = templates.LOOKUP.get_template('glapi_mapi_tmp.h.mako')
+
+ # FIXME: It would be better to just take a file option than to use stdout
+ sys.stdout.write(template.render(
+ api=api,
+ extensions=_sort_extensions(api)))
+ sys.stdout.flush()
+
+
+def _sort_extensions(api):
+ """Sort extensions into groups based on when they were added."""
+ extensions = collections.defaultdict(list)
+ abi_extensions = set()
+ for func in api.functionIterateAll():
+ for n in func.entry_points:
+ category, _ = api.get_category_for_name(n)
+ # consider only GL_VERSION_X_Y or extensions
+ category = gl_XML.real_category_name(category)
+ if category.startswith('GL_'):
+ extensions[category].append(func)
+ # remember the ext names of the ABI
+ if func.is_abi() and n == func.name:
+ abi_extensions.add(category)
+ # ignore the ABI itself
+ for ext in abi_extensions:
+ del extensions[ext]
+
+ return extensions
def _parser():
@@ -186,13 +84,12 @@ def _parser():
def main():
"""Main function."""
args = _parser()
-
api = gl_XML.parse_GL_API(args.file_name)
+
if args.es is not None:
api.filter_functions_by_api(args.es)
- printer = PrintGlRemap()
- printer.Print(api)
+ generate(api)
if __name__ == '__main__':
diff --git a/src/mapi/glapi/gen/templates/glapi_mapi_tmp.h.mako b/src/mapi/glapi/gen/templates/glapi_mapi_tmp.h.mako
new file mode 100644
index 0000000000..2ddd544f4d
--- /dev/null
+++ b/src/mapi/glapi/gen/templates/glapi_mapi_tmp.h.mako
@@ -0,0 +1,103 @@
+## Copyright (C) 2014 Intel Corporation
+##
+## Permission is hereby granted, free of charge, to any person obtaining
+## a copy of this software and associated documentation files (the "Software"),
+## to deal in the Software without restriction, including without limitation
+## the rights to use, copy, modify, merge, publish, distribute, sublicense,
+## and/or sell copies of the Software, and to permit persons to whom the
+## Software is furnished to do so, subject to the following conditions:
+##
+## The above copyright notice and this permission notice shall be included
+## in all copies or substantial portions of the Software.
+##
+## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+## EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+## OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+## IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+## DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+## TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
+## OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+##
+## In case it isn't obvious, this ## commented copyright header will not be
+## rendered into the actual template, it applies to the template.
+##
+<%namespace name="utils" file="utils.mako"/>
+
+<%def name="_get_comment(func)" filter="trim">
+ % if func.assign_offset:
+ will be remapped
+ % elif func.offset > 0:
+ offset ${func.offset}
+ % else:
+ dynamic
+ % endif
+</%def>
+
+<%
+ index = 0
+ pool_indecies = {}
+
+ def get_function_spec(func):
+ sig = ""
+ # derive parameter signature
+ for p in func.parameterIterator():
+ if p.is_padding:
+ continue
+ # FIXME: This is a *really* ugly hack. :(
+ tn = p.type_expr.get_base_type_node()
+ if p.is_pointer():
+ sig += 'p'
+ elif tn.integer:
+ sig += 'i'
+ elif tn.size == 4:
+ sig += 'f'
+ else:
+ sig += 'd'
+
+ spec = [sig]
+ for ent in func.entry_points:
+ spec.append("gl" + ent)
+ spec.append('')
+
+ return spec
+%>
+
+${utils.copyright(['2009 Chia-I Wu <olv@0xlab.org>'], 'remap_helper.py')}
+
+#include "main/dispatch.h"
+#include "main/remap.h"
+
+/* This is internal to remap.c */
+#ifndef need_MESA_remap_table
+#error Only remap.c should include this file!
+#endif
+
+static const char _mesa_function_pool[] =
+% for func in api.functionIterateAll():
+ <% pool_indecies[func] = index %> \
+ /* _mesa_function_pool[${index}]: ${func.name} (${_get_comment(func)}) */
+ % for line in get_function_spec(func):
+ "${line}\0"
+ <% index += len(line) + 1 %> \
+ % endfor
+% endfor
+;
+
+/* these functions need to be remapped */
+static const struct gl_function_pool_remap MESA_remap_table_functions[] = {
+% for func in (f for f in api.functionIterateByOffset() if f.assign_offset):
+ { ${str(pool_indecies[func]).rjust(5, ' ')}, ${func.name}_remap_index },
+% endfor
+ { -1, -1 }
+};
+
+## output ABI Functions that have alternative names
+/* These functions are in the ABI, but have alternate names */
+static const struct gl_function_remap MESA_alt_functions[] = {
+% for ext in sorted(extensions.iterkeys()):
+ % for func in (f for f in extensions[ext] if (f.is_abi() and len(f.entry_points) > 1)):
+ { ${str(pool_indecies[func]).rjust(5, ' ')}, _gloffset_${func.name} },
+ % endfor
+% endfor
+ { -1, -1 }
+};