mirror of
https://github.com/Zenithsiz/dcb.git
synced 2026-02-09 03:40:23 +00:00
Removed pseudo::*Assign instructions.
This commit is contained in:
@@ -139,6 +139,10 @@ impl InstFmt for Inst {
|
||||
let mnemonic = kind.mnemonic();
|
||||
let value = kind.value_fmt();
|
||||
|
||||
write!(f, "{mnemonic} {dst}, {lhs}, {value}")
|
||||
// If `$dst` and `$lhs` are the same, only print one of them
|
||||
match dst == lhs {
|
||||
true => write!(f, "{mnemonic} {dst}, {value}"),
|
||||
false => write!(f, "{mnemonic} {dst}, {lhs}, {value}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,6 +145,10 @@ impl InstFmt for Inst {
|
||||
let Self { dst, lhs, rhs, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
write!(f, "{mnemonic} {dst}, {lhs}, {rhs}")
|
||||
// If `$dst` and `$lhs` are the same, only print one of them
|
||||
match dst == lhs {
|
||||
true => write!(f, "{mnemonic} {dst}, {rhs}"),
|
||||
false => write!(f, "{mnemonic} {dst}, {lhs}, {rhs}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,6 +104,10 @@ impl InstFmt for Inst {
|
||||
let Self { dst, lhs, rhs, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
write!(f, "{mnemonic} {dst}, {lhs}, {rhs:#x}")
|
||||
// If `$dst` and `$lhs` are the same, only print one of them
|
||||
match dst == lhs {
|
||||
true => write!(f, "{mnemonic} {dst}, {rhs:#x}"),
|
||||
false => write!(f, "{mnemonic} {dst}, {lhs}, {rhs:#x}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,6 +103,10 @@ impl InstFmt for Inst {
|
||||
let Self { dst, lhs, rhs, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
|
||||
write!(f, "{mnemonic} {dst}, {lhs}, {rhs}")
|
||||
// If `$dst` and `$lhs` are the same, only print one of them
|
||||
match dst == lhs {
|
||||
true => write!(f, "{mnemonic} {dst}, {rhs}"),
|
||||
false => write!(f, "{mnemonic} {dst}, {lhs}, {rhs}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,12 +5,10 @@
|
||||
//! via the [`Decodable`] trait.
|
||||
|
||||
// Modules
|
||||
pub mod alu_assign;
|
||||
pub mod load;
|
||||
pub mod load_imm;
|
||||
pub mod move_reg;
|
||||
pub mod nop;
|
||||
pub mod shift_assign;
|
||||
pub mod store;
|
||||
|
||||
// Imports
|
||||
@@ -20,12 +18,6 @@ use super::{basic, InstFmt, InstSize};
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
#[derive(derive_more::TryInto)]
|
||||
pub enum Inst {
|
||||
/// Alu self-assign
|
||||
AluAssign(alu_assign::Inst),
|
||||
|
||||
/// Shift self-assign
|
||||
ShiftAssign(shift_assign::Inst),
|
||||
|
||||
/// Load immediate
|
||||
LoadImm(load_imm::Inst),
|
||||
|
||||
@@ -46,9 +38,7 @@ impl Decodable for Inst {
|
||||
#[rustfmt::skip]
|
||||
fn decode(insts: impl Iterator<Item = basic::Inst> + Clone) -> Option<Self> {
|
||||
load_imm ::Inst::decode(insts.clone()).map(Self::LoadImm )
|
||||
.or_else( || nop ::Inst::decode(insts.clone()).map(Self::Nop )) // Note: Nop must come before `shift_assign`
|
||||
.or_else( || alu_assign ::Inst::decode(insts.clone()).map(Self::AluAssign ))
|
||||
.or_else( || shift_assign::Inst::decode(insts.clone()).map(Self::ShiftAssign))
|
||||
.or_else( || nop ::Inst::decode(insts.clone()).map(Self::Nop ))
|
||||
.or_else( || load ::Inst::decode(insts.clone()).map(Self::Load ))
|
||||
.or_else( || store ::Inst::decode(insts.clone()).map(Self::Store ))
|
||||
.or_else(move || move_reg ::Inst::decode( insts ).map(Self::MoveReg ))
|
||||
@@ -58,8 +48,6 @@ impl Decodable for Inst {
|
||||
impl InstSize for Inst {
|
||||
fn size(&self) -> usize {
|
||||
match self {
|
||||
Self::AluAssign(inst) => inst.size(),
|
||||
Self::ShiftAssign(inst) => inst.size(),
|
||||
Self::LoadImm(inst) => inst.size(),
|
||||
Self::Nop(inst) => inst.size(),
|
||||
Self::MoveReg(inst) => inst.size(),
|
||||
@@ -72,8 +60,6 @@ impl InstSize for Inst {
|
||||
impl InstFmt for Inst {
|
||||
fn fmt(&self, pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Self::AluAssign(inst) => inst.fmt(pos, f),
|
||||
Self::ShiftAssign(inst) => inst.fmt(pos, f),
|
||||
Self::LoadImm(inst) => inst.fmt(pos, f),
|
||||
Self::Nop(inst) => inst.fmt(pos, f),
|
||||
Self::MoveReg(inst) => inst.fmt(pos, f),
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
//! Alu self-assign instructions
|
||||
|
||||
// Imports
|
||||
use super::Decodable;
|
||||
use crate::exe::inst::{
|
||||
basic::{self, alu},
|
||||
InstFmt, InstSize, Register,
|
||||
};
|
||||
use std::{convert::TryInto, fmt};
|
||||
|
||||
/// Alu assign kind
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub enum Kind {
|
||||
/// Immediate
|
||||
Imm {
|
||||
/// Kind
|
||||
kind: alu::imm::Kind,
|
||||
},
|
||||
|
||||
/// Register
|
||||
Reg {
|
||||
/// Kind
|
||||
kind: alu::reg::Kind,
|
||||
|
||||
/// Argument
|
||||
rhs: Register,
|
||||
},
|
||||
}
|
||||
|
||||
impl Kind {
|
||||
/// Returns this kind's mnemonic
|
||||
#[must_use]
|
||||
pub const fn mnemonic(self) -> &'static str {
|
||||
match self {
|
||||
Self::Imm { kind } => kind.mnemonic(),
|
||||
Self::Reg { kind, .. } => kind.mnemonic(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a displayable with the value of this kind
|
||||
#[must_use]
|
||||
pub fn value_fmt(self) -> impl fmt::Display {
|
||||
dcb_util::DisplayWrapper::new(move |f| match self {
|
||||
Self::Imm { kind } => write!(f, "{}", kind.value_fmt()),
|
||||
Self::Reg { rhs, .. } => write!(f, "{}", rhs),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Alu self-assign instructions
|
||||
///
|
||||
/// Alias for
|
||||
/// ```mips
|
||||
/// [alu] $dst, $dst, ...
|
||||
/// ```
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub struct Inst {
|
||||
/// Destination and source register
|
||||
pub dst: Register,
|
||||
|
||||
/// Kind
|
||||
pub kind: Kind,
|
||||
}
|
||||
|
||||
impl Decodable for Inst {
|
||||
fn decode(mut insts: impl Iterator<Item = basic::Inst> + Clone) -> Option<Self> {
|
||||
match insts.next()?.try_into().ok()? {
|
||||
alu::Inst::Imm(alu::imm::Inst { dst, lhs, kind }) if dst == lhs => Some(Self {
|
||||
dst,
|
||||
kind: Kind::Imm { kind },
|
||||
}),
|
||||
alu::Inst::Reg(alu::reg::Inst { dst, lhs, rhs, kind }) if dst == lhs => Some(Self {
|
||||
dst,
|
||||
kind: Kind::Reg { kind, rhs },
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InstSize for Inst {
|
||||
fn size(&self) -> usize {
|
||||
4
|
||||
}
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
let value = kind.value_fmt();
|
||||
|
||||
write!(f, "{mnemonic} {dst}, {value}")
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
//! Shift self-assign instructions
|
||||
|
||||
// Imports
|
||||
use super::Decodable;
|
||||
use crate::exe::inst::{
|
||||
basic::{self, shift},
|
||||
InstFmt, InstSize, Register,
|
||||
};
|
||||
use std::{convert::TryInto, fmt};
|
||||
|
||||
/// Shift assign kind
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub enum Kind {
|
||||
/// Immediate
|
||||
Imm {
|
||||
/// Kind
|
||||
kind: shift::imm::Kind,
|
||||
|
||||
/// Argument
|
||||
rhs: u8,
|
||||
},
|
||||
|
||||
/// Register
|
||||
Reg {
|
||||
/// Kind
|
||||
kind: shift::reg::Kind,
|
||||
|
||||
/// Argument
|
||||
rhs: Register,
|
||||
},
|
||||
}
|
||||
|
||||
impl Kind {
|
||||
/// Returns this kind's mnemonic
|
||||
#[must_use]
|
||||
pub const fn mnemonic(self) -> &'static str {
|
||||
match self {
|
||||
Self::Imm { kind, .. } => kind.mnemonic(),
|
||||
Self::Reg { kind, .. } => kind.mnemonic(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a displayable with the value of this kind
|
||||
#[must_use]
|
||||
pub fn value_fmt(self) -> impl fmt::Display {
|
||||
dcb_util::DisplayWrapper::new(move |f| match self {
|
||||
Self::Imm { rhs, .. } => write!(f, "{:#x}", rhs),
|
||||
Self::Reg { rhs, .. } => write!(f, "{}", rhs),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// Shift self-assign instructions
|
||||
///
|
||||
/// Alias for
|
||||
/// ```mips
|
||||
/// [shift] $dst, $dst, ...
|
||||
/// ```
|
||||
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
|
||||
pub struct Inst {
|
||||
/// Destination and source register
|
||||
pub dst: Register,
|
||||
|
||||
/// Kind
|
||||
pub kind: Kind,
|
||||
}
|
||||
|
||||
impl Decodable for Inst {
|
||||
fn decode(mut insts: impl Iterator<Item = basic::Inst> + Clone) -> Option<Self> {
|
||||
match insts.next()?.try_into().ok()? {
|
||||
shift::Inst::Imm(shift::imm::Inst { dst, lhs, rhs, kind }) if dst == lhs => Some(Self {
|
||||
dst,
|
||||
kind: Kind::Imm { kind, rhs },
|
||||
}),
|
||||
shift::Inst::Reg(shift::reg::Inst { dst, lhs, rhs, kind }) if dst == lhs => Some(Self {
|
||||
dst,
|
||||
kind: Kind::Reg { kind, rhs },
|
||||
}),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl InstSize for Inst {
|
||||
fn size(&self) -> usize {
|
||||
4
|
||||
}
|
||||
}
|
||||
|
||||
impl InstFmt for Inst {
|
||||
fn fmt(&self, _pos: crate::Pos, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
let Self { dst, kind } = self;
|
||||
let mnemonic = kind.mnemonic();
|
||||
let value = kind.value_fmt();
|
||||
|
||||
write!(f, "{mnemonic} {dst}, {value}")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user