vk/util: handful of pythonic cleanups
No functional changes. Signed-off-by: Eric Engestrom <eric@igalia.com> Reviewed-by: Jason Ekstrand <jason.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17713>
This commit is contained in:
parent
5b196716cf
commit
e4199322ee
|
@ -28,7 +28,6 @@ import argparse
|
|||
import math
|
||||
import os
|
||||
|
||||
from collections import OrderedDict, namedtuple
|
||||
from mako.template import Template
|
||||
|
||||
# Mesa-local imports must be declared in meson variable
|
||||
|
@ -595,7 +594,7 @@ U32_MASK = 2**32 - 1
|
|||
PRIME_FACTOR = 5024183
|
||||
PRIME_STEP = 19
|
||||
|
||||
class StringIntMapEntry(object):
|
||||
class StringIntMapEntry:
|
||||
def __init__(self, string, num):
|
||||
self.string = string
|
||||
self.num = num
|
||||
|
@ -611,10 +610,10 @@ class StringIntMapEntry(object):
|
|||
def round_to_pow2(x):
|
||||
return 2**int(math.ceil(math.log(x, 2)))
|
||||
|
||||
class StringIntMap(object):
|
||||
class StringIntMap:
|
||||
def __init__(self):
|
||||
self.baked = False
|
||||
self.strings = dict()
|
||||
self.strings = {}
|
||||
|
||||
def add_string(self, string, num):
|
||||
assert not self.baked
|
||||
|
|
|
@ -26,7 +26,7 @@ from collections import OrderedDict, namedtuple
|
|||
|
||||
# Mesa-local imports must be declared in meson variable
|
||||
# '{file_without_suffix}_depend_files'.
|
||||
from vk_extensions import *
|
||||
from vk_extensions import Extension, VkVersion
|
||||
|
||||
EntrypointParam = namedtuple('EntrypointParam', 'type name decl len')
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import argparse
|
||||
import copy
|
||||
import re
|
||||
import xml.etree.ElementTree as et
|
||||
|
@ -47,7 +46,7 @@ class VkVersion:
|
|||
# VK_MAKE_VERSION macro
|
||||
assert self.major < 1024 and self.minor < 1024
|
||||
assert self.patch is None or self.patch < 4096
|
||||
assert(str(self) == string)
|
||||
assert str(self) == string
|
||||
|
||||
def __str__(self):
|
||||
ver_list = [str(self.major), str(self.minor)]
|
||||
|
@ -56,14 +55,12 @@ class VkVersion:
|
|||
return '.'.join(ver_list)
|
||||
|
||||
def c_vk_version(self):
|
||||
patch = self.patch if self.patch is not None else 0
|
||||
ver_list = [str(self.major), str(self.minor), str(patch)]
|
||||
ver_list = [str(self.major), str(self.minor), str(self.patch or 0)]
|
||||
return 'VK_MAKE_VERSION(' + ', '.join(ver_list) + ')'
|
||||
|
||||
def __int_ver(self):
|
||||
# This is just an expansion of VK_VERSION
|
||||
patch = self.patch if self.patch is not None else 0
|
||||
return (self.major << 22) | (self.minor << 12) | patch
|
||||
return (self.major << 22) | (self.minor << 12) | (self.patch or 0)
|
||||
|
||||
def __gt__(self, other):
|
||||
# If only one of them has a patch version, "ignore" it by making
|
||||
|
@ -108,7 +105,6 @@ def get_all_exts_from_xml(xml):
|
|||
if 'value' in enum_elem.attrib:
|
||||
assert version is None
|
||||
version = int(enum_elem.attrib['value'])
|
||||
ext = Extension(name, version, True)
|
||||
extensions.append(Extension(name, version, True))
|
||||
|
||||
return sorted(extensions, key=extension_order)
|
||||
|
|
|
@ -24,13 +24,13 @@ COPYRIGHT = """\
|
|||
*/
|
||||
"""
|
||||
|
||||
import xml.etree.ElementTree as et
|
||||
import argparse
|
||||
|
||||
from mako.template import Template
|
||||
|
||||
# Mesa-local imports must be declared in meson variable
|
||||
# '{file_without_suffix}_depend_files'.
|
||||
from vk_extensions import *
|
||||
from vk_extensions import get_all_exts_from_xml, init_exts_from_xml
|
||||
|
||||
_TEMPLATE_H = Template(COPYRIGHT + """
|
||||
|
||||
|
@ -209,7 +209,7 @@ def gen_extensions(driver, xml_files, api_versions, max_api_version,
|
|||
init_exts_from_xml(filename, extensions, platform_defines)
|
||||
|
||||
for ext in extensions:
|
||||
assert ext.type == 'instance' or ext.type == 'device'
|
||||
assert ext.type in {'instance', 'device'}
|
||||
|
||||
template_env = {
|
||||
'driver': driver,
|
||||
|
@ -229,7 +229,7 @@ def gen_extensions(driver, xml_files, api_versions, max_api_version,
|
|||
f.write(_TEMPLATE_C.render(**template_env))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--out-c', help='Output C file.')
|
||||
parser.add_argument('--out-h', help='Output H file.')
|
||||
|
@ -246,3 +246,6 @@ if __name__ == '__main__':
|
|||
|
||||
gen_extensions('vk', args.xml_files, None, None,
|
||||
extensions, args.out_c, args.out_h)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue