From 961c9e998ac7f3111e91fcfb5a70906484a36076 Mon Sep 17 00:00:00 2001 From: darcy Date: Wed, 18 Dec 2024 11:12:02 +1100 Subject: [PATCH 1/3] feat: support literals for PC-offset operands --- src/parser.rs | 46 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 14 deletions(-) diff --git a/src/parser.rs b/src/parser.rs index 56124bb..e8f9149 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -234,8 +234,7 @@ impl AsmParser { }) } InstrKind::Br(flag) => { - let label_tok = self.expect(TokenKind::Label)?; - let dest_label = Label::try_fill(self.get_span(label_tok.span)); + let dest_label = self.expect_lit_or_label(9)?; Ok(AirStmt::Branch { flag, dest_label }) } InstrKind::Jmp => { @@ -243,8 +242,7 @@ impl AsmParser { Ok(AirStmt::Jump { src_reg }) } InstrKind::Jsr => { - let label_tok = self.expect(TokenKind::Label)?; - let dest_label = Label::try_fill(self.get_span(label_tok.span)); + let dest_label = self.expect_lit_or_label(11)?; Ok(AirStmt::JumbSub { dest_label }) } InstrKind::Jsrr => { @@ -253,14 +251,12 @@ impl AsmParser { } InstrKind::Ld => { let dest = self.expect_reg()?; - let label_tok = self.expect(TokenKind::Label)?; - let src_label = Label::try_fill(self.get_span(label_tok.span)); + let src_label = self.expect_lit_or_label(9)?; Ok(AirStmt::Load { dest, src_label }) } InstrKind::Ldi => { let dest = self.expect_reg()?; - let label_tok = self.expect(TokenKind::Label)?; - let src_label = Label::try_fill(self.get_span(label_tok.span)); + let src_label = self.expect_lit_or_label(9)?; Ok(AirStmt::LoadInd { dest, src_label }) } InstrKind::Ldr => { @@ -275,8 +271,7 @@ impl AsmParser { } InstrKind::Lea => { let dest = self.expect_reg()?; - let label_tok = self.expect(TokenKind::Label)?; - let src_label = Label::try_fill(self.get_span(label_tok.span)); + let src_label = self.expect_lit_or_label(9)?; Ok(AirStmt::LoadEAddr { dest, src_label }) } InstrKind::Not => { @@ -288,8 +283,7 @@ impl AsmParser { InstrKind::Rti => Ok(AirStmt::Interrupt), InstrKind::St => { let src_reg = self.expect_reg()?; - let label_tok = self.expect(TokenKind::Label)?; - let dest_label = Label::try_fill(self.get_span(label_tok.span)); + let dest_label = self.expect_lit_or_label(9)?; Ok(AirStmt::Store { src_reg, dest_label, @@ -297,8 +291,7 @@ impl AsmParser { } InstrKind::Sti => { let src_reg = self.expect_reg()?; - let label_tok = self.expect(TokenKind::Label)?; - let dest_label = Label::try_fill(self.get_span(label_tok.span)); + let dest_label = self.expect_lit_or_label(9)?; Ok(AirStmt::StoreInd { src_reg, dest_label, @@ -435,6 +428,31 @@ impl AsmParser { None => return Err(error::parse_eof(self.src)), } } + + fn expect_lit_or_label(&mut self, bits: u8) -> Result