mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
gh-105481: add pseudo-instructions to the bytecodes DSL (#105506)
This commit is contained in:
parent
20a56d8bec
commit
58f5227d7c
8 changed files with 507 additions and 267 deletions
|
@ -136,10 +136,15 @@ class Family(Node):
|
|||
size: str # Variable giving the cache size in code units
|
||||
members: list[str]
|
||||
|
||||
@dataclass
|
||||
class Pseudo(Node):
|
||||
name: str
|
||||
targets: list[str] # opcodes this can be replaced by
|
||||
|
||||
|
||||
class Parser(PLexer):
|
||||
@contextual
|
||||
def definition(self) -> InstDef | Super | Macro | Family | None:
|
||||
def definition(self) -> InstDef | Super | Macro | Family | Pseudo | None:
|
||||
if inst := self.inst_def():
|
||||
return inst
|
||||
if super := self.super_def():
|
||||
|
@ -148,6 +153,8 @@ class Parser(PLexer):
|
|||
return macro
|
||||
if family := self.family_def():
|
||||
return family
|
||||
if pseudo := self.pseudo_def():
|
||||
return pseudo
|
||||
|
||||
@contextual
|
||||
def inst_def(self) -> InstDef | None:
|
||||
|
@ -364,6 +371,23 @@ class Parser(PLexer):
|
|||
)
|
||||
return None
|
||||
|
||||
@contextual
|
||||
def pseudo_def(self) -> Pseudo | None:
|
||||
if (tkn := self.expect(lx.IDENTIFIER)) and tkn.text == "pseudo":
|
||||
size = None
|
||||
if self.expect(lx.LPAREN):
|
||||
if tkn := self.expect(lx.IDENTIFIER):
|
||||
if self.expect(lx.RPAREN):
|
||||
if self.expect(lx.EQUALS):
|
||||
if not self.expect(lx.LBRACE):
|
||||
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 None
|
||||
|
||||
def members(self) -> list[str] | None:
|
||||
here = self.getpos()
|
||||
if tkn := self.expect(lx.IDENTIFIER):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue