forked from AbleOS/holey-bytes
special-cased BRC
This commit is contained in:
parent
271ab5a953
commit
116a228c5a
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);)*
|
||||||
|
|
|
@ -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!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +135,7 @@ macro_rules! gen_text {
|
||||||
|
|
||||||
asm.run()
|
asm.run()
|
||||||
.map_err(|kind| Error { kind, span: asm.lexer.span() })?;
|
.map_err(|kind| Error { kind, span: asm.lexer.span() })?;
|
||||||
|
|
||||||
for &loc in &asm.asm.sub {
|
for &loc in &asm.asm.sub {
|
||||||
let val = asm.symloc
|
let val = asm.symloc
|
||||||
.get(
|
.get(
|
||||||
|
@ -166,7 +178,7 @@ macro_rules! gen_text {
|
||||||
macro_rules! extract_pat {
|
macro_rules! extract_pat {
|
||||||
($self:expr, $pat:pat) => {
|
($self:expr, $pat:pat) => {
|
||||||
let $pat = $self.next()?
|
let $pat = $self.next()?
|
||||||
else { return Err(ErrorKind::UnexpectedToken) };
|
else { return Err(ErrorKind::UnexpectedToken) };
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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)?;
|
||||||
|
|
Loading…
Reference in a new issue