From 24e5a1714f3bad5a0d7405a5d5a2f9b2120d587c Mon Sep 17 00:00:00 2001 From: RenzoWit35 <168984533+RenzoWit35@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:22:16 +0100 Subject: [PATCH] tooling: skip BOM and commented labels in scan_unsupported_shaders assembly parsing parse_assembly_file kept a UTF-8 BOM on the first line (so a file written by Windows PowerShell 5 reported '\ufeffs_endpgm' as an unknown opcode) and kept llc-style labels with a trailing comment such as 'pixel: ; @pixel' as opcodes. Open with utf-8-sig and test for a bare label after stripping the comment, using the same comment rule as extract_opcode. --- tests/rdna2_tools_check.py | 13 +++++++++++++ tools/scan_unsupported_shaders.py | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/rdna2_tools_check.py b/tests/rdna2_tools_check.py index 3641bd6de..e7bfde6c5 100644 --- a/tests/rdna2_tools_check.py +++ b/tests/rdna2_tools_check.py @@ -5023,6 +5023,19 @@ def scan(): result = scan() self.assertIn("Full Shaders Accepted by Translator: 0", result.stdout) + def test_parse_assembly_file_skips_bom_and_commented_labels(self): + """A UTF-8 BOM and llc-style commented labels are not instructions; a ':' in a comment keeps the line.""" + from scan_unsupported_shaders import parse_assembly_file + with tempfile.TemporaryDirectory() as tmp: + bom = Path(tmp) / "bom.s" + bom.write_bytes(b"\xef\xbb\xbfs_endpgm\n") + self.assertEqual(parse_assembly_file(bom), ["s_endpgm"]) + labels = Path(tmp) / "labels.s" + labels.write_text("pixel: ; @pixel\n" + ".LBB0_1: ; %bb.1\n" + "s_endpgm ; done:\n", encoding="utf-8") + self.assertEqual(parse_assembly_file(labels), ["s_endpgm ; done:"]) + def test_binary_scan_recognizes_vop1_cvt_off_sat_pack_and_swap_opcodes(self): """The scan report names the four VOP1 forms instead of listing v_vop1_NN as unknown opcodes.""" shader = bytes.fromhex( diff --git a/tools/scan_unsupported_shaders.py b/tools/scan_unsupported_shaders.py index acf8b5e8a..37d628210 100644 --- a/tools/scan_unsupported_shaders.py +++ b/tools/scan_unsupported_shaders.py @@ -751,7 +751,7 @@ def analyze_shader_instructions(shader_name: str, instructions: list[str], *, def parse_assembly_file(path: Path) -> list[str]: """Read assembly instructions from a text file (.s, .asm, .txt).""" lines = [] - with path.open("r", encoding="utf-8", errors="replace") as f: + with path.open("r", encoding="utf-8-sig", errors="replace") as f: for line in f: stripped = line.strip() if not stripped or stripped.startswith(("//", ";", "#", "@")): @@ -759,7 +759,8 @@ def parse_assembly_file(path: Path) -> list[str]: # Symbol metadata emits no instruction. Keep data and alignment directives visible. if stripped == ".text" or stripped.split(None, 1)[0] in (".globl", ".global", ".type", ".size"): continue - if stripped.endswith(":") and " " not in stripped: + code = re.split(r"//|[;#]", stripped)[0].strip() # same comment rule as extract_opcode + if code.endswith(":") and " " not in code: continue lines.append(stripped) return lines