summaryrefslogtreecommitdiffstats
path: root/Tools
diff options
context:
space:
mode:
authorIrit Katriel <1055913+iritkatriel@users.noreply.github.com>2023-01-24 22:39:13 (GMT)
committerGitHub <noreply@github.com>2023-01-24 22:39:13 (GMT)
commit1a9d8c750be83e6abb65769d312361fe9742de02 (patch)
treebee01eac8527f9fd4cbcb7d4a71733c4762318ba /Tools
parentf02fa64bf2d03ef7a28650c164e17a5fb5d8543d (diff)
downloadcpython-1a9d8c750be83e6abb65769d312361fe9742de02.zip
cpython-1a9d8c750be83e6abb65769d312361fe9742de02.tar.gz
cpython-1a9d8c750be83e6abb65769d312361fe9742de02.tar.bz2
gh-98831: rewrite pattern matching opcodes in the instruction definition DSL (#101287)
Diffstat (limited to 'Tools')
-rw-r--r--Tools/cases_generator/generate_cases.py8
-rw-r--r--Tools/cases_generator/test_generator.py14
2 files changed, 18 insertions, 4 deletions
diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py
index 90f101a..429c9d3 100644
--- a/Tools/cases_generator/generate_cases.py
+++ b/Tools/cases_generator/generate_cases.py
@@ -26,7 +26,7 @@ DEFAULT_METADATA_OUTPUT = os.path.relpath(
)
BEGIN_MARKER = "// BEGIN BYTECODES //"
END_MARKER = "// END BYTECODES //"
-RE_PREDICTED = r"^\s*(?:PREDICT\(|GO_TO_INSTRUCTION\(|DEOPT_IF\(.*?,\s*)(\w+)\);\s*$"
+RE_PREDICTED = r"^\s*(?:PREDICT\(|GO_TO_INSTRUCTION\(|DEOPT_IF\(.*?,\s*)(\w+)\);\s*(?://.*)?$"
UNUSED = "unused"
BITS_PER_CODE_UNIT = 16
@@ -354,7 +354,7 @@ class Instruction:
assert dedent <= 0
extra = " " * -dedent
for line in self.block_text:
- if m := re.match(r"(\s*)ERROR_IF\((.+), (\w+)\);\s*$", line):
+ if m := re.match(r"(\s*)ERROR_IF\((.+), (\w+)\);\s*(?://.*)?$", line):
space, cond, label = m.groups()
# ERROR_IF() must pop the inputs from the stack.
# The code block is responsible for DECREF()ing them.
@@ -378,7 +378,7 @@ class Instruction:
)
else:
out.write_raw(f"{extra}{space}if ({cond}) goto {label};\n")
- elif m := re.match(r"(\s*)DECREF_INPUTS\(\);\s*$", line):
+ elif m := re.match(r"(\s*)DECREF_INPUTS\(\);\s*(?://.*)?$", line):
if not self.register:
space = m.group(1)
for ieff in self.input_effects:
@@ -964,7 +964,7 @@ def extract_block_text(block: parser.Block) -> tuple[list[str], list[str]]:
# Separate PREDICT(...) macros from end
predictions: list[str] = []
- while blocklines and (m := re.match(r"^\s*PREDICT\((\w+)\);\s*$", blocklines[-1])):
+ while blocklines and (m := re.match(r"^\s*PREDICT\((\w+)\);\s*(?://.*)?$", blocklines[-1])):
predictions.insert(0, m.group(1))
blocklines.pop()
diff --git a/Tools/cases_generator/test_generator.py b/Tools/cases_generator/test_generator.py
index ae0c1e2..c59aae8 100644
--- a/Tools/cases_generator/test_generator.py
+++ b/Tools/cases_generator/test_generator.py
@@ -215,6 +215,20 @@ def test_error_if_plain():
"""
run_cases_test(input, output)
+def test_error_if_plain_with_comment():
+ input = """
+ inst(OP, (--)) {
+ ERROR_IF(cond, label); // Comment is ok
+ }
+ """
+ output = """
+ TARGET(OP) {
+ if (cond) goto label;
+ DISPATCH();
+ }
+ """
+ run_cases_test(input, output)
+
def test_error_if_pop():
input = """
inst(OP, (left, right -- res)) {