use std::fmt::{Debug, Display, Formatter}; use std::fmt; use crate::asm::data::{Rd, WrData}; /// Data destination argument (read-write) #[derive(Clone, Copy, Eq, PartialEq)] pub struct Wr(pub WrData); impl Wr { pub fn new(dst: WrData) -> Self { Wr(dst) } pub fn discard() -> Wr { Wr(WrData::Discard) } pub fn as_rd(self) -> Rd { Rd(self.0.into()) } pub fn is_readable(self) -> bool { self.0.is_readable() } pub fn is_discard(self) -> bool { match self.0 { WrData::Discard => true, _ => false } } } impl From<&Wr> for Wr { fn from(a: &Wr) -> Self { *a } } impl Display for Wr { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "{}", self.0) } } impl Debug for Wr { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { write!(f, "Wr({})", self.0) } }