diff options
author | Dylan Baker <dylanx.c.baker@intel.com> | 2014-11-19 14:15:04 -0800 |
---|---|---|
committer | Dylan Baker <baker.dylan.c@gmail.com> | 2015-06-22 14:13:36 -0700 |
commit | d1671884f86edd773ebb073d32b55bd1c7951757 (patch) | |
tree | d8bc0b79e497dae89b5f6bb0b4bd52f95244ea65 | |
parent | 1762568fd39b9be42d963d335e36daea25df7044 (diff) |
glapi: gl_table.py: Use mako to generate the glapitable.h
This uses a very simple mako template and a couple of generators to
create the gl_table.h file, as opposed to a complex class of print
statements. The result is easier to read, and easier to modify.
There are a few minor differences between the file generated after this
patch and before.
1) The formatting of the copyright is slightly different: lines are
wrapped in slightly different places, and the explicit names of the
authors and/or copyright holders in the final clause are replaced
with "THE AUTHORS OR COPYRIGHT HOLDERS"
2) The "DO NOT EDIT" comment is slightly reworded
3) Some ifdef changes. Each level of preprocessor macro now has one
additional space between the # and the first letter of the word, and
some comments were removed because the brevity of the template makes
it obvious which ifdefs and endifs go together.
-rw-r--r-- | src/mapi/glapi/gen/Makefile.am | 5 | ||||
-rw-r--r-- | src/mapi/glapi/gen/SConscript | 2 | ||||
-rw-r--r-- | src/mapi/glapi/gen/gl_table.py | 71 | ||||
-rw-r--r-- | src/mapi/glapi/gen/python/__init__.py | 0 | ||||
-rw-r--r-- | src/mapi/glapi/gen/python/templates.py | 28 | ||||
-rw-r--r-- | src/mapi/glapi/gen/templates/glapitable.h.mako | 53 | ||||
-rw-r--r-- | src/mapi/glapi/gen/templates/utils.mako | 54 |
7 files changed, 160 insertions, 53 deletions
diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am index 5b163b02e0..91b399b4cb 100644 --- a/src/mapi/glapi/gen/Makefile.am +++ b/src/mapi/glapi/gen/Makefile.am @@ -247,8 +247,9 @@ $(MESA_GLAPI_DIR)/glprocs.h: gl_procs.py $(COMMON) $(MESA_GLAPI_DIR)/glapitemp.h: gl_apitemp.py $(COMMON) $(PYTHON_GEN) $< -f $(srcdir)/gl_and_es_API.xml > $@ -$(MESA_GLAPI_DIR)/glapitable.h: gl_table.py $(COMMON) - $(PYTHON_GEN) $< -f $(srcdir)/gl_and_es_API.xml > $@ +$(MESA_GLAPI_DIR)/glapitable.h: gl_table.py $(COMMON) templates/glapitable.h.mako + $(PYTHON_GEN) $< -f $(srcdir)/gl_and_es_API.xml \ + | $(INDENT) $(INDENT_FLAGS) > $@ $(MESA_GLAPI_DIR)/glapi_gentable.c: gl_gentable.py $(COMMON) $(PYTHON_GEN) $< -f $(srcdir)/gl_and_es_API.xml > $@ diff --git a/src/mapi/glapi/gen/SConscript b/src/mapi/glapi/gen/SConscript index b9cdbbf363..b85736913e 100644 --- a/src/mapi/glapi/gen/SConscript +++ b/src/mapi/glapi/gen/SConscript @@ -23,7 +23,7 @@ env.CodeGenerate( env.CodeGenerate( target = '../../../mapi/glapi/glapitable.h', script = 'gl_table.py', - source = sources, + source = sources + ['templates/glapitable.h.mako'], command = python_cmd + ' $SCRIPT -f $SOURCE > $TARGET' ) diff --git a/src/mapi/glapi/gen/gl_table.py b/src/mapi/glapi/gen/gl_table.py index 3f02902308..604d4f100e 100644 --- a/src/mapi/glapi/gen/gl_table.py +++ b/src/mapi/glapi/gen/gl_table.py @@ -26,53 +26,12 @@ # Authors: # Ian Romanick <idr@us.ibm.com> +import sys import argparse import gl_XML import license - - -class PrintGlTable(gl_XML.gl_print_base): - def __init__(self, es=False): - gl_XML.gl_print_base.__init__(self) - - self.es = es - self.header_tag = '_GLAPI_TABLE_H_' - self.name = "gl_table.py (from Mesa)" - self.license = license.bsd_license_template % ( \ -"""Copyright (C) 1999-2003 Brian Paul All Rights Reserved. -(C) Copyright IBM Corporation 2004""", "BRIAN PAUL, IBM") - self.ifdef_emitted = False - return - - def printBody(self, api): - for f in api.functionIterateByOffset(): - if not f.is_abi() and not self.ifdef_emitted: - print '#if !defined HAVE_SHARED_GLAPI' - self.ifdef_emitted = True - arg_string = f.get_parameter_string() - print ' %s (GLAPIENTRYP %s)(%s); /* %d */' % ( - f.return_type, f.name, arg_string, f.offset) - - print '#endif /* !defined HAVE_SHARED_GLAPI */' - - def printRealHeader(self): - print '#ifndef GLAPIENTRYP' - print '# ifndef GLAPIENTRY' - print '# define GLAPIENTRY' - print '# endif' - print '' - print '# define GLAPIENTRYP GLAPIENTRY *' - print '#endif' - print '' - print '' - print 'struct _glapi_table' - print '{' - return - - def printRealFooter(self): - print '};' - return +from python import templates class PrintRemapTable(gl_XML.gl_print_base): @@ -202,6 +161,20 @@ class PrintRemapTable(gl_XML.gl_print_base): return +def make_gl_table(api): + """Call mako to generate a template.""" + template = templates.LOOKUP.get_template('glapitable.h.mako') + + # Rather than using print write directly to stdout like a file, be sure to + # flush afterwards. + # TODO: change this script to take an output filename argument + sys.stdout.write(template.render( + abi_functions=(x for x in api.functionIterateByOffset() if x.is_abi()), + glapi_functions=(x for x in api.functionIterateByOffset() + if not x.is_abi()))) + sys.stdout.flush() + + def _parser(): """Parse arguments and return a namespace.""" parser = argparse.ArgumentParser() @@ -227,18 +200,16 @@ def _parser(): def main(): """Main function.""" args = _parser() - api = gl_XML.parse_GL_API(args.file_name) - if args.mode == "table": - printer = PrintGlTable(args.es) - elif args.mode == "remap_table": - printer = PrintRemapTable(args.es) - if args.es is not None: api.filter_functions_by_api(args.es) - printer.Print(api) + if args.mode == "table": + make_gl_table(api) + elif args.mode == "remap_table": + printer = PrintRemapTable(args.es) + printer.Print(api) if __name__ == '__main__': diff --git a/src/mapi/glapi/gen/python/__init__.py b/src/mapi/glapi/gen/python/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/src/mapi/glapi/gen/python/__init__.py diff --git a/src/mapi/glapi/gen/python/templates.py b/src/mapi/glapi/gen/python/templates.py new file mode 100644 index 0000000000..a469b190cd --- /dev/null +++ b/src/mapi/glapi/gen/python/templates.py @@ -0,0 +1,28 @@ +# Copyright (c) 2015 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. + +from __future__ import absolute_import +import os + +from mako.lookup import TemplateLookup + +_ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) + +LOOKUP = TemplateLookup(directories=[os.path.join(_ROOT_DIR, 'templates')]) diff --git a/src/mapi/glapi/gen/templates/glapitable.h.mako b/src/mapi/glapi/gen/templates/glapitable.h.mako new file mode 100644 index 0000000000..30a4ec75ff --- /dev/null +++ b/src/mapi/glapi/gen/templates/glapitable.h.mako @@ -0,0 +1,53 @@ +## 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"/> + +/* THIS FILE IS AUTOGENERATED BY gl_table.py -- DO NOT EDIT */ +${utils.copyright(['1999-2003 Brian Paul', '2004 IBM Corporation', '2014 Intel Corporation'], 'gl_table.py')} + +#if !defined(_GLAPI_TABLE_H_) +# define _GLAPI_TABLE_H_ + +# ifndef GLAPIENTRYP +# ifndef GLAPIENTRY +# define GLAPIENTRY +# endif + +# define GLAPIENTRYP GLAPIENTRY * +# endif + + +struct _glapi_table +{ +% for func in abi_functions: + ${func.return_type} (GLAPIENTRYP ${func.name})(${func.get_parameter_string()}); /* ${func.offset} */ +% endfor +# if !defined HAVE_SHARED_GLAPI +% for func in glapi_functions: + ${func.return_type} (GLAPIENTRYP ${func.name})(${func.get_parameter_string()}); /* ${func.offset} */ +% endfor +# endif +}; + +#endif diff --git a/src/mapi/glapi/gen/templates/utils.mako b/src/mapi/glapi/gen/templates/utils.mako new file mode 100644 index 0000000000..7c656c3b3a --- /dev/null +++ b/src/mapi/glapi/gen/templates/utils.mako @@ -0,0 +1,54 @@ +## 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. + +<%doc> +A set of mako utility functions to reduce code between templates + +This should contain mako specific functions, ie those that are designed to print +things, rather than python functions which should not be doing much printing. +</%doc> + +## Holders a container of '{year} {owner}' strings, which will be sorted +## script is the name of the script that generates the file +<%def name="copyright(holders, script)"> +/* THIS FILE IS AUTO-GENERATED by ${script} -- DO NOT EDIT + * +% for each in sorted(holders): + * Copyright (c) ${each} +% endfor + * 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. + */ +</%def> |