special-cased BRC

This commit is contained in:
Erin 2023-07-12 02:23:47 +02:00 committed by ondra05
parent 271ab5a953
commit 116a228c5a
3 changed files with 28 additions and 5 deletions

View file

@ -16,7 +16,7 @@ macros::impl_both!(
bbbb(p0: R, p1: R, p2: R, p3: R) bbbb(p0: R, p1: R, p2: R, p3: R)
=> [DIR, DIRF, FMAF], => [DIR, DIRF, FMAF],
bbb(p0: R, p1: R, p2: R) bbb(p0: R, p1: R, p2: R)
=> [ADD, SUB, MUL, AND, OR, XOR, SL, SR, SRS, CMP, CMPU, BRC, ADDF, SUBF, MULF], => [ADD, SUB, MUL, AND, OR, XOR, SL, SR, SRS, CMP, CMPU, /*BRC,*/ ADDF, SUBF, MULF],
bbdh(p0: R, p1: R, p2: I, p3: u16) bbdh(p0: R, p1: R, p2: I, p3: u16)
=> [LD, ST], => [LD, ST],
bbd(p0: R, p1: R, p2: I) bbd(p0: R, p1: R, p2: I)
@ -30,6 +30,14 @@ macros::impl_both!(
=> [NOP, ECALL], => [NOP, ECALL],
); );
impl Assembler {
// Special-cased
#[inline(always)]
pub fn i_brc(&mut self, p0: u8, p1: u8, p2: u8) {
self.i_param_bbb(hbbytecode::opcode::BRC, p0, p1, p2)
}
}
pub trait Imm { pub trait Imm {
fn insert(&self, asm: &mut Assembler); fn insert(&self, asm: &mut Assembler);
} }

View file

@ -11,7 +11,6 @@ macro_rules! impl_asm_opcodes {
=> [$opcode:ident, $($rest:tt)*] => [$opcode:ident, $($rest:tt)*]
) => { ) => {
paste::paste! { paste::paste! {
#[allow(dead_code)]
#[inline(always)] #[inline(always)]
pub fn [<i_ $opcode:lower>](&mut self, $($param_i: $param_ty),*) { pub fn [<i_ $opcode:lower>](&mut self, $($param_i: $param_ty),*) {
self.$generic(hbbytecode::opcode::$opcode, $($param_i),*) self.$generic(hbbytecode::opcode::$opcode, $($param_i),*)
@ -45,7 +44,6 @@ macro_rules! impl_asm {
) => { ) => {
paste::paste! { paste::paste! {
$( $(
#[allow(dead_code)]
fn [<i_param_ $ityn>](&mut self, opcode: u8, $($param_i: macros::asm::ident_map_ty!($param_ty)),*) { fn [<i_param_ $ityn>](&mut self, opcode: u8, $($param_i: macros::asm::ident_map_ty!($param_ty)),*) {
self.buf.push(opcode); self.buf.push(opcode);
$(macros::asm::impl_asm_insert!(self, $param_i, $param_ty);)* $(macros::asm::impl_asm_insert!(self, $param_i, $param_ty);)*

View file

@ -24,6 +24,7 @@ macro_rules! gen_text {
#[logos(skip r"-- .*")] #[logos(skip r"-- .*")]
pub enum Token { pub enum Token {
$($(#[token(~([<$opcode:lower>]), |_| hbbytecode::opcode::[<$opcode:upper>])])*)* $($(#[token(~([<$opcode:lower>]), |_| hbbytecode::opcode::[<$opcode:upper>])])*)*
#[token("brc", |_| hbbytecode::opcode::BRC)] // Special-cased
Opcode(u8), Opcode(u8),
#[regex("[0-9]+", |l| l.slice().parse().ok())] #[regex("[0-9]+", |l| l.slice().parse().ok())]
@ -100,6 +101,17 @@ macro_rules! gen_text {
self.asm.[<i_param_ $ityn>](op, $($param_i),*); self.asm.[<i_param_ $ityn>](op, $($param_i),*);
}), }),
)* )*
// Special-cased
hbbytecode::opcode::BRC => {
param_extract_itm!(
self,
p0: R,
p1: R,
p2: u8
);
self.asm.i_param_bbb(op, p0, p1, p2);
}
_ => unreachable!(), _ => unreachable!(),
} }
} }
@ -183,6 +195,11 @@ macro_rules! extract {
}; };
}; };
($self:expr, u8, $id:ident) => {
extract_pat!($self, Token::Integer($id));
let $id = u8::try_from($id).map_err(|_| ErrorKind::InvalidToken)?;
};
($self:expr, u16, $id:ident) => { ($self:expr, u16, $id:ident) => {
extract_pat!($self, Token::Integer($id)); extract_pat!($self, Token::Integer($id));
let $id = u16::try_from($id).map_err(|_| ErrorKind::InvalidToken)?; let $id = u16::try_from($id).map_err(|_| ErrorKind::InvalidToken)?;