[Mesa-dev] [PATCH v2 6/14] anv: convert header generation in anv_entrypoints_gen.py to mako

Eric Engestrom eric.engestrom at imgtec.com
Fri Feb 24 10:28:22 UTC 2017


On Thursday, 2017-02-23 10:46:19 -0800, Dylan Baker wrote:
> This produces an identical file except for whitespace.
> 
> Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
> ---
>  src/intel/vulkan/anv_entrypoints_gen.py | 75 ++++++++++++++------------
>  1 file changed, 41 insertions(+), 34 deletions(-)
> 
> diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
> index 772f3e6..7493fb6 100644
> --- a/src/intel/vulkan/anv_entrypoints_gen.py
> +++ b/src/intel/vulkan/anv_entrypoints_gen.py
> @@ -26,6 +26,8 @@ import argparse
>  import textwrap
>  import xml.etree.ElementTree as et
>  
> +from mako.template import Template
> +
>  MAX_API_VERSION = 1.0
>  
>  SUPPORTED_EXTENSIONS = [
> @@ -45,6 +47,44 @@ SUPPORTED_EXTENSIONS = [
>  # function and a power-of-two size table. The prime numbers are determined
>  # experimentally.
>  
> +TEMPLATE_H = Template(textwrap.dedent("""\
> +    /* This file generated from vk_gen.py, don't edit directly. */

s/vk_gen.py/anv_entrypoints_gen.py/ :)

(This can be added as a separate, preceding patch?)

> +
> +    struct anv_dispatch_table {
> +       union {
> +          void *entrypoints[${len(entrypoints)}];
> +          struct {
> +          % for _, name, _, _, _, guard in entrypoints:
> +            % if guard is not None:
> +    #ifdef ${guard}
> +              PFN_vk${name} ${name};
> +    #else
> +              void *${name};
> +    # endif
> +            % else:
> +              PFN_vk${name} ${name};
> +            % endif
> +          % endfor
> +          };
> +       };
> +    };
> +
> +    void anv_set_dispatch_devinfo(const struct gen_device_info *info);
> +    % for type_, name, args, num, h, guard in entrypoints:
> +      % if guard is not None:
> +    #ifdef ${guard}
> +      % endif
> +      ${type_} anv_${name}(${args});
> +      ${type_} gen7_${name}(${args});
> +      ${type_} gen75_${name}(${args});
> +      ${type_} gen8_${name}(${args});
> +      ${type_} gen9_${name}(${args});
> +      % if guard is not None:
> +    #endif // ${guard}
> +      % endif
> +    % endfor
> +    """))
> +
>  NONE = 0xffff
>  HASH_SIZE = 256
>  U32_MASK = 2**32 - 1
> @@ -130,39 +170,6 @@ def get_entrypoints_defines(doc):
>      return entrypoints_to_defines
>  
>  
> -def gen_header(entrypoints):
> -    print "/* This file generated from vk_gen.py, don't edit directly. */\n"
> -
> -    print "struct anv_dispatch_table {"
> -    print "   union {"
> -    print "      void *entrypoints[%d];" % len(entrypoints)
> -    print "      struct {"
> -
> -    for type, name, args, num, h, guard in entrypoints:
> -        if guard is not None:
> -            print "#ifdef {0}".format(guard)
> -            print "         PFN_vk{0} {0};".format(name)
> -            print "#else"
> -            print "         void *{0};".format(name)
> -            print "#endif"
> -        else:
> -            print "         PFN_vk{0} {0};".format(name)
> -    print "      };\n"
> -    print "   };\n"
> -    print "};\n"
> -
> -    print "void anv_set_dispatch_devinfo(const struct gen_device_info *info);\n"
> -
> -    for type, name, args, num, h, guard in entrypoints:
> -        print_guard_start(guard)
> -        print "%s anv_%s(%s);" % (type, name, args)
> -        print "%s gen7_%s(%s);" % (type, name, args)
> -        print "%s gen75_%s(%s);" % (type, name, args)
> -        print "%s gen8_%s(%s);" % (type, name, args)
> -        print "%s gen9_%s(%s);" % (type, name, args)
> -        print_guard_end(guard)
> -
> -
>  def gen_code(entrypoints):
>      print textwrap.dedent("""\
>      /*
> @@ -371,7 +378,7 @@ def main():
>      # For outputting entrypoints.h we generate a anv_EntryPoint() prototype
>      # per entry point.
>      if args.target == 'header':
> -        gen_header(entrypoints)
> +        print TEMPLATE_H.render(entrypoints=entrypoints)
>      else:
>          gen_code(entrypoints)
>  
> -- 
> git-series 0.9.0
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list