From 7ca0b1d4eb64f35b777d4c0f76aabbe968f21150 Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 11 Jul 2023 02:08:55 +0200 Subject: [PATCH] Improved assembler library --- hbasm/src/lib.rs | 30 +++++++++++++++++++----------- hbasm/src/macros.rs | 2 +- hbasm/src/text.rs | 3 --- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/hbasm/src/lib.rs b/hbasm/src/lib.rs index 6568916f..b3e12e3e 100644 --- a/hbasm/src/lib.rs +++ b/hbasm/src/lib.rs @@ -18,16 +18,16 @@ pub struct Assembler { impl Assembler { macros::impl_asm!( bbbb(p0: u8, p1: u8, p2: u8, p3: u8) - => [DIR, DIRF], + => [DIR, DIRF, FMAF], bbb(p0: u8, p1: u8, p2: u8) - => [ADD, SUB, MUL, AND, OR, XOR, SL, SRS, CMP, CMPU, BRC, ADDF, MULF], + => [ADD, SUB, MUL, AND, OR, XOR, SL, SR, SRS, CMP, CMPU, BRC, ADDF, SUBF, MULF], bbdh(p0: u8, p1: u8, p2: impl Imm, p3: u16) => [LD, ST], bbd(p0: u8, p1: u8, p2: impl Imm) => [ADDI, MULI, ANDI, ORI, XORI, SLI, SRI, SRSI, CMPI, CMPUI, - JEQ, JNE, JLT, JGT, JLTU, JGTU, ADDFI, MULFI], + BMC, JEQ, JNE, JLT, JGT, JLTU, JGTU, ADDFI, MULFI], bb(p0: u8, p1: u8) - => [NEG, NOT, CP, SWA], + => [NEG, NOT, CP, SWA, NEGF, ITF, FTI], bd(p0: u8, p1: impl Imm) => [LI, JMP], n() @@ -36,21 +36,29 @@ impl Assembler { } pub trait Imm { - fn insert(self, asm: &mut Assembler); + fn insert(&self, asm: &mut Assembler); } -impl Imm for u64 { - #[inline(always)] - fn insert(self, asm: &mut Assembler) { - asm.buf.extend(self.to_le_bytes()); - } +macro_rules! impl_imm_le_bytes { + ($($ty:ty),* $(,)?) => { + $( + impl Imm for $ty { + #[inline(always)] + fn insert(&self, asm: &mut Assembler) { + asm.buf.extend(self.to_le_bytes()); + } + } + )* + }; } +impl_imm_le_bytes!(u64, i64, f64); + #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub struct Symbol(pub u64); impl Imm for Symbol { #[inline(always)] - fn insert(self, asm: &mut Assembler) { + fn insert(&self, asm: &mut Assembler) { asm.sub.insert(asm.buf.len()); asm.buf.extend(self.0.to_le_bytes()); } diff --git a/hbasm/src/macros.rs b/hbasm/src/macros.rs index b6557ff3..d041ab20 100644 --- a/hbasm/src/macros.rs +++ b/hbasm/src/macros.rs @@ -33,7 +33,7 @@ macro_rules! gen_impl_asm_insert { };)* ($self:expr, $id:ident, $_:ty) => { - Imm::insert($id, $self) + Imm::insert(&$id, $self) }; } }; diff --git a/hbasm/src/text.rs b/hbasm/src/text.rs index d4a3a9ec..7739d0e0 100644 --- a/hbasm/src/text.rs +++ b/hbasm/src/text.rs @@ -1,6 +1,3 @@ - - -// use std::collections::HashMap; extern crate alloc; use alloc::vec::Vec;