mirror of
https://github.com/python/cpython.git
synced 2025-08-19 16:20:59 +00:00
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:
parent
6bde3d2fd3
commit
5134ef4878
3 changed files with 70 additions and 60 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue