GH-98831: Update generate_cases.py: register inst, opcode_metadata.h (#100735)

(These aren't used yet, but may be coming soon,
and it's easier to keep this tool the same between branches.)

Added a sanity check for all this to compile.c.

Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
This commit is contained in:
Guido van Rossum 2023-01-05 13:01:07 -08:00 committed by GitHub
parent 28187141cc
commit 14b7f00fdf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 456 additions and 37 deletions

View file

@ -84,7 +84,8 @@ class OpName(Node):
@dataclass
class InstHeader(Node):
kind: Literal["inst", "op"]
register: bool
kind: Literal["inst", "op", "legacy"] # Legacy means no (inputs -- outputs)
name: str
inputs: list[InputEffect]
outputs: list[OutputEffect]
@ -92,7 +93,8 @@ class InstHeader(Node):
@dataclass
class InstDef(Node):
kind: Literal["inst", "op"]
register: bool
kind: Literal["inst", "op", "legacy"]
name: str
inputs: list[InputEffect]
outputs: list[OutputEffect]
@ -134,16 +136,19 @@ def definition(self) -> InstDef | Super | Macro | Family | None:
def inst_def(self) -> InstDef | None:
if hdr := self.inst_header():
if block := self.block():
return InstDef(hdr.kind, hdr.name, hdr.inputs, hdr.outputs, block)
return InstDef(
hdr.register, hdr.kind, hdr.name, hdr.inputs, hdr.outputs, block
)
raise self.make_syntax_error("Expected block")
return None
@contextual
def inst_header(self) -> InstHeader | None:
# inst(NAME)
# | inst(NAME, (inputs -- outputs))
# | op(NAME, (inputs -- outputs))
# | [register] inst(NAME, (inputs -- outputs))
# | [register] op(NAME, (inputs -- outputs))
# TODO: Make INST a keyword in the lexer.
register = bool(self.expect(lx.REGISTER))
if (tkn := self.expect(lx.IDENTIFIER)) and (kind := tkn.text) in ("inst", "op"):
if self.expect(lx.LPAREN) and (tkn := self.expect(lx.IDENTIFIER)):
name = tkn.text
@ -151,10 +156,10 @@ def inst_header(self) -> InstHeader | None:
inp, outp = self.io_effect()
if self.expect(lx.RPAREN):
if (tkn := self.peek()) and tkn.kind == lx.LBRACE:
return InstHeader(kind, name, inp, outp)
return InstHeader(register, kind, name, inp, outp)
elif self.expect(lx.RPAREN) and kind == "inst":
# No legacy stack effect if kind is "op".
return InstHeader(kind, name, [], [])
return InstHeader(register, "legacy", name, [], [])
return None
def io_effect(self) -> tuple[list[InputEffect], list[OutputEffect]]: