mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03: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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue