From a892ad09f19fb1583ba9c6c2e6d8dfba19fb8aaa Mon Sep 17 00:00:00 2001 From: Filipe Rodrigues Date: Tue, 12 Jan 2021 01:34:40 +0000 Subject: [PATCH] Removed `pseudo::*Assign` instructions. --- dcb-exe/src/exe/inst/basic/alu/imm.rs | 6 +- dcb-exe/src/exe/inst/basic/alu/reg.rs | 6 +- dcb-exe/src/exe/inst/basic/shift/imm.rs | 6 +- dcb-exe/src/exe/inst/basic/shift/reg.rs | 6 +- dcb-exe/src/exe/inst/pseudo.rs | 16 +--- dcb-exe/src/exe/inst/pseudo/alu_assign.rs | 95 -------------------- dcb-exe/src/exe/inst/pseudo/shift_assign.rs | 98 --------------------- 7 files changed, 21 insertions(+), 212 deletions(-) delete mode 100644 dcb-exe/src/exe/inst/pseudo/alu_assign.rs delete mode 100644 dcb-exe/src/exe/inst/pseudo/shift_assign.rs diff --git a/dcb-exe/src/exe/inst/basic/alu/imm.rs b/dcb-exe/src/exe/inst/basic/alu/imm.rs index 1bb9bf8..59e8876 100644 --- a/dcb-exe/src/exe/inst/basic/alu/imm.rs +++ b/dcb-exe/src/exe/inst/basic/alu/imm.rs @@ -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}"), + } } } diff --git a/dcb-exe/src/exe/inst/basic/alu/reg.rs b/dcb-exe/src/exe/inst/basic/alu/reg.rs index 93ee55c..67559a7 100644 --- a/dcb-exe/src/exe/inst/basic/alu/reg.rs +++ b/dcb-exe/src/exe/inst/basic/alu/reg.rs @@ -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}"), + } } } diff --git a/dcb-exe/src/exe/inst/basic/shift/imm.rs b/dcb-exe/src/exe/inst/basic/shift/imm.rs index b27f0b0..3e8830f 100644 --- a/dcb-exe/src/exe/inst/basic/shift/imm.rs +++ b/dcb-exe/src/exe/inst/basic/shift/imm.rs @@ -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}"), + } } } diff --git a/dcb-exe/src/exe/inst/basic/shift/reg.rs b/dcb-exe/src/exe/inst/basic/shift/reg.rs index 2aacc16..3f92c35 100644 --- a/dcb-exe/src/exe/inst/basic/shift/reg.rs +++ b/dcb-exe/src/exe/inst/basic/shift/reg.rs @@ -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}"), + } } } diff --git a/dcb-exe/src/exe/inst/pseudo.rs b/dcb-exe/src/exe/inst/pseudo.rs index 85fb65b..6c55ee7 100644 --- a/dcb-exe/src/exe/inst/pseudo.rs +++ b/dcb-exe/src/exe/inst/pseudo.rs @@ -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 + Clone) -> Option { 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), diff --git a/dcb-exe/src/exe/inst/pseudo/alu_assign.rs b/dcb-exe/src/exe/inst/pseudo/alu_assign.rs deleted file mode 100644 index 97e30b0..0000000 --- a/dcb-exe/src/exe/inst/pseudo/alu_assign.rs +++ /dev/null @@ -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 + Clone) -> Option { - 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}") - } -} diff --git a/dcb-exe/src/exe/inst/pseudo/shift_assign.rs b/dcb-exe/src/exe/inst/pseudo/shift_assign.rs deleted file mode 100644 index 1dbefb2..0000000 --- a/dcb-exe/src/exe/inst/pseudo/shift_assign.rs +++ /dev/null @@ -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 + Clone) -> Option { - 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}") - } -}