|
|
|
@ -13,6 +13,13 @@ pub mod literal; |
|
|
|
|
pub mod reg; |
|
|
|
|
pub mod mask; |
|
|
|
|
|
|
|
|
|
mod rd; |
|
|
|
|
pub use rd::Rd; |
|
|
|
|
pub use rd::RdObj; |
|
|
|
|
|
|
|
|
|
mod wr; |
|
|
|
|
pub use wr::Wr; |
|
|
|
|
|
|
|
|
|
/// Data source disposition
|
|
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)] |
|
|
|
|
pub enum DataDisp { |
|
|
|
@ -36,7 +43,7 @@ impl Display for DataDisp { |
|
|
|
|
write!(f, "{}", r) |
|
|
|
|
} |
|
|
|
|
DataDisp::ObjectPtr(r) => { |
|
|
|
|
write!(f, "%{}", r) |
|
|
|
|
write!(f, "@{}", r) |
|
|
|
|
} |
|
|
|
|
DataDisp::Discard => { |
|
|
|
|
write!(f, "_") |
|
|
|
@ -45,29 +52,29 @@ impl Display for DataDisp { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<SrcDisp> for DataDisp { |
|
|
|
|
fn from(s: SrcDisp) -> Self { |
|
|
|
|
impl From<RdData> for DataDisp { |
|
|
|
|
fn from(s: RdData) -> Self { |
|
|
|
|
match s { |
|
|
|
|
SrcDisp::Immediate(x) => DataDisp::Immediate(x), |
|
|
|
|
SrcDisp::Register(x) => DataDisp::Register(x), |
|
|
|
|
SrcDisp::ObjectPtr(x) => DataDisp::ObjectPtr(x), |
|
|
|
|
RdData::Immediate(x) => DataDisp::Immediate(x), |
|
|
|
|
RdData::Register(x) => DataDisp::Register(x), |
|
|
|
|
RdData::ObjectPtr(x) => DataDisp::ObjectPtr(x), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<DstDisp> for DataDisp { |
|
|
|
|
fn from(s: DstDisp) -> Self { |
|
|
|
|
impl From<WrData> for DataDisp { |
|
|
|
|
fn from(s: WrData) -> Self { |
|
|
|
|
match s { |
|
|
|
|
DstDisp::Register(x) => DataDisp::Register(x), |
|
|
|
|
DstDisp::ObjectPtr(x) => DataDisp::ObjectPtr(x), |
|
|
|
|
DstDisp::Discard => DataDisp::Discard, |
|
|
|
|
WrData::Register(x) => DataDisp::Register(x), |
|
|
|
|
WrData::ObjectPtr(x) => DataDisp::ObjectPtr(x), |
|
|
|
|
WrData::Discard => DataDisp::Discard, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Data source disposition
|
|
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)] |
|
|
|
|
pub enum SrcDisp { |
|
|
|
|
pub enum RdData { |
|
|
|
|
/// Constant value
|
|
|
|
|
Immediate(Value), |
|
|
|
|
/// Register
|
|
|
|
@ -76,14 +83,14 @@ pub enum SrcDisp { |
|
|
|
|
ObjectPtr(Register), |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl TryFrom<DataDisp> for SrcDisp { |
|
|
|
|
impl TryFrom<DataDisp> for RdData { |
|
|
|
|
type Error = AsmError; |
|
|
|
|
|
|
|
|
|
fn try_from(value: DataDisp) -> Result<Self, Self::Error> { |
|
|
|
|
match value { |
|
|
|
|
DataDisp::Immediate(x) => Ok(SrcDisp::Immediate(x)), |
|
|
|
|
DataDisp::Register(x) => Ok(SrcDisp::Register(x)), |
|
|
|
|
DataDisp::ObjectPtr(x) => Ok(SrcDisp::ObjectPtr(x)), |
|
|
|
|
DataDisp::Immediate(x) => Ok(RdData::Immediate(x)), |
|
|
|
|
DataDisp::Register(x) => Ok(RdData::Register(x)), |
|
|
|
|
DataDisp::ObjectPtr(x) => Ok(RdData::ObjectPtr(x)), |
|
|
|
|
DataDisp::Discard => Err(AsmError::DiscardAsValue), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -91,7 +98,7 @@ impl TryFrom<DataDisp> for SrcDisp { |
|
|
|
|
|
|
|
|
|
/// Data destination disposition
|
|
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)] |
|
|
|
|
pub enum DstDisp { |
|
|
|
|
pub enum WrData { |
|
|
|
|
/// Register
|
|
|
|
|
Register(Register), |
|
|
|
|
/// Pointer into memory, stored in a numbered register
|
|
|
|
@ -100,92 +107,26 @@ pub enum DstDisp { |
|
|
|
|
Discard, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl From<DstDisp> for SrcDisp { |
|
|
|
|
fn from(s: DstDisp) -> Self { |
|
|
|
|
impl From<WrData> for RdData { |
|
|
|
|
fn from(s: WrData) -> Self { |
|
|
|
|
match s { |
|
|
|
|
DstDisp::Register(x) => SrcDisp::Register(x), |
|
|
|
|
DstDisp::ObjectPtr(x) => SrcDisp::ObjectPtr(x), |
|
|
|
|
DstDisp::Discard => SrcDisp::Immediate(0), |
|
|
|
|
WrData::Register(x) => RdData::Register(x), |
|
|
|
|
WrData::ObjectPtr(x) => RdData::ObjectPtr(x), |
|
|
|
|
WrData::Discard => RdData::Immediate(0), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl TryFrom<DataDisp> for DstDisp { |
|
|
|
|
impl TryFrom<DataDisp> for WrData { |
|
|
|
|
type Error = AsmError; |
|
|
|
|
|
|
|
|
|
fn try_from(value: DataDisp) -> Result<Self, Self::Error> { |
|
|
|
|
match value { |
|
|
|
|
DataDisp::Immediate(_x) => Err(AsmError::ValueAsOutput), |
|
|
|
|
DataDisp::Register(x) => Ok(DstDisp::Register(x)), |
|
|
|
|
DataDisp::ObjectPtr(x) => Ok(DstDisp::ObjectPtr(x)), |
|
|
|
|
DataDisp::Discard => Ok(DstDisp::Discard), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Data source argument (read-only)
|
|
|
|
|
#[derive(Clone, Copy, Eq, PartialEq)] |
|
|
|
|
pub struct Rd(SrcDisp, Mask); |
|
|
|
|
|
|
|
|
|
impl Rd { |
|
|
|
|
pub fn new(src: SrcDisp) -> Self { |
|
|
|
|
Rd(src, Mask::default()) |
|
|
|
|
} |
|
|
|
|
pub fn d(self) -> SrcDisp { |
|
|
|
|
self.0 |
|
|
|
|
} |
|
|
|
|
pub fn mask(self) -> Mask { |
|
|
|
|
self.1 |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn immediate(val: Value) -> Rd { |
|
|
|
|
Rd(SrcDisp::Immediate(val), Mask::default()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/// Data destination argument (read-write)
|
|
|
|
|
#[derive(Clone, Copy, Eq, PartialEq)] |
|
|
|
|
pub struct Wr(DstDisp, Mask); |
|
|
|
|
|
|
|
|
|
impl Wr { |
|
|
|
|
pub fn new(dst: DstDisp) -> Self { |
|
|
|
|
Wr(dst, Mask::default()) |
|
|
|
|
} |
|
|
|
|
pub fn d(self) -> DstDisp { |
|
|
|
|
self.0 |
|
|
|
|
} |
|
|
|
|
pub fn mask(self) -> Mask { |
|
|
|
|
self.1 |
|
|
|
|
} |
|
|
|
|
pub fn as_rd(&self) -> Rd { |
|
|
|
|
Rd(self.0.into(), self.1) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pub fn discard() -> Wr { |
|
|
|
|
Wr(DstDisp::Discard, Mask::default()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Debug for Rd { |
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
|
|
|
|
write!(f, "Rd(")?; |
|
|
|
|
let disp: DataDisp = self.0.into(); |
|
|
|
|
write!(f, "{}", disp)?; |
|
|
|
|
if !self.mask().is_default() { |
|
|
|
|
write!(f, ",{:?}", self.mask())?; |
|
|
|
|
DataDisp::Register(x) => Ok(WrData::Register(x)), |
|
|
|
|
DataDisp::ObjectPtr(x) => Ok(WrData::ObjectPtr(x)), |
|
|
|
|
DataDisp::Discard => Ok(WrData::Discard), |
|
|
|
|
} |
|
|
|
|
write!(f, ")") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
impl Debug for Wr { |
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { |
|
|
|
|
write!(f, "Wr(")?; |
|
|
|
|
let disp: DataDisp = self.0.into(); |
|
|
|
|
write!(f, "{}", disp)?; |
|
|
|
|
if !self.mask().is_default() { |
|
|
|
|
write!(f, ",{:?}", self.mask())?; |
|
|
|
|
} |
|
|
|
|
write!(f, ")") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|