gh-105481: add pseudo-instructions to the bytecodes DSL (#105506)

This commit is contained in:
Irit Katriel 2023-06-11 22:31:59 +01:00 committed by GitHub
parent 20a56d8bec
commit 58f5227d7c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 507 additions and 267 deletions

View file

@ -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):