diff --git a/tools/spec.py b/tools/spec.py index ca2a1d8..c52a8ae 100644 --- a/tools/spec.py +++ b/tools/spec.py @@ -1,9 +1,8 @@ #!/usr/bin/env python3 - +import argparse import sys import logging from typing import List, Dict, Set, TextIO -import pprint import xml.etree.ElementTree @@ -15,7 +14,7 @@ def rename(name: str): ############################################################################### class Registry: - types: Dict[str, object] = {} + types: Dict[str, 'Type'] = {} extensions: Dict = {} features: Dict = {} applied: Set = set() @@ -403,13 +402,13 @@ class Command(Type): be the same as self.name for a useful system). """ - def __init__(self, name:str, type:str, param:str, depends:List[str]): + def __init__(self, name: str, klass: str, param: str, depends: List[str]): super().__init__( name=name, depends=depends, ) - self.type = type + self.type = klass self.param = param def __repr__(self) -> str: @@ -509,9 +508,9 @@ class Require(object): # ----------------------------------------------------------------------------- class Feature(Type): - def __init__(self, name: str, requires: List[Require] = []): + def __init__(self, name: str, requires: List[Require] = None): super().__init__(name) - self.requires = requires + self.requires = requires or [] def define(self, reg: Registry): return "#define %s" % self.name @@ -569,7 +568,6 @@ class Extension(Type): ############################################################################### def ignore_node(types: Dict[str, Type], root): - types, root pass @@ -595,7 +593,7 @@ def parse_types(reg: Registry, root): reg.types[name] = AliasType(name, target) continue - category = t.attrib.get ('category') + category = t.attrib.get('category') # if we don't have a category we should have a bare type that has a # dependency on something like a header. @@ -645,7 +643,8 @@ def parse_enums(reg: Registry, root): else: owner[valuename] = Constant(node) -#------------------------------------------------------------------------------ + +# ----------------------------------------------------------------------------- def parse_param(root) -> Command.Param: assert root.tag == 'param' @@ -657,12 +656,12 @@ def parse_param(root) -> Command.Param: param = " ".join(param.split()) name = root.find('name').text - type = root.find('type').text + klass = root.find('type').text depends = [root.find('type').text] return Command.Param( name=name, - type=type, + klass=klass, param=param, depends=depends, ) @@ -711,7 +710,8 @@ def parse_require(root) -> Require: return Require(values=values, depends=depends) -##----------------------------------------------------------------------------- + +# ----------------------------------------------------------------------------- def parse_feature(reg: Registry, root): assert root.tag == 'feature' @@ -814,7 +814,7 @@ def write_load(dst: TextIO, q: List[Type], reg: Registry): """) for name, test in collections.items(): - curr = [i for i in commands if test(i, reg)] + curr = [i for i in commands if test(i, reg)] next = [i for i in commands if not test(i, reg)] commands = next @@ -1016,7 +1016,7 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry): for obj in (i for i in q if isinstance(i, Command)): inner = "" - if obj.name in [ 'vkGetInstanceProcAddr' ]: + if obj.name in ['vkGetInstanceProcAddr']: inner = """ #define FWD(NAME) \\ @@ -1026,9 +1026,12 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry): else \\ return nullptr;\\ } + #undef FWD + + #define FWD(NAME) if (!strcmp(#NAME,pName)) { return (PFN_vkVoidFunction)NAME; } MAP_INSTANCE_COMMANDS(FWD) #undef FWD - std::clog << "Missed: " << pName << '\\n'; + std::clog << "Unhooked: " << pName << '\\n'; """ dst.write(f""" @@ -1041,10 +1044,6 @@ def write_trace(dst: TextIO, q: List[Type], reg: Registry): ############################################################################### -import argparse - - -# ----------------------------------------------------------------------------- def main(): logging.getLogger().setLevel(logging.WARNING)