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
This commit is contained in:
Guido van Rossum 2023-01-13 17:06:45 -08:00 committed by GitHub
parent 6bde3d2fd3
commit 5134ef4878
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 60 deletions

View file

@ -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