Mesa (main): pvr: csbgen: Formatting pass (PEP-8 plus other minor changes)
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Jun 8 09:22:02 UTC 2022
Module: Mesa
Branch: main
Commit: 89d6a1cfe48518c9e29dd2ca6d1db3d14121d694
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=89d6a1cfe48518c9e29dd2ca6d1db3d14121d694
Author: Matt Coster <matt.coster at imgtec.com>
Date: Fri May 13 10:30:05 2022 +0100
pvr: csbgen: Formatting pass (PEP-8 plus other minor changes)
Signed-off-by: Matt Coster <matt.coster at imgtec.com>
Reviewed-by: Frank Binns <frank.binns at imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16884>
---
src/imagination/csbgen/gen_pack_header.py | 379 ++++++++++++++----------------
1 file changed, 177 insertions(+), 202 deletions(-)
diff --git a/src/imagination/csbgen/gen_pack_header.py b/src/imagination/csbgen/gen_pack_header.py
index e6df6c82b75..501caccd9df 100644
--- a/src/imagination/csbgen/gen_pack_header.py
+++ b/src/imagination/csbgen/gen_pack_header.py
@@ -36,8 +36,9 @@ import copy
import os
import textwrap
-license = """/*
- * Copyright © 2022 Imagination Technologies Ltd.
+
+MIT_LICENSE_COMMENT = """/*
+ * Copyright © %(copyright)s
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -59,7 +60,7 @@ license = """/*
* SOFTWARE.
*/"""
-pack_header = """%(license)s
+PACK_FILE_HEADER = """%(license)s
/* Enums, structures and pack functions for %(platform)s.
*
@@ -73,23 +74,26 @@ pack_header = """%(license)s
"""
+
def safe_name(name):
if not name[0].isalpha():
- name = '_' + name
+ name = "_" + name
return name
+
def num_from_str(num_str):
- if num_str.lower().startswith('0x'):
+ if num_str.lower().startswith("0x"):
return int(num_str, base=16)
- if num_str.startswith('0') and len(num_str) > 1:
- raise ValueError('Octal numbers not allowed')
+ if num_str.startswith("0") and len(num_str) > 1:
+ raise ValueError("Octal numbers not allowed")
return int(num_str)
+
class Node:
- def __init__(self, parent, name, name_is_safe = False):
+ def __init__(self, parent, name, name_is_safe=False):
self.parent = parent
if name_is_safe:
self.name = name
@@ -98,7 +102,7 @@ class Node:
@property
def full_name(self):
- if self.name[0] == '_':
+ if self.name[0] == "_":
return self.parent.prefix + self.name.upper()
return self.parent.prefix + "_" + self.name.upper()
@@ -107,6 +111,7 @@ class Node:
def prefix(self):
return self.parent.prefix
+
class Csbgen(Node):
def __init__(self, name, prefix, filename):
super().__init__(None, name.upper())
@@ -128,31 +133,32 @@ class Csbgen(Node):
def add(self, element):
if isinstance(element, Enum):
if element.name in self._enums:
- raise RuntimeError('Enum redefined. Enum: %s' % element.name)
+ raise RuntimeError("Enum redefined. Enum: %s" % element.name)
self._enums[element.name] = element
elif isinstance(element, Struct):
if element.name in self._structs:
- raise RuntimeError('Struct redefined. Struct: %s' % element.name)
+ raise RuntimeError("Struct redefined. Struct: %s" % element.name)
self._structs[element.name] = element
elif isinstance(element, Define):
define_names = map(lambda d: d.full_name, self._defines)
if element.full_name in define_names:
- raise RuntimeError('Define redefined. Define: %s' % element.full_name)
+ raise RuntimeError("Define redefined. Define: %s" % element.full_name)
self._defines.append(element)
else:
- raise RuntimeError('Element "%s" cannot be nested in csbgen.' %
- type(element).__name__)
+ raise RuntimeError("Element '%s' cannot be nested in csbgen." % type(element).__name__)
def _gen_guard(self):
- return os.path.basename(self.filename).replace('.xml', '_h').upper()
+ return os.path.basename(self.filename).replace(".xml", "_h").upper()
def emit(self):
- print(pack_header % {'license': license,
- 'platform': self.name,
- 'guard': self._gen_guard()})
+ print(PACK_FILE_HEADER % {
+ "license": MIT_LICENSE_COMMENT % {"copyright": "2022 Imagination Technologies Ltd."},
+ "platform": self.name,
+ "guard": self._gen_guard(),
+ })
for define in self._defines:
define.emit(self)
@@ -165,7 +171,7 @@ class Csbgen(Node):
for struct in self._structs.values():
struct.emit(self)
- print('#endif /* %s */' % self._gen_guard())
+ print("#endif /* %s */" % self._gen_guard())
def is_known_struct(self, struct_name):
return struct_name in self._structs.keys()
@@ -176,6 +182,7 @@ class Csbgen(Node):
def get_enum(self, enum_name):
return self._enums[enum_name]
+
class Enum(Node):
def __init__(self, parent, name):
super().__init__(parent, name)
@@ -194,24 +201,24 @@ class Enum(Node):
def add(self, element):
if not isinstance(element, Value):
- raise RuntimeError('Element cannot be nested in enum. ' +
- 'Element Type: %s, Enum: %s' %
- (type(element).__name__, self.full_name))
+ raise RuntimeError("Element cannot be nested in enum. Element Type: %s, Enum: %s"
+ % (type(element).__name__, self.full_name))
if element.name in self._values:
- raise RuntimeError('Value is being redefined. Value: "%s"' % element.name)
+ raise RuntimeError("Value is being redefined. Value: '%s'" % element.name)
self._values[element.name] = element
def emit(self, root):
# This check is invalid if tags other than Value can be nested within an enum.
if not self._values.values():
- raise RuntimeError('Enum definition is empty. Enum: "%s"' % self.full_name)
+ raise RuntimeError("Enum definition is empty. Enum: '%s'" % self.full_name)
- print('enum %s {' % self.full_name)
+ print("enum %s {" % self.full_name)
for value in self._values.values():
value.emit()
- print('};\n')
+ print("};\n")
+
class Value(Node):
def __init__(self, parent, name, value):
@@ -222,7 +229,8 @@ class Value(Node):
self.parent.add(self)
def emit(self):
- print(' %-36s = %6d,' % (self.full_name, self.value))
+ print(" %-36s = %6d," % (self.full_name, self.value))
+
class Struct(Node):
def __init__(self, parent, name, length):
@@ -232,8 +240,7 @@ class Struct(Node):
self.size = self.length * 32
if self.length <= 0:
- raise ValueError('Struct length must be greater than 0. ' +
- 'Struct: "%s".' % self.full_name)
+ raise ValueError("Struct length must be greater than 0. Struct: '%s'." % self.full_name)
self._children = {}
@@ -260,9 +267,8 @@ class Struct(Node):
# We don't support conditions and field having the same name.
if isinstance(element, Field):
if element.name in self._children.keys():
- raise ValueError('Field is being redefined. ' +
- 'Field: "%s", Struct: "%s"' %
- (element.name, self.full_name))
+ raise ValueError("Field is being redefined. Field: '%s', Struct: '%s'"
+ % (element.name, self.full_name))
self._children[element.name] = element
@@ -270,52 +276,50 @@ class Struct(Node):
# We only save ifs, and ignore the rest. The rest will be linked to
# the if condition so we just need to call emit() on the if and the
# rest will also be emitted.
- if element.type == 'if':
+ if element.type == "if":
self._children[element.name] = element
else:
if element.name not in self._children.keys():
- raise RuntimeError('Unknown condition: "%s"' % element.name)
+ raise RuntimeError("Unknown condition: '%s'" % element.name)
else:
- raise RuntimeError('Element cannot be nested in struct. ' +
- 'Element Type: %s, Struct: %s' %
- (type(element).__name__, self.full_name))
+ raise RuntimeError("Element cannot be nested in struct. Element Type: %s, Struct: %s"
+ % (type(element).__name__, self.full_name))
def _emit_header(self, root):
- fields = filter(lambda f: hasattr(f, 'default'), self.fields)
+ fields = filter(lambda f: hasattr(f, "default"), self.fields)
default_fields = []
for field in fields:
if field.is_builtin_type:
- default_fields.append(" .%-35s = %6d" %
- (field.name, field.default))
+ default_fields.append(" .%-35s = %6d" % (field.name, field.default))
else:
if not root.is_known_enum(field.type):
# Default values should not apply to structures
- raise RuntimeError('Unknown type. Field: "%s" Type: "%s"' %
- (field.name, field.type))
+ raise RuntimeError(
+ "Unknown type. Field: '%s' Type: '%s'"
+ % (field.name, field.type)
+ )
enum = root.get_enum(field.type)
try:
value = enum.get_value(field.default)
except KeyError:
- raise ValueError('Unknown enum value. ' +
- 'Value: "%s", Enum: "%s", Field: "%s"' %
- (field.default, enum.full_name, field.name))
+ raise ValueError("Unknown enum value. Value: '%s', Enum: '%s', Field: '%s'"
+ % (field.default, enum.full_name, field.name))
- default_fields.append(" .%-35s = %s" %
- (field.name, value.full_name))
+ default_fields.append(" .%-35s = %s" % (field.name, value.full_name))
- print('#define %-40s\\' % (self.full_name + '_header'))
+ print("#define %-40s\\" % (self.full_name + "_header"))
print(", \\\n".join(default_fields))
- print('')
+ print("")
def _emit_helper_macros(self, root):
fields_with_defines = filter(lambda f: f.defines, self.fields)
for field in fields_with_defines:
- print("/* Helper macros for %s */" % (field.name))
+ print("/* Helper macros for %s */" % field.name)
for define in field.defines:
define.emit(root)
@@ -330,7 +334,7 @@ class Struct(Node):
{""") % (self.full_name, ' ' * len(self.full_name), self.full_name))
group = Group(0, 1, self.size, self.fields)
- (dwords, length) = group.collect_dwords_and_length()
+ dwords, length = group.collect_dwords_and_length()
if length:
# Cast dst to make header C++ friendly
print(" uint32_t * restrict dw = (uint32_t * restrict) dst;")
@@ -339,9 +343,8 @@ class Struct(Node):
print("}\n")
-
def emit(self, root):
- print('#define %-33s %6d' % (self.full_name + "_length", self.length))
+ print("#define %-33s %6d" % (self.full_name + "_length", self.length))
self._emit_header(root)
@@ -349,31 +352,30 @@ class Struct(Node):
print("struct %s {" % self.full_name)
for child in self._children.values():
- child.emit(root)
+ child.emit(root)
print("};\n")
self._emit_pack_function(root)
+
class Field(Node):
- def __init__(self, parent, name, start, end, type, default=None, shift=None):
+ def __init__(self, parent, name, start, end, ty, default=None, shift=None):
super().__init__(parent, name)
self.start = int(start)
self.end = int(end)
- self.type = type
+ self.type = ty
self._defines = {}
self.parent.add(self)
if self.start > self.end:
- raise ValueError('Start cannot be after end. ' +
- 'Start: %d, End: %d, Field: "%s"' %
- (self.start, self.end, self.name))
+ raise ValueError("Start cannot be after end. Start: %d, End: %d, Field: '%s'"
+ % (self.start, self.end, self.name))
- if self.type == 'bool' and self.end != self.start:
- raise ValueError('Bool field can only be 1 bit long. ' +
- 'Field "%s"' % self.name)
+ if self.type == "bool" and self.end != self.start:
+ raise ValueError("Bool field can only be 1 bit long. Field '%s'" % self.name)
if default is not None:
if not self.is_builtin_type:
@@ -383,18 +385,15 @@ class Field(Node):
self.default = num_from_str(default)
if shift is not None:
- if self.type != 'address':
- raise RuntimeError('Only address fields can have a shift ' +
- 'attribute. Field: "%s"' % self.name)
+ if self.type != "address":
+ raise RuntimeError("Only address fields can have a shift attribute. Field: '%s'" % self.name)
self.shift = int(shift)
- Define(self, "ALIGNMENT", 2 ** self.shift)
+ Define(self, "ALIGNMENT", 2**self.shift)
else:
- if self.type == 'address':
- raise RuntimeError('Field of address type ' +
- 'requires a shift attribute. Field "%s"' %
- self.name)
+ if self.type == "address":
+ raise RuntimeError("Field of address type requires a shift attribute. Field '%s'" % self.name)
@property
def defines(self):
@@ -407,59 +406,55 @@ class Field(Node):
@property
def is_builtin_type(self):
- builtins = {'address', 'bool', 'float', 'mbo', 'offset', 'int', 'uint'}
+ builtins = {"address", "bool", "float", "mbo", "offset", "int", "uint"}
return self.type in builtins
def _get_c_type(self, root):
- if self.type == 'address':
- return '__pvr_address_type'
- elif self.type == 'bool':
- return 'bool'
- elif self.type == 'float':
- return 'float'
- elif self.type == 'offset':
- return 'uint64_t'
- elif self.type == 'int':
- return 'int32_t'
- elif self.type == 'uint':
+ if self.type == "address":
+ return "__pvr_address_type"
+ elif self.type == "bool":
+ return "bool"
+ elif self.type == "float":
+ return "float"
+ elif self.type == "offset":
+ return "uint64_t"
+ elif self.type == "int":
+ return "int32_t"
+ elif self.type == "uint":
if self.end - self.start < 32:
- return 'uint32_t'
- elif self.end - self.self < 64:
- return 'uint64_t'
+ return "uint32_t"
+ elif self.end - self.start < 64:
+ return "uint64_t"
- raise RuntimeError('No known C type found to hold %d bit sized value. ' +
- 'Field: "%s"' %
- (self.end - self.start, self.name))
+ raise RuntimeError("No known C type found to hold %d bit sized value. Field: '%s'"
+ % (self.end - self.start, self.name))
elif root.is_known_struct(self.type):
- return 'struct ' + self.type
+ return "struct " + self.type
elif root.is_known_enum(self.type):
- return 'enum ' + root.get_enum(self.type).full_name
- raise RuntimeError('Unknown type. Type: "%s", Field: "%s"' %
- (self.type, self.name))
+ return "enum " + root.get_enum(self.type).full_name
+ raise RuntimeError("Unknown type. Type: '%s', Field: '%s'" % (self.type, self.name))
def add(self, element):
- if self.type == 'mbo':
- raise RuntimeError('No element can be nested in an mbo field. ' +
- 'Element Type: %s, Field: %s' %
- (type(element).__name__, self.name))
+ if self.type == "mbo":
+ raise RuntimeError("No element can be nested in an mbo field. Element Type: %s, Field: %s"
+ % (type(element).__name__, self.name))
if isinstance(element, Define):
if element.name in self._defines:
- raise RuntimeError('Duplicate define. Define: "%s"' %
- element.name)
+ raise RuntimeError("Duplicate define. Define: '%s'" % element.name)
self._defines[element.name] = element
else:
- raise RuntimeError('Element cannot be nested in a field. ' +
- 'Element Type: %s, Field: %s' %
- (type(element).__name__, self.name))
+ raise RuntimeError("Element cannot be nested in a field. Element Type: %s, Field: %s"
+ % (type(element).__name__, self.name))
def emit(self, root):
- if self.type == 'mbo':
+ if self.type == "mbo":
return
print(" %-36s %s;" % (self._get_c_type(root), self.name))
+
class Define(Node):
def __init__(self, parent, name, value):
super().__init__(parent, name)
@@ -471,13 +466,14 @@ class Define(Node):
def emit(self, root):
print("#define %-40s %d" % (self.full_name, self.value))
+
class Condition(Node):
- def __init__(self, parent, name, type):
- super().__init__(parent, name, name_is_safe = True)
+ def __init__(self, parent, name, ty):
+ super().__init__(parent, name, name_is_safe=True)
- self.type = type
+ self.type = ty
if not Condition._is_valid_type(self.type):
- raise RuntimeError('Unknown type: "%s"' % self.name)
+ raise RuntimeError("Unknown type: '%s'" % self.name)
self._children = {}
@@ -509,24 +505,22 @@ class Condition(Node):
return fields
- def _is_valid_type(type):
- types = {'if', 'elif', 'else', 'endif'}
- return type in types
+ def _is_valid_type(ty):
+ types = {"if", "elif", "else", "endif"}
+ return ty in types
def _is_compatible_child_branch(self, branch):
- types = ['if', 'elif', 'else', 'endif']
+ types = ["if", "elif", "else", "endif"]
idx = types.index(self.type)
return (branch.type in types[idx + 1:] or
- self.type == 'elif' and branch.type == 'elif')
+ self.type == "elif" and branch.type == "elif")
def _add_branch(self, branch):
- if branch.type == 'elif' and branch.name == self.name:
- raise RuntimeError('Elif branch cannot have same check as previous branch. ' +
- 'Check: "%s"' % (branch.name))
+ if branch.type == "elif" and branch.name == self.name:
+ raise RuntimeError("Elif branch cannot have same check as previous branch. Check: '%s'" % branch.name)
if not self._is_compatible_child_branch(branch):
- raise RuntimeError('Invalid branch. Check: "%s", Type: "%s"' %
- (branch.name, branch.type))
+ raise RuntimeError("Invalid branch. Check: '%s', Type: '%s'" % (branch.name, branch.type))
self._child_branch = branch
@@ -541,7 +535,7 @@ class Condition(Node):
# just save the name of the if instead of having to walk towards it whenever
# a new condition is being added.
def _top_branch_name(self):
- if self.type == 'if':
+ if self.type == "if":
return self.name
return self.parent._top_branch_name()
@@ -549,16 +543,16 @@ class Condition(Node):
def add(self, element):
if isinstance(element, Field):
if element.name in self._children.keys():
- raise ValueError('Duplicate field. Field: "%s"' % element.name)
+ raise ValueError("Duplicate field. Field: '%s'" % element.name)
self._children[element.name] = element
elif isinstance(element, Condition):
- if element.type == 'elif' or self._top_branch_name() == element.name:
+ if element.type == "elif" or self._top_branch_name() == element.name:
self._add_branch(element)
else:
- if element.type != 'if':
- raise RuntimeError('Branch of an unopened if condition. ' +
- 'Check: "%s", Type: "%s".' % (element.name, element.type))
+ if element.type != "if":
+ raise RuntimeError("Branch of an unopened if condition. Check: '%s', Type: '%s'."
+ % (element.name, element.type))
# This is a nested condition and we made sure that the name
# doesn't match _top_branch_name() so we can recognize the else
@@ -581,33 +575,32 @@ class Condition(Node):
# We fix this by checking the if condition name against its
# parent.
if element.name == self.name:
- raise RuntimeError('Invalid if condition. Check: "%s"' %
- element.name)
+ raise RuntimeError("Invalid if condition. Check: '%s'" % element.name)
self._children[element.name] = element
else:
- raise RuntimeError('Element cannot be nested in a condition. ' +
- 'Element Type: %s, Check: %s' %
- (type(element).__name__, self.name))
+ raise RuntimeError("Element cannot be nested in a condition. Element Type: %s, Check: %s"
+ % (type(element).__name__, self.name))
def emit(self, root):
if self.type == "if":
- print("/* if %s is supported use: */" % (self.name))
+ print("/* if %s is supported use: */" % self.name)
elif self.type == "elif":
- print("/* else if %s is supported use: */" % (self.name))
+ print("/* else if %s is supported use: */" % self.name)
elif self.type == "else":
- print("/* else %s is not-supported use: */" % (self.name))
+ print("/* else %s is not-supported use: */" % self.name)
elif self.type == "endif":
- print("/* endif %s */" % (self.name))
+ print("/* endif %s */" % self.name)
return
else:
- raise RuntimeError('Unknown condition type. Implementation error.')
+ raise RuntimeError("Unknown condition type. Implementation error.")
for child in self._children.values():
child.emit(root)
self._child_branch.emit(root)
+
class Group(object):
def __init__(self, start, count, size, fields):
self.start = start
@@ -642,8 +635,7 @@ class Group(object):
# and address and a few bits) or where a single struct field
# completely covers multiple dwords.
while index < (start + field.end) // 32:
- if index + 1 in dwords and \
- not dwords[index] == dwords[index + 1]:
+ if index + 1 in dwords and not dwords[index] == dwords[index + 1]:
dwords[index].fields.extend(dwords[index + 1].fields)
dwords[index].addresses.extend(dwords[index + 1].addresses)
dwords[index].size = 64
@@ -665,7 +657,7 @@ class Group(object):
else:
length = 0
- return (dwords, length)
+ return dwords, length
def emit_pack_function(self, root, dwords, length):
for index in range(length):
@@ -691,9 +683,8 @@ class Group(object):
name = field.name + field.dim
if root.is_known_struct(field.type) and field.start % 32 == 0:
print("")
- print(" %s_pack(data, &dw[%d], &values->%s);" %
- (self.parser.gen_prefix(safe_name(field.type)),
- index, name))
+ print(" %s_pack(data, &dw[%d], &values->%s);"
+ % (self.parser.gen_prefix(safe_name(field.type)), index, name))
continue
# Pack any fields of struct type first so we have integer values
@@ -704,14 +695,13 @@ class Group(object):
name = field.name + field.dim
print("")
print(" uint32_t v%d_%d;" % (index, field_index))
- print(" %s_pack(data, &v%d_%d, &values->%s);" %
- (self.parser.gen_prefix(safe_name(field.type)),
- index, field_index, name))
+ print(" %s_pack(data, &v%d_%d, &values->%s);"
+ % (self.parser.gen_prefix(safe_name(field.type)), index, field_index, name))
field_index = field_index + 1
print("")
dword_start = index * 32
- address_count = len(dw.addresses);
+ address_count = len(dw.addresses)
if dw.size == 32 and not dw.addresses:
v = None
@@ -729,75 +719,62 @@ class Group(object):
name = field.name + field.dim
if field.type == "mbo":
- non_address_fields.append("__pvr_mbo(%d, %d)" %
- (field.start - dword_start,
- field.end - dword_start))
+ non_address_fields.append("__pvr_mbo(%d, %d)"
+ % (field.start - dword_start, field.end - dword_start))
elif field.type == "address":
pass
elif field.type == "uint":
- non_address_fields.append("__pvr_uint(values->%s, %d, %d)" %
- (name, field.start - dword_start,
- field.end - dword_start))
+ non_address_fields.append("__pvr_uint(values->%s, %d, %d)"
+ % (name, field.start - dword_start, field.end - dword_start))
elif root.is_known_enum(field.type):
- non_address_fields.append("__pvr_uint(values->%s, %d, %d)" %
- (name, field.start - dword_start,
- field.end - dword_start))
+ non_address_fields.append("__pvr_uint(values->%s, %d, %d)"
+ % (name, field.start - dword_start, field.end - dword_start))
elif field.type == "int":
- non_address_fields.append("__pvr_sint(values->%s, %d, %d)" %
- (name, field.start - dword_start,
- field.end - dword_start))
+ non_address_fields.append("__pvr_sint(values->%s, %d, %d)"
+ % (name, field.start - dword_start, field.end - dword_start))
elif field.type == "bool":
- non_address_fields.append("__pvr_uint(values->%s, %d, %d)" %
- (name, field.start - dword_start,
- field.end - dword_start))
+ non_address_fields.append("__pvr_uint(values->%s, %d, %d)"
+ % (name, field.start - dword_start, field.end - dword_start))
elif field.type == "float":
non_address_fields.append("__pvr_float(values->%s)" % name)
elif field.type == "offset":
- non_address_fields.append(
- "__pvr_offset(values->%s,"" %d, %d)" %
- (name, field.start - dword_start,
- field.end - dword_start))
+ non_address_fields.append("__pvr_offset(values->%s, %d, %d)"
+ % (name, field.start - dword_start, field.end - dword_start))
elif field.is_struct_type():
- non_address_fields.append("__pvr_uint(v%d_%d, %d, %d)" %
- (index, field_index,
- field.start - dword_start,
- field.end - dword_start))
+ non_address_fields.append("__pvr_uint(v%d_%d, %d, %d)"
+ % (index, field_index, field.start - dword_start,
+ field.end - dword_start))
field_index = field_index + 1
else:
- non_address_fields.append("/* unhandled field %s,"
- " type %s */\n" %
- (name, field.type))
+ non_address_fields.append(
+ "/* unhandled field %s," " type %s */\n" % (name, field.type)
+ )
if non_address_fields:
- print(" |\n".join(" " + f for f in non_address_fields) +
- ";")
+ print(" |\n".join(" " + f for f in non_address_fields) + ";")
if dw.size == 32:
for i in range(address_count):
- print(" dw[%d] = __pvr_address("
- "values->%s, %d, %d, %d) | %s;" %
- (index, dw.addresses[i].name + field.dim,
- dw.addresses[i].shift, dw.addresses[i].start - dword_start,
- dw.addresses[i].end - dword_start, v))
+ print(" dw[%d] = __pvr_address(values->%s, %d, %d, %d) | %s;"
+ % (index, dw.addresses[i].name + field.dim, dw.addresses[i].shift,
+ dw.addresses[i].start - dword_start, dw.addresses[i].end - dword_start, v))
continue
v_accumulated_addr = ""
for i in range(address_count):
v_address = "v%d_address" % i
v_accumulated_addr += "v%d_address" % i
- print(" const uint64_t %s =\n "
- " __pvr_address(values->%s, %d, %d, %d);" %
- (v_address, dw.addresses[i].name + field.dim, dw.addresses[i].shift,
- dw.addresses[i].start - dword_start,
- dw.addresses[i].end - dword_start))
+ print(" const uint64_t %s =" % v_address)
+ print(" __pvr_address(values->%s, %d, %d, %d);"
+ % (dw.addresses[i].name + field.dim, dw.addresses[i].shift,
+ dw.addresses[i].start - dword_start, dw.addresses[i].end - dword_start))
if i < (address_count - 1):
v_accumulated_addr += " |\n "
if dw.addresses:
if len(dw.fields) > address_count:
print(" dw[%d] = %s | %s;" % (index, v_accumulated_addr, v))
- print(" dw[%d] = (%s >> 32) | (%s >> 32);" %
- (index + 1, v_accumulated_addr, v))
+ print(" dw[%d] = (%s >> 32) | (%s >> 32);" % (index + 1, v_accumulated_addr, v))
continue
else:
v = v_accumulated_addr
@@ -805,6 +782,7 @@ class Group(object):
print(" dw[%d] = %s;" % (index, v))
print(" dw[%d] = %s >> 32;" % (index + 1, v))
+
class Parser(object):
def __init__(self):
self.parser = xml.parsers.expat.ParserCreate()
@@ -819,14 +797,16 @@ class Parser(object):
if name == "csbgen":
if self.context:
- raise RuntimeError('Can only have 1 csbgen block and it has ' +
- 'to contain all of the other elements.')
+ raise RuntimeError(
+ "Can only have 1 csbgen block and it has "
+ + "to contain all of the other elements."
+ )
csbgen = Csbgen(attrs["name"], attrs["prefix"], self.filename)
self.context.append(csbgen)
elif name == "struct":
- struct = Struct(parent , attrs["name"], attrs["length"])
+ struct = Struct(parent, attrs["name"], attrs["length"])
self.context.append(struct)
elif name == "field":
@@ -838,13 +818,8 @@ class Parser(object):
if "shift" in attrs.keys():
shift = attrs["shift"]
- field = Field(parent,
- name = attrs["name"],
- start = int(attrs["start"]),
- end = int(attrs["end"]),
- type = attrs["type"],
- default = default,
- shift = shift)
+ field = Field(parent, name=attrs["name"], start=int(attrs["start"]), end=int(attrs["end"]),
+ ty=attrs["type"], default=default, shift=shift)
self.context.append(field)
elif name == "enum":
@@ -860,7 +835,7 @@ class Parser(object):
self.context.append(define)
elif name == "condition":
- condition = Condition(parent, name=attrs["check"], type=attrs["type"])
+ condition = Condition(parent, name=attrs["check"], ty=attrs["type"])
# Starting with the if statement we push it in the context. For each
# branch following (elif, and else) we assign the top of stack as
@@ -869,23 +844,23 @@ class Parser(object):
# it's not supposed to have any children and it's supposed to close
# the whole if statement.
- if condition.type != 'if':
+ if condition.type != "if":
# Remove the parent condition from the context. We were peeking
# before, now we pop().
self.context.pop()
- if condition.type == 'endif':
+ if condition.type == "endif":
if not isinstance(parent, Condition):
- raise RuntimeError('Cannot close unopened or already ' +
- 'closed condition. Condition: "%s"' % condition.name)
+ raise RuntimeError("Cannot close unopened or already closed condition. Condition: '%s'"
+ % condition.name)
else:
self.context.append(condition)
else:
- raise RuntimeError('Unknown tag: "%s"' % name)
+ raise RuntimeError("Unknown tag: '%s'" % name)
def end_element(self, name):
- if name == 'condition':
+ if name == "condition":
element = self.context[-1]
if not isinstance(element, Condition) and not isinstance(element, Struct):
raise RuntimeError("Expected condition or struct tag to be closed.")
@@ -911,12 +886,11 @@ class Parser(object):
raise RuntimeError("Expected define tag to be closed.")
elif name == "csbgen":
if not isinstance(element, Csbgen):
- raise RuntimeError("""Expected csbgen tag to be closed.
- Some tags may have not been closed""")
+ raise RuntimeError("Expected csbgen tag to be closed.\nSome tags may have not been closed")
element.emit()
else:
- raise RuntimeError('Unknown closing element: "%s"' % name)
+ raise RuntimeError("Unknown closing element: '%s'" % name)
def parse(self, filename):
file = open(filename, "rb")
@@ -924,6 +898,7 @@ class Parser(object):
self.parser.ParseFile(file)
file.close()
+
if len(sys.argv) < 2:
print("No input xml file specified")
sys.exit(1)
More information about the mesa-commit
mailing list