Skip to content

Commit 6c398ab

Browse files
authored
[NFC][mlir][spirv] Fix syntax warnings in gen_spirv_dialect.py (#111775)
In the context of regular expressions, Python (used to) gracefully ignore the escape behavior of `\` in some contexts, e.g. for representing the regular expression `\w+`. However in newer versions of Python this now gives a warning in the form ``` SyntaxWarning: invalid escape sequence '\w' ``` Fix by explicitly using raw strings instead.
1 parent 72fb379 commit 6c398ab

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

mlir/utils/spirv/gen_spirv_dialect.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def gen_instr_coverage_report(path, instructions):
538538

539539
prefix = "def SPIRV_OC_"
540540
existing_opcodes = [
541-
k[len(prefix) :] for k in re.findall(prefix + "\w+", content[1])
541+
k[len(prefix) :] for k in re.findall(prefix + r"\w+", content[1])
542542
]
543543
existing_instructions = list(
544544
filter(lambda inst: (inst["opname"] in existing_opcodes), instructions)
@@ -597,7 +597,7 @@ def update_td_opcodes(path, instructions, filter_list):
597597
# Extend opcode list with existing list
598598
prefix = "def SPIRV_OC_"
599599
existing_opcodes = [
600-
k[len(prefix) :] for k in re.findall(prefix + "\w+", content[1])
600+
k[len(prefix) :] for k in re.findall(prefix + r"\w+", content[1])
601601
]
602602
filter_list.extend(existing_opcodes)
603603
filter_list = list(set(filter_list))
@@ -644,7 +644,7 @@ def update_td_enum_attrs(path, operand_kinds, filter_list):
644644
suffix = "Attr"
645645
existing_kinds = [
646646
k[len(prefix) : -len(suffix)]
647-
for k in re.findall(prefix + "\w+" + suffix, content[1])
647+
for k in re.findall(prefix + r"\w+" + suffix, content[1])
648648
]
649649
filter_list.extend(existing_kinds)
650650

@@ -971,15 +971,15 @@ def extract_td_op_info(op_def):
971971
suffix = "Op"
972972
opname = [
973973
o[len(prefix) : -len(suffix)]
974-
for o in re.findall(prefix + "\w+" + suffix, op_def)
974+
for o in re.findall(prefix + r"\w+" + suffix, op_def)
975975
]
976976
assert len(opname) == 1, "more than one ops in the same section!"
977977
opname = opname[0]
978978

979979
# Get instruction category
980980
prefix = "SPIRV_"
981981
inst_category = [
982-
o[len(prefix) :] for o in re.findall(prefix + "\w+Op", op_def.split(":", 1)[1])
982+
o[len(prefix) :] for o in re.findall(prefix + r"\w+Op", op_def.split(":", 1)[1])
983983
]
984984
assert len(inst_category) <= 1, "more than one ops in the same section!"
985985
inst_category = inst_category[0] if len(inst_category) == 1 else "Op"

0 commit comments

Comments
 (0)