aboutsummaryrefslogtreecommitdiffstats
path: root/src/vulkan
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2017-09-21 08:05:25 -0700
committerJason Ekstrand <[email protected]>2017-09-22 07:47:34 -0700
commita2fa09efd353fabd66253cfffec1c7dd05322f79 (patch)
tree82fcd57d03353d4d912b772784ccc71a335a609b /src/vulkan
parent0ee868c1f63dd27fcef4e7c5994327cbf06934b1 (diff)
vulkan: enum generator: Stop using iterparse
While using iterparse is potentially a little more efficient, the Vulkan registry XML is not large and using regular element tree simplifies the parsing logic substantially. Reviewed-by: Dylan Baker <[email protected]>
Diffstat (limited to 'src/vulkan')
-rw-r--r--src/vulkan/util/gen_enum_to_str.py36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/vulkan/util/gen_enum_to_str.py b/src/vulkan/util/gen_enum_to_str.py
index e89acb94bb3..b54c740484e 100644
--- a/src/vulkan/util/gen_enum_to_str.py
+++ b/src/vulkan/util/gen_enum_to_str.py
@@ -157,32 +157,16 @@ def parse_xml(enum_factory, ext_factory, filename):
of VkEnum objects.
"""
- with open(filename, 'rb') as f:
- context = iter(et.iterparse(f, events=('start', 'end')))
-
- # This gives the root element, since goal is to iterate over the
- # elements without building a tree, this allows the root to be cleared
- # (erase the elements) after the children have been processed.
- _, root = next(context)
-
- for event, elem in context:
- if event == 'end' and elem.tag == 'enums':
- type_ = elem.attrib.get('type')
- if type_ == 'enum':
- enum = enum_factory(elem.attrib['name'])
- enum.values.extend([e.attrib['name'] for e in elem
- if e.tag == 'enum'])
- elif event == 'start' and elem.tag == 'extension':
- ext_factory(elem.attrib['name'],
- number=int(elem.attrib['number']))
- elif event == 'end' and elem.tag == 'extension':
- if elem.attrib['supported'] != 'vulkan':
- continue
- for e in elem.findall('.//enum[@extends][@offset]'):
- enum = enum_factory(e.attrib['extends'])
- enum.values.append(e.attrib['name'])
-
- root.clear()
+ xml = et.parse(filename)
+
+ for enum_type in xml.findall('./enums[@type="enum"]'):
+ enum = enum_factory(enum_type.attrib['name'])
+ for value in enum_type.findall('./enum'):
+ enum.values.append(value.attrib['name'])
+
+ for ext_elem in xml.findall('./extensions/extension[@supported="vulkan"]'):
+ ext_factory(ext_elem.attrib['name'],
+ number=int(ext_elem.attrib['number']))
def main():
parser = argparse.ArgumentParser()