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-02-18 13:33:23 -0800 |
commit | 4a6018c5fe6e2bdb67b44b5d4acc03e4c672f374 (patch) | |
tree | 2ce79c3ec4f4a6428b6e88e6b8bb46383647ab8e | |
parent | b669209023da0b414349775635f74d0dc8297937 (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/gl_table.py | 73 | ||||
-rw-r--r-- | src/mapi/glapi/gen/templates/glapitable.h.mako | 73 |
2 files changed, 96 insertions, 50 deletions
diff --git a/src/mapi/glapi/gen/gl_table.py b/src/mapi/glapi/gen/gl_table.py index 99403214ac..0b7decf75d 100644 --- a/src/mapi/glapi/gen/gl_table.py +++ b/src/mapi/glapi/gen/gl_table.py @@ -26,55 +26,15 @@ # Authors: # Ian Romanick <idr@us.ibm.com> +import sys import argparse +from mako.template import Template + 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 - - class PrintRemapTable(gl_XML.gl_print_base): def __init__(self, es=False): gl_XML.gl_print_base.__init__(self) @@ -202,6 +162,20 @@ class PrintRemapTable(gl_XML.gl_print_base): return +def make_gl_table(api): + """Call mako to generate a template.""" + template = Template(filename='templates/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() @@ -214,7 +188,7 @@ def _parser(): parser.add_argument('-m', '--mode', choices={'table', 'remap_table'}, default='table', - metava="mode", + metavar="mode", help="Generate either a table or a remap_table") parser.add_argument('-c', '--es-version', choices={None, 'es1', 'es2'}, @@ -229,15 +203,14 @@ def main(): """Main function.""" args = _parser() - if args.mode == "table": - printer = PrintGlTable(args.es) - elif args.mode == "remap_table": - printer = PrintRemapTable(args.es) - if args.es is not None: args.api.filter_functions_by_api(args.es) - printer.Print(args.api) + if args.mode == "table": + make_gl_table(args.api) + elif args.mode == "remap_table": + printer = PrintRemapTable(args.es) + printer.Print(args.api) if __name__ == '__main__': 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..4f67e56c58 --- /dev/null +++ b/src/mapi/glapi/gen/templates/glapitable.h.mako @@ -0,0 +1,73 @@ +## 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. +## +/* THIS FILE IS AUTOGENERATED BY gl_table.py -- DO NOT EDIT + * + * Copyright (c) 1999-2003 Brian Paul + * Copyright (c) 2004 IBM Corporation + * 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. + */ + +#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 |