gh-106812: Refactor cases_generator to allow uops with array stack effects (#107564)

Introducing a new file, stacking.py, that takes over several responsibilities related to symbolic evaluation of push/pop operations, with more generality.
This commit is contained in:
Guido van Rossum 2023-08-04 09:35:56 -07:00 committed by GitHub
parent 407d7fda94
commit 400835ea16
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 1798 additions and 1098 deletions

View file

@ -69,12 +69,18 @@ class Block(Node):
@dataclass
class StackEffect(Node):
name: str
name: str = field(compare=False) # __eq__ only uses type, cond, size
type: str = "" # Optional `:type`
cond: str = "" # Optional `if (cond)`
size: str = "" # Optional `[size]`
# Note: size cannot be combined with type or cond
def __repr__(self):
items = [self.name, self.type, self.cond, self.size]
while items and items[-1] == "":
del items[-1]
return f"StackEffect({', '.join(repr(item) for item in items)})"
@dataclass
class Expression(Node):
@ -130,6 +136,7 @@ class Family(Node):
size: str # Variable giving the cache size in code units
members: list[str]
@dataclass
class Pseudo(Node):
name: str
@ -154,7 +161,13 @@ class Parser(PLexer):
if hdr := self.inst_header():
if block := self.block():
return InstDef(
hdr.override, hdr.register, hdr.kind, hdr.name, hdr.inputs, hdr.outputs, block
hdr.override,
hdr.register,
hdr.kind,
hdr.name,
hdr.inputs,
hdr.outputs,
block,
)
raise self.make_syntax_error("Expected block")
return None
@ -371,9 +384,7 @@ class Parser(PLexer):
raise self.make_syntax_error("Expected {")
if members := self.members():
if self.expect(lx.RBRACE) and self.expect(lx.SEMI):
return Pseudo(
tkn.text, members
)
return Pseudo(tkn.text, members)
return None
def members(self) -> list[str] | None: