tools/spec: make main an actual function

This reduces variable shadowing across the rest of the file
This commit is contained in:
Danny Robson 2019-01-05 12:16:52 +11:00
parent 09c9ff741a
commit 06e29cb474

View File

@ -45,7 +45,7 @@ class Registry:
required = [] required = []
for (_, f) in self.features.items(): for (_, f) in self.features.items():
required += f.apply(reg) required += f.apply(self)
required.append(f.name) required.append(f.name)
for e in self.extensions: for e in self.extensions:
@ -84,7 +84,7 @@ class Type(object):
def declare(self): def declare(self):
return "" return ""
def define(self,reg): def define(self, reg: Registry):
return "" return ""
@ -695,7 +695,7 @@ def parse_commands(reg: Registry, root):
def parse_feature(reg: Registry, root): def parse_feature(reg: Registry, root):
assert root.tag == 'feature' assert root.tag == 'feature'
name = node.attrib['name'] name = root.attrib['name']
assert name not in reg.features assert name not in reg.features
reg.features[name] = Feature(root) reg.features[name] = Feature(root)
@ -714,7 +714,7 @@ def parse_extensions(reg: Registry, root):
############################################################################### ###############################################################################
def write_header(path: str, q: List[Type]): def write_header(path: str, q: List[Type], reg: Registry):
with open(path, 'w') as dst: with open(path, 'w') as dst:
dst.write("#pragma once\n") dst.write("#pragma once\n")
@ -766,7 +766,7 @@ def write_header(path: str, q: List[Type]):
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
def write_icd(path: str, q: List[Type]): def write_icd(path: str, q: List[Type], reg: Registry):
with open(path, 'w') as icd: with open(path, 'w') as icd:
commands = [i for i in q if isinstance(i, Command)] commands = [i for i in q if isinstance(i, Command)]
instance_commands = [i for i in commands if i.is_instance(reg)] instance_commands = [i for i in commands if i.is_instance(reg)]
@ -813,7 +813,7 @@ def write_icd(path: str, q: List[Type]):
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
def write_dispatch(path: str, q: List[Type]): def write_dispatch(path: str, q: List[Type], reg: Registry):
with open(path, 'w') as dispatch: with open(path, 'w') as dispatch:
dispatch.write(""" dispatch.write("""
#include "../vk.hpp" #include "../vk.hpp"
@ -884,7 +884,7 @@ import argparse
##----------------------------------------------------------------------------- ##-----------------------------------------------------------------------------
if __name__ == '__main__': def main():
logging.getLogger().setLevel(logging.WARNING) logging.getLogger().setLevel(logging.WARNING)
parser = argparse.ArgumentParser(description='Transform XML API specification into C++ headers') parser = argparse.ArgumentParser(description='Transform XML API specification into C++ headers')
@ -935,6 +935,10 @@ if __name__ == '__main__':
q = reg.serialise(args.platform) q = reg.serialise(args.platform)
# Finally write out the header, icd, and dispatch code. # Finally write out the header, icd, and dispatch code.
write_header(args.dst, q) write_header(args.dst, q, reg)
write_icd(args.icd, q) write_icd(args.icd, q, reg)
write_dispatch(args.dispatch, q) write_dispatch(args.dispatch, q, reg)
##-----------------------------------------------------------------------------
if __name__ == '__main__':
main()