diff options
author | Guido van Rossum <guido@python.org> | 2023-01-14 01:06:45 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-14 01:06:45 (GMT) |
commit | 5134ef48784b07133ae40b09a8086c10f0cac324 (patch) | |
tree | 6d5f229d8ba72492f2ae485b56ce0853ed05da3e /Tools | |
parent | 6bde3d2fd323fde8b9abf19b996ef7e8f1c549c1 (diff) | |
download | cpython-5134ef48784b07133ae40b09a8086c10f0cac324.zip cpython-5134ef48784b07133ae40b09a8086c10f0cac324.tar.gz cpython-5134ef48784b07133ae40b09a8086c10f0cac324.tar.bz2 |
GH-98831: Identify instructions that don't use oparg (#100957)
For these the instr_format field uses IX instead of IB.
Register instructions use IX, IB, IBBX, IBBB, etc.
Also: Include the closing '}' in Block.tokens, for completeness
Diffstat (limited to 'Tools')
-rw-r--r-- | Tools/cases_generator/generate_cases.py | 14 | ||||
-rw-r--r-- | Tools/cases_generator/parser.py | 2 |
2 files changed, 13 insertions, 3 deletions
diff --git a/Tools/cases_generator/generate_cases.py b/Tools/cases_generator/generate_cases.py index 608df6b..4bd99b7 100644 --- a/Tools/cases_generator/generate_cases.py +++ b/Tools/cases_generator/generate_cases.py @@ -168,9 +168,14 @@ class Instruction: break self.unmoved_names = frozenset(unmoved_names) if self.register: - fmt = "IBBB" + num_regs = len(self.input_effects) + len(self.output_effects) + num_dummies = (num_regs // 2) * 2 + 1 - num_regs + fmt = "I" + "B"*num_regs + "X"*num_dummies else: - fmt = "IB" + if variable_used(inst.block, "oparg"): + fmt = "IB" + else: + fmt = "IX" cache = "C" for ce in self.cache_effects: for _ in range(ce.size): @@ -894,6 +899,11 @@ def always_exits(lines: list[str]) -> bool: ) +def variable_used(block: parser.Block, name: str) -> bool: + """Determine whether a variable with a given name is used in a block.""" + return any(token.kind == "IDENTIFIER" and token.text == name for token in block.tokens) + + def main(): """Parse command line, parse input, analyze, write output.""" args = arg_parser.parse_args() # Prints message and sys.exit(2) on error diff --git a/Tools/cases_generator/parser.py b/Tools/cases_generator/parser.py index 4885394..fad0cb9 100644 --- a/Tools/cases_generator/parser.py +++ b/Tools/cases_generator/parser.py @@ -338,13 +338,13 @@ class Parser(PLexer): tokens: list[lx.Token] = [] level = 0 while tkn := self.next(raw=True): + tokens.append(tkn) if tkn.kind in (lx.LBRACE, lx.LPAREN, lx.LBRACKET): level += 1 elif tkn.kind in (lx.RBRACE, lx.RPAREN, lx.RBRACKET): level -= 1 if level <= 0: break - tokens.append(tkn) return tokens |