mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-05 11:48:06 +02:00
asahi/genxml: add nicer error checking
avoids digging into backtraces for basic info. lot of bang for buck here. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31532>
This commit is contained in:
parent
3a0e152de2
commit
225797601b
1 changed files with 24 additions and 11 deletions
|
|
@ -441,6 +441,8 @@ class Group(object):
|
|||
v = None
|
||||
prefix = " cl[%2d] =" % index
|
||||
|
||||
lines = []
|
||||
|
||||
for contributor in word.contributors:
|
||||
field = contributor.field
|
||||
name = field.name
|
||||
|
|
@ -464,18 +466,26 @@ class Group(object):
|
|||
value = "__gen_to_groups({}, {}, {})".format(value,
|
||||
field.modifier[1], end - start + 1)
|
||||
|
||||
if field.type in ["uint", "hex", "address"]:
|
||||
s = "util_bitpack_uint(%s, %d, %d)" % \
|
||||
(value, start, end)
|
||||
elif field.type in self.parser.enums:
|
||||
s = "util_bitpack_uint(%s, %d, %d)" % \
|
||||
(value, start, end)
|
||||
if field.type in ["uint", "hex", "address", "bool"] or field.type in self.parser.enums:
|
||||
bits = (end - start + 1)
|
||||
if bits < 64:
|
||||
# Add some nicer error checking
|
||||
error = f"{self.label}::{name} out-of-bounds"
|
||||
bound = hex(1 << bits)
|
||||
|
||||
print("#ifndef NDEBUG")
|
||||
print("#ifndef __OPENCL_VERSION__")
|
||||
print(f"if (unlikely((uint64_t){value} >= {bound})) {{")
|
||||
print(f" fprintf(stderr, \"{error}, got 0x%\" PRIx64 \", max {bound}\\n\", (uint64_t) {value});")
|
||||
print(f" unreachable(\"{error}\");")
|
||||
print(f"}}")
|
||||
print("#endif")
|
||||
print("#endif")
|
||||
|
||||
s = f"util_bitpack_uint({value}, {start}, {end})"
|
||||
elif field.type == "int":
|
||||
s = "util_bitpack_sint(%s, %d, %d)" % \
|
||||
(value, start, end)
|
||||
elif field.type == "bool":
|
||||
s = "util_bitpack_uint(%s, %d, %d)" % \
|
||||
(value, start, end)
|
||||
elif field.type == "float":
|
||||
assert(start == 0 and end == 31)
|
||||
s = "util_bitpack_float({})".format(value)
|
||||
|
|
@ -494,11 +504,14 @@ class Group(object):
|
|||
s = "%s >> %d" % (s, shift)
|
||||
|
||||
if contributor == word.contributors[-1]:
|
||||
print("%s %s;" % (prefix, s))
|
||||
lines.append("%s %s;" % (prefix, s))
|
||||
else:
|
||||
print("%s %s |" % (prefix, s))
|
||||
lines.append("%s %s |" % (prefix, s))
|
||||
prefix = " "
|
||||
|
||||
for ln in lines:
|
||||
print(ln)
|
||||
|
||||
continue
|
||||
|
||||
# Given a field (start, end) contained in word `index`, generate the 32-bit
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue