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

@ -44,8 +44,8 @@ class Registry:
def serialise(self, platform: Set[str]):
required = []
for (_,f) in self.features.items():
required += f.apply(reg)
for (_, f) in self.features.items():
required += f.apply(self)
required.append(f.name)
for e in self.extensions:
@ -84,7 +84,7 @@ class Type(object):
def declare(self):
return ""
def define(self,reg):
def define(self, reg: Registry):
return ""
@ -695,7 +695,7 @@ def parse_commands(reg: Registry, root):
def parse_feature(reg: Registry, root):
assert root.tag == 'feature'
name = node.attrib['name']
name = root.attrib['name']
assert name not in reg.features
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:
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:
commands = [i for i in q if isinstance(i, Command)]
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:
dispatch.write("""
#include "../vk.hpp"
@ -884,7 +884,7 @@ import argparse
##-----------------------------------------------------------------------------
if __name__ == '__main__':
def main():
logging.getLogger().setLevel(logging.WARNING)
parser = argparse.ArgumentParser(description='Transform XML API specification into C++ headers')
@ -935,6 +935,10 @@ if __name__ == '__main__':
q = reg.serialise(args.platform)
# Finally write out the header, icd, and dispatch code.
write_header(args.dst, q)
write_icd(args.icd, q)
write_dispatch(args.dispatch, q)
write_header(args.dst, q, reg)
write_icd(args.icd, q, reg)
write_dispatch(args.dispatch, q, reg)
##-----------------------------------------------------------------------------
if __name__ == '__main__':
main()