Kekw
This commit is contained in:
parent
193be0bd5a
commit
d20447dd15
|
@ -24,7 +24,7 @@ macros::impl_both!(
|
||||||
=> [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: L)
|
||||||
=> [LD, ST],
|
=> [LD, ST],
|
||||||
bbd(p0: R, p1: R, p2: I)
|
bbd(p0: R, p1: R, p2: I)
|
||||||
=> [ADDI, MULI, ANDI, ORI, XORI, CMPI, CMPUI, BMC, JAL, JEQ, JNE, JLT, JGT, JLTU,
|
=> [ADDI, MULI, ANDI, ORI, XORI, CMPI, CMPUI, BMC, JAL, JEQ, JNE, JLT, JGT, JLTU,
|
||||||
|
|
|
@ -38,6 +38,12 @@ macro_rules! impl_asm_insert {
|
||||||
Imm::insert(&$id, $self)
|
Imm::insert(&$id, $self)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Length - cannot be more than 2048
|
||||||
|
($self:expr, $id:ident, L) => {{
|
||||||
|
assert!($id <= 2048);
|
||||||
|
$self.buf.extend($id.to_le_bytes())
|
||||||
|
}};
|
||||||
|
|
||||||
// Other numbers, just insert their bytes, little endian
|
// Other numbers, just insert their bytes, little endian
|
||||||
($self:expr, $id:ident, $_:ident) => {
|
($self:expr, $id:ident, $_:ident) => {
|
||||||
$self.buf.extend($id.to_le_bytes())
|
$self.buf.extend($id.to_le_bytes())
|
||||||
|
@ -76,6 +82,7 @@ macro_rules! impl_asm {
|
||||||
macro_rules! ident_map_ty {
|
macro_rules! ident_map_ty {
|
||||||
(R) => { u8 }; // Register is just u8
|
(R) => { u8 }; // Register is just u8
|
||||||
(I) => { impl Imm }; // Immediate is anything implementing the trait
|
(I) => { impl Imm }; // Immediate is anything implementing the trait
|
||||||
|
(L) => { u16 }; // Copy count
|
||||||
($id:ident) => { $id }; // Anything else → identity map
|
($id:ident) => { $id }; // Anything else → identity map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -226,6 +226,15 @@ macro_rules! gen_extract {
|
||||||
extract_pat!($self, Token::Register($id));
|
extract_pat!($self, Token::Register($id));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
($self:expr, L, $id:ident) => {
|
||||||
|
extract_pat!($self, Token::Integer($id));
|
||||||
|
if $id > 2048 {
|
||||||
|
return Err(ErrorKind::InvalidToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
let $id = u16::try_from($id).unwrap();
|
||||||
|
};
|
||||||
|
|
||||||
// Immediate
|
// Immediate
|
||||||
($self:expr, I, $id:ident) => {
|
($self:expr, I, $id:ident) => {
|
||||||
let $id = match $self.next()? {
|
let $id = match $self.next()? {
|
||||||
|
|
|
@ -48,8 +48,10 @@ pub fn validate(mut program: &[u8]) -> Result<(), Error> {
|
||||||
// Match on instruction types and perform necessary checks
|
// Match on instruction types and perform necessary checks
|
||||||
program = match program {
|
program = match program {
|
||||||
[] => return Ok(()),
|
[] => return Ok(()),
|
||||||
[LD..=ST, reg, _, _, _, _, _, _, _, _, _, count, ..]
|
[LD..=ST, reg, _, _, _, _, _, _, _, _, count_0, count_1, ..]
|
||||||
if usize::from(*reg) * 8 + usize::from(*count) > 2048 =>
|
if usize::from(*reg) * 8
|
||||||
|
+ usize::from(u16::from_le_bytes([*count_0, *count_1]))
|
||||||
|
> 2048 =>
|
||||||
{
|
{
|
||||||
return Err(Error {
|
return Err(Error {
|
||||||
kind: ErrorKind::RegisterArrayOverflow,
|
kind: ErrorKind::RegisterArrayOverflow,
|
||||||
|
|
Loading…
Reference in a new issue