[Mesa-dev] [PATCH v3 02/15] anv: Use python style in anv_entrypoints_gen.py

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


These are all fairly small cleanups/tweaks that don't really deserve
their own patch.

- Prefer comprehensions to map() and filter(), since they're faster
- replace unused variables with _
- Use 4 spaces of indent
- drop semicolons from the end of lines
- Don't use parens around if conditions
- don't put spaces around brackets
- don't import modules as caps (ET -> et)
- Use docstrings instead of comments

v2: - Replace comprehensions with multiplication

Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
---
 src/intel/vulkan/anv_entrypoints_gen.py | 63 ++++++++++++++------------
 1 file changed, 34 insertions(+), 29 deletions(-)

diff --git a/src/intel/vulkan/anv_entrypoints_gen.py b/src/intel/vulkan/anv_entrypoints_gen.py
index 3f7a1ce..b4cead9 100644
--- a/src/intel/vulkan/anv_entrypoints_gen.py
+++ b/src/intel/vulkan/anv_entrypoints_gen.py
@@ -24,20 +24,20 @@
 
 import sys
 import textwrap
-import xml.etree.ElementTree as ET
+import xml.etree.ElementTree as et
 
 max_api_version = 1.0
 
 supported_extensions = [
-   'VK_KHR_get_physical_device_properties2',
-   'VK_KHR_maintenance1',
-   'VK_KHR_sampler_mirror_clamp_to_edge',
-   'VK_KHR_shader_draw_parameters',
-   'VK_KHR_surface',
-   'VK_KHR_swapchain',
-   'VK_KHR_wayland_surface',
-   'VK_KHR_xcb_surface',
-   'VK_KHR_xlib_surface',
+    'VK_KHR_get_physical_device_properties2',
+    'VK_KHR_maintenance1',
+    'VK_KHR_sampler_mirror_clamp_to_edge',
+    'VK_KHR_shader_draw_parameters',
+    'VK_KHR_surface',
+    'VK_KHR_swapchain',
+    'VK_KHR_wayland_surface',
+    'VK_KHR_xcb_surface',
+    'VK_KHR_xlib_surface',
 ]
 
 # We generate a static hash table for entry point lookup
@@ -53,33 +53,37 @@ hash_mask = hash_size - 1
 prime_factor = 5024183
 prime_step = 19
 
+opt_header = False
+opt_code = False
+
+if sys.argv[1] == "header":
+    opt_header = True
+    sys.argv.pop()
+elif sys.argv[1] == "code":
+    opt_code = True
+    sys.argv.pop()
+
+
 def hash(name):
-    h = 0;
+    h = 0
     for c in name:
         h = (h * prime_factor + ord(c)) & u32_mask
 
     return h
 
+
 def print_guard_start(guard):
     if guard is not None:
         print "#ifdef {0}".format(guard)
 
+
 def print_guard_end(guard):
     if guard is not None:
         print "#endif // {0}".format(guard)
 
-opt_header = False
-opt_code = False
 
-if (sys.argv[1] == "header"):
-    opt_header = True
-    sys.argv.pop()
-elif (sys.argv[1] == "code"):
-    opt_code = True
-    sys.argv.pop()
-
-# Extract the entry points from the registry
 def get_entrypoints(doc, entrypoints_to_defines):
+    """Extract the entry points from the registry."""
     entrypoints = []
 
     enabled_commands = set()
@@ -108,7 +112,7 @@ def get_entrypoints(doc, entrypoints_to_defines):
             continue
 
         shortname = fullname[2:]
-        params = map(lambda p: "".join(p.itertext()), command.findall('./param'))
+        params = (''.join(p.itertext()) for p in command.findall('./param'))
         params = ', '.join(params)
         if fullname in entrypoints_to_defines:
             guard = entrypoints_to_defines[fullname]
@@ -119,8 +123,9 @@ def get_entrypoints(doc, entrypoints_to_defines):
 
     return entrypoints
 
-# Maps entry points to extension defines
+
 def get_entrypoints_defines(doc):
+    """Maps entry points to extension defines."""
     entrypoints_to_defines = {}
     extensions = doc.findall('./extensions/extension')
     for extension in extensions:
@@ -133,7 +138,7 @@ def get_entrypoints_defines(doc):
 
 
 def main():
-    doc = ET.parse(sys.stdin)
+    doc = et.parse(sys.stdin)
     entrypoints = get_entrypoints(doc, get_entrypoints_defines(doc))
 
     # Manually add CreateDmaBufImageINTEL for which we don't have an extension
@@ -225,7 +230,7 @@ def main():
     static const char strings[] =""")
 
     offsets = []
-    i = 0;
+    i = 0
     for type, name, args, num, h, guard in entrypoints:
         print "   \"vk%s\\0\"" % name
         offsets.append(i)
@@ -247,7 +252,7 @@ def main():
      */
     """)
 
-    for layer in [ "anv", "gen7", "gen75", "gen8", "gen9" ]:
+    for layer in ["anv", "gen7", "gen75", "gen8", "gen9"]:
         for type, name, args, num, h, guard in entrypoints:
             print_guard_start(guard)
             print "%s %s_%s(%s) __attribute__ ((weak));" % (type, layer, name, args)
@@ -295,8 +300,8 @@ def main():
     # uint16_t table of entry point indices. We use 0xffff to indicate an entry
     # in the hash table is empty.
 
-    map = [none for f in xrange(hash_size)]
-    collisions = [0 for f in xrange(10)]
+    map = [none] * hash_size
+    collisions = [0] * 10
     for type, name, args, num, h, guard in entrypoints:
         level = 0
         while map[h & hash_mask] != none:
@@ -312,7 +317,7 @@ def main():
     print " * size %d entries" % hash_size
     print " * collisions  entries"
     for i in xrange(10):
-        if (i == 9):
+        if i == 9:
             plus = "+"
         else:
             plus = " "
-- 
git-series 0.9.1


More information about the mesa-dev mailing list