gh-105481: Generate the opcode lists in dis from data extracted from bytecodes.c (#106758)

This commit is contained in:
Irit Katriel 2023-07-18 19:42:44 +01:00 committed by GitHub
parent 3535ef1eec
commit 40f3f11a77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 402 additions and 158 deletions

View file

@ -261,6 +261,8 @@ class InstructionFlags:
HAS_CONST_FLAG: bool
HAS_NAME_FLAG: bool
HAS_JUMP_FLAG: bool
HAS_FREE_FLAG: bool
HAS_LOCAL_FLAG: bool
def __post_init__(self):
self.bitmask = {
@ -269,16 +271,25 @@ class InstructionFlags:
@staticmethod
def fromInstruction(instr: "AnyInstruction"):
has_free = (variable_used(instr, "PyCell_New") or
variable_used(instr, "PyCell_GET") or
variable_used(instr, "PyCell_SET"))
return InstructionFlags(
HAS_ARG_FLAG=variable_used(instr, "oparg"),
HAS_CONST_FLAG=variable_used(instr, "FRAME_CO_CONSTS"),
HAS_NAME_FLAG=variable_used(instr, "FRAME_CO_NAMES"),
HAS_JUMP_FLAG=variable_used(instr, "JUMPBY"),
HAS_FREE_FLAG=has_free,
HAS_LOCAL_FLAG=(variable_used(instr, "GETLOCAL") or
variable_used(instr, "SETLOCAL")) and
not has_free,
)
@staticmethod
def newEmpty():
return InstructionFlags(False, False, False, False)
return InstructionFlags(False, False, False, False, False, False)
def add(self, other: "InstructionFlags") -> None:
for name, value in dataclasses.asdict(other).items():