mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 03:39:52 +00:00
Merge commit '263284f' into task/215-m27
This commit is contained in:
commit
980436a963
5 files changed
+82
-7
No files matched your search
@@ -806,9 +806,10 @@ def _well_formed(rule):
|
||||
)
|
||||
|
||||
|
||||
def variant_row(registry, variant):
|
||||
def variant_row(registry, variant, base=None):
|
||||
"""The base form re-encoded: its declaration with the variant's identity."""
|
||||
base = next(form for form in registry["form"] if form.get("name") == variant["of"])
|
||||
if base is None:
|
||||
base = next(form for form in registry["form"] if form.get("name") == variant["of"])
|
||||
return dict(
|
||||
base, family=variant["family"], opcode=variant["opcode"], operands=variant["operands"],
|
||||
spec=variant["spec"], verify=variant["verify"],
|
||||
@@ -881,7 +882,9 @@ def _check_variants(registry, rules, documents, snapshot, seen, errors):
|
||||
if FORM_KEYS - set(base):
|
||||
errors.append(f"{label}: not checked, its form {variant['of']} is incomplete")
|
||||
continue
|
||||
_check_xml(variant_row(registry, variant), rule, snapshot, errors)
|
||||
# The same base row as the completeness check above (with duplicate
|
||||
# declarations, the dict keeps the last one).
|
||||
_check_xml(variant_row(registry, variant, base), rule, snapshot, errors)
|
||||
# Every explicit operand, destination included, has the base encoding's
|
||||
# data format, in the same order (VSRC1 of VOP2 is SRC1 of VOP3).
|
||||
base_xml = snapshot["variants"].get((base["name"], _family_encoding(base["family"])))
|
||||
|
||||
@@ -182,11 +182,15 @@ def read_declarations(registry, identified):
|
||||
# An encoding variant declares its base form in another encoding family.
|
||||
raw_variants = registry.get("encoding_variant", [])
|
||||
if not isinstance(raw_variants, list) or not all(
|
||||
isinstance(variant, dict) and {"family", "of", "opcode", "operands"} <= set(variant)
|
||||
isinstance(variant, dict)
|
||||
and {"family", "of", "opcode", "operands"} <= set(variant)
|
||||
and all(isinstance(variant[key], str) for key in ("family", "of", "operands"))
|
||||
and type(variant["opcode"]) is int
|
||||
for variant in raw_variants
|
||||
):
|
||||
raise ValueError(
|
||||
f"{REGISTRY}: every encoding_variant needs family, of, opcode and operands"
|
||||
f"{REGISTRY}: every encoding_variant needs string family, of and operands"
|
||||
" and an integer opcode"
|
||||
)
|
||||
variants = [
|
||||
{"family": variant["family"], "name": variant["of"], "opcode": variant["opcode"],
|
||||
|
||||
+12
-2
@@ -172,7 +172,12 @@ def main(argv: list[str] | None = None) -> int:
|
||||
if args.command == "rdna2" and args.action == "rank":
|
||||
from .rdna2_rank import run_rank
|
||||
|
||||
return run_rank(_root(), args)
|
||||
try:
|
||||
return run_rank(_root(), args)
|
||||
except ValueError as exc:
|
||||
# A malformed registry is a diagnostic, not a traceback.
|
||||
print(f"rdna2: {exc}", file=sys.stderr)
|
||||
return 2
|
||||
if args.command == "rdna2" and args.no_float:
|
||||
r.error("--no-float requires the rank action")
|
||||
root = _root()
|
||||
@@ -263,7 +268,12 @@ def main(argv: list[str] | None = None) -> int:
|
||||
else:
|
||||
print(json.dumps(payload, indent=2, sort_keys=True))
|
||||
return 0
|
||||
data = load_inventories(root)
|
||||
try:
|
||||
data = load_inventories(root)
|
||||
except ValueError as exc:
|
||||
# A malformed registry is a diagnostic, not a traceback.
|
||||
print(f"rdna2: {exc}", file=sys.stderr)
|
||||
return 2
|
||||
inv = summarize_inventory(data)
|
||||
exclude_families: list[str] = []
|
||||
claimed_paths: list[str] = []
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
"""A malformed encoding variant gives the planner a diagnostic, not a traceback."""
|
||||
|
||||
import contextlib
|
||||
import io
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
import qa.__main__ as cli
|
||||
from qa import rdna2_plan
|
||||
from audit import semantic_coverage as coverage
|
||||
|
||||
|
||||
def malformed_loader(variant):
|
||||
def load(_root):
|
||||
registry = {
|
||||
"schema": 1,
|
||||
"form": [{"family": "SOP2", "name": "S_ADD_U32", "opcode": 0,
|
||||
"operands": "scalar", "verify": ["reference"]}],
|
||||
"operand_rules": {"scalar": {"family": "SOP2", "unsupported": ["two_literals"]}},
|
||||
"encoding_variant": [variant],
|
||||
}
|
||||
# The real reader, as load_inventories uses it.
|
||||
coverage.read_declarations(registry, {("SOP2", "S_ADD_U32"): 0})
|
||||
raise AssertionError("the malformed variant was accepted")
|
||||
|
||||
return load
|
||||
|
||||
|
||||
class MalformedVariant(unittest.TestCase):
|
||||
def test_inventory_and_rank_report_registry_errors(self):
|
||||
variants = {
|
||||
"missing of": {"family": "VOP3", "opcode": 1, "operands": "x"},
|
||||
"list operands": {"family": "VOP3", "of": "S_ADD_U32", "opcode": 1, "operands": []},
|
||||
}
|
||||
for action in ("inventory", "rank"):
|
||||
for name, variant in variants.items():
|
||||
with self.subTest(action=action, variant=name):
|
||||
stderr = io.StringIO()
|
||||
loader = malformed_loader(variant)
|
||||
with mock.patch.object(cli, "load_inventories", loader), \
|
||||
mock.patch.object(rdna2_plan, "load_inventories", loader), \
|
||||
contextlib.redirect_stderr(stderr), contextlib.redirect_stdout(io.StringIO()):
|
||||
code = cli.main(["rdna2", action])
|
||||
self.assertEqual(code, 2)
|
||||
self.assertIn("encoding_variant needs", stderr.getvalue())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -964,6 +964,15 @@ class Validate(unittest.TestCase):
|
||||
self.assertTrue(any("missing ['width']" in error for error in errors), errors)
|
||||
self.assertTrue(any("is incomplete" in error for error in errors), errors)
|
||||
|
||||
def test_a_variant_of_an_incomplete_first_duplicate_is_a_diagnostic(self):
|
||||
reg = variants()
|
||||
base = next(f for f in reg["form"] if f["name"] == reg["encoding_variant"][0]["of"])
|
||||
incomplete = copy.deepcopy(base)
|
||||
del incomplete["width"]
|
||||
reg["form"].insert(reg["form"].index(base), incomplete)
|
||||
errors = self.errors(reg)
|
||||
self.assertTrue(any("missing ['width']" in error for error in errors), errors)
|
||||
|
||||
def test_a_non_array_or_non_table_variant_is_a_diagnostic(self):
|
||||
reg = variants()
|
||||
reg["encoding_variant"] = 1
|
||||
|
||||
Reference in new issue
Block a user