[Mesa-dev] [PATCH v3 07/15] anv: convert header generation in anv_entrypoints_gen.py to mako

Dylan Baker dylan at pnwbakers.com
Fri Feb 24 18:21:35 UTC 2017


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 | 77 ++++++++++++++------------
 1 file changed, 42 insertions(+), 35 deletions(-)

diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
index 05a685d..cad94c8 100644
--- a/src/intel/vulkan/anv_entrypoints_gen.py
+++ b/src/intel/vulkan/anv_entrypoints_gen.py
@@ -27,6 +27,8 @@ import os
 import textwrap
 import xml.etree.ElementTree as et
 
+from mako.template import Template
+
 MAX_API_VERSION = 1.0
 
 SUPPORTED_EXTENSIONS = [
@@ -46,6 +48,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 ${filename}, don't edit directly. */
+
+    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
@@ -131,40 +171,6 @@ def get_entrypoints_defines(doc):
     return entrypoints_to_defines
 
 
-def gen_header(entrypoints):
-    print "/* This file generated from {}, don't edit directly. */\n".format(
-        os.path.basename(__file__))
-
-    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("""\
     /*
@@ -373,7 +379,8 @@ 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,
+                                filename=os.path.basename(__file__))
     else:
         gen_code(entrypoints)
 
-- 
git-series 0.9.1


More information about the mesa-dev mailing list