2 # Copyright (c) 2016 Google Inc.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 """Generates the vendor tool table from the SPIR-V XML registry."""
17 from __future__ import print_function
19 import distutils.dir_util
21 import xml.etree.ElementTree
24 def generate_vendor_table(registry):
25 """Returns a list of C style initializers for the registered vendors
29 registry: The SPIR-V XMLregistry as an xml.ElementTree
33 for ids in registry.iter('ids'):
34 if 'vendor' == ids.attrib['type']:
35 for an_id in ids.iter('id'):
36 value = an_id.attrib['value']
37 vendor = an_id.attrib['vendor']
38 if 'tool' in an_id.attrib:
39 tool = an_id.attrib['tool']
40 vendor_tool = vendor + ' ' + tool
44 line = '{' + '{}, "{}", "{}", "{}"'.format(value,
49 return '\n'.join(lines)
54 parser = argparse.ArgumentParser(description=
55 'Generate tables from SPIR-V XML registry')
56 parser.add_argument('--xml', metavar='<path>',
57 type=str, required=True,
58 help='SPIR-V XML Registry file')
59 parser.add_argument('--generator-output', metavar='<path>',
60 type=str, required=True,
61 help='output file for SPIR-V generators table')
62 args = parser.parse_args()
64 with open(args.xml) as xml_in:
65 registry = xml.etree.ElementTree.fromstring(xml_in.read())
67 distutils.dir_util.mkpath(os.path.dirname(args.generator_output))
68 print(generate_vendor_table(registry), file=open(args.generator_output, 'w'))
71 if __name__ == '__main__':