gh-102021 : Allow multiple input files for interpreter loop generator (#102022)

The input files no longer use `-i`.
This commit is contained in:
Jacob Bower 2023-03-03 20:59:21 -08:00 committed by GitHub
parent cb944d0be8
commit 8de59c1bb9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 41 deletions

View file

@ -33,7 +33,7 @@ class Context(NamedTuple):
owner: PLexer
def __repr__(self):
return f"<{self.begin}-{self.end}>"
return f"<{self.owner.filename}: {self.begin}-{self.end}>"
@dataclass
@ -99,6 +99,7 @@ UOp = OpName | CacheEffect
@dataclass
class InstHeader(Node):
override: bool
register: bool
kind: Literal["inst", "op", "legacy"] # Legacy means no (inputs -- outputs)
name: str
@ -108,6 +109,7 @@ class InstHeader(Node):
@dataclass
class InstDef(Node):
override: bool
register: bool
kind: Literal["inst", "op", "legacy"]
name: str
@ -152,17 +154,18 @@ class Parser(PLexer):
if hdr := self.inst_header():
if block := self.block():
return InstDef(
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
@contextual
def inst_header(self) -> InstHeader | None:
# inst(NAME)
# | [register] inst(NAME, (inputs -- outputs))
# | [register] op(NAME, (inputs -- outputs))
# [override] inst(NAME)
# | [override] [register] inst(NAME, (inputs -- outputs))
# | [override] [register] op(NAME, (inputs -- outputs))
# TODO: Make INST a keyword in the lexer.
override = bool(self.expect(lx.OVERRIDE))
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)):
@ -171,10 +174,10 @@ class Parser(PLexer):
inp, outp = self.io_effect()
if self.expect(lx.RPAREN):
if (tkn := self.peek()) and tkn.kind == lx.LBRACE:
return InstHeader(register, kind, name, inp, outp)
return InstHeader(override, register, kind, name, inp, outp)
elif self.expect(lx.RPAREN) and kind == "inst":
# No legacy stack effect if kind is "op".
return InstHeader(register, "legacy", name, [], [])
return InstHeader(override, register, "legacy", name, [], [])
return None
def io_effect(self) -> tuple[list[InputEffect], list[OutputEffect]]: