|
|
@ -25,10 +25,12 @@ mod wr; |
|
|
|
pub enum DataDisp { |
|
|
|
pub enum DataDisp { |
|
|
|
/// Constant value
|
|
|
|
/// Constant value
|
|
|
|
Immediate(Value), |
|
|
|
Immediate(Value), |
|
|
|
|
|
|
|
/// Object pointer with immediate value
|
|
|
|
|
|
|
|
ImmObject(Value), |
|
|
|
/// Register
|
|
|
|
/// Register
|
|
|
|
Register(Register), |
|
|
|
Register(Register), |
|
|
|
/// Object pointer
|
|
|
|
/// Object pointer in register
|
|
|
|
ObjectPtr(Register), |
|
|
|
RegObject(Register), |
|
|
|
/// Discard the written value
|
|
|
|
/// Discard the written value
|
|
|
|
Discard, |
|
|
|
Discard, |
|
|
|
} |
|
|
|
} |
|
|
@ -42,9 +44,12 @@ impl Display for DataDisp { |
|
|
|
DataDisp::Register(r) => { |
|
|
|
DataDisp::Register(r) => { |
|
|
|
write!(f, "{}", r) |
|
|
|
write!(f, "{}", r) |
|
|
|
} |
|
|
|
} |
|
|
|
DataDisp::ObjectPtr(r) => { |
|
|
|
DataDisp::RegObject(r) => { |
|
|
|
write!(f, "@{}", r) |
|
|
|
write!(f, "@{}", r) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
DataDisp::ImmObject(r) => { |
|
|
|
|
|
|
|
write!(f, "@{:#x}", r) |
|
|
|
|
|
|
|
} |
|
|
|
DataDisp::Discard => { |
|
|
|
DataDisp::Discard => { |
|
|
|
write!(f, "_") |
|
|
|
write!(f, "_") |
|
|
|
} |
|
|
|
} |
|
|
@ -57,7 +62,8 @@ impl From<RdData> for DataDisp { |
|
|
|
match s { |
|
|
|
match s { |
|
|
|
RdData::Immediate(x) => DataDisp::Immediate(x), |
|
|
|
RdData::Immediate(x) => DataDisp::Immediate(x), |
|
|
|
RdData::Register(x) => DataDisp::Register(x), |
|
|
|
RdData::Register(x) => DataDisp::Register(x), |
|
|
|
RdData::ObjectPtr(x) => DataDisp::ObjectPtr(x), |
|
|
|
RdData::RegObject(x) => DataDisp::RegObject(x), |
|
|
|
|
|
|
|
RdData::ImmObject(x) => DataDisp::ImmObject(x), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -66,7 +72,8 @@ impl From<WrData> for DataDisp { |
|
|
|
fn from(s: WrData) -> Self { |
|
|
|
fn from(s: WrData) -> Self { |
|
|
|
match s { |
|
|
|
match s { |
|
|
|
WrData::Register(x) => DataDisp::Register(x), |
|
|
|
WrData::Register(x) => DataDisp::Register(x), |
|
|
|
WrData::ObjectPtr(x) => DataDisp::ObjectPtr(x), |
|
|
|
WrData::RegObject(x) => DataDisp::RegObject(x), |
|
|
|
|
|
|
|
WrData::ImmObject(x) => DataDisp::ImmObject(x), |
|
|
|
WrData::Discard => DataDisp::Discard, |
|
|
|
WrData::Discard => DataDisp::Discard, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -77,10 +84,12 @@ impl From<WrData> for DataDisp { |
|
|
|
pub enum RdData { |
|
|
|
pub enum RdData { |
|
|
|
/// Constant value
|
|
|
|
/// Constant value
|
|
|
|
Immediate(Value), |
|
|
|
Immediate(Value), |
|
|
|
|
|
|
|
/// Pointer into memory, address immediate
|
|
|
|
|
|
|
|
ImmObject(Value), |
|
|
|
/// Register
|
|
|
|
/// Register
|
|
|
|
Register(Register), |
|
|
|
Register(Register), |
|
|
|
/// Pointer into memory, stored in a numbered register
|
|
|
|
/// Pointer into memory, stored in a numbered register
|
|
|
|
ObjectPtr(Register), |
|
|
|
RegObject(Register), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl Display for RdData { |
|
|
|
impl Display for RdData { |
|
|
@ -94,7 +103,8 @@ impl Display for RdData { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
RdData::Register(r) => write!(f, "{}", r), |
|
|
|
RdData::Register(r) => write!(f, "{}", r), |
|
|
|
RdData::ObjectPtr(r) => write!(f, "@{}", r) |
|
|
|
RdData::RegObject(r) => write!(f, "@{}", r), |
|
|
|
|
|
|
|
RdData::ImmObject(v) => write!(f, "@{:#x}", v), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -105,8 +115,9 @@ impl TryFrom<DataDisp> for RdData { |
|
|
|
fn try_from(value: DataDisp) -> Result<Self, Self::Error> { |
|
|
|
fn try_from(value: DataDisp) -> Result<Self, Self::Error> { |
|
|
|
match value { |
|
|
|
match value { |
|
|
|
DataDisp::Immediate(x) => Ok(RdData::Immediate(x)), |
|
|
|
DataDisp::Immediate(x) => Ok(RdData::Immediate(x)), |
|
|
|
|
|
|
|
DataDisp::ImmObject(x) => Ok(RdData::ImmObject(x)), |
|
|
|
DataDisp::Register(x) => Ok(RdData::Register(x)), |
|
|
|
DataDisp::Register(x) => Ok(RdData::Register(x)), |
|
|
|
DataDisp::ObjectPtr(x) => Ok(RdData::ObjectPtr(x)), |
|
|
|
DataDisp::RegObject(x) => Ok(RdData::RegObject(x)), |
|
|
|
DataDisp::Discard => Err(AsmError::DiscardAsValue), |
|
|
|
DataDisp::Discard => Err(AsmError::DiscardAsValue), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -115,10 +126,12 @@ impl TryFrom<DataDisp> for RdData { |
|
|
|
/// Data destination disposition
|
|
|
|
/// Data destination disposition
|
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)] |
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq)] |
|
|
|
pub enum WrData { |
|
|
|
pub enum WrData { |
|
|
|
|
|
|
|
/// Pointer into memory, address immediate
|
|
|
|
|
|
|
|
ImmObject(Value), |
|
|
|
/// Register
|
|
|
|
/// Register
|
|
|
|
Register(Register), |
|
|
|
Register(Register), |
|
|
|
/// Pointer into memory, stored in a numbered register
|
|
|
|
/// Pointer into memory, stored in a numbered register
|
|
|
|
ObjectPtr(Register), |
|
|
|
RegObject(Register), |
|
|
|
/// Discard the written value
|
|
|
|
/// Discard the written value
|
|
|
|
Discard, |
|
|
|
Discard, |
|
|
|
} |
|
|
|
} |
|
|
@ -128,7 +141,8 @@ impl Display for WrData { |
|
|
|
match self { |
|
|
|
match self { |
|
|
|
WrData::Discard => f.write_str("_"), |
|
|
|
WrData::Discard => f.write_str("_"), |
|
|
|
WrData::Register(r) => write!(f, "{}", r), |
|
|
|
WrData::Register(r) => write!(f, "{}", r), |
|
|
|
WrData::ObjectPtr(r) => write!(f, "@{}", r) |
|
|
|
WrData::RegObject(r) => write!(f, "@{}", r), |
|
|
|
|
|
|
|
WrData::ImmObject(v) => write!(f, "@{:#x}", v), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -136,9 +150,10 @@ impl Display for WrData { |
|
|
|
impl From<WrData> for RdData { |
|
|
|
impl From<WrData> for RdData { |
|
|
|
fn from(s: WrData) -> Self { |
|
|
|
fn from(s: WrData) -> Self { |
|
|
|
match s { |
|
|
|
match s { |
|
|
|
|
|
|
|
WrData::ImmObject(x) => RdData::ImmObject(x), |
|
|
|
WrData::Register(x) => RdData::Register(x), |
|
|
|
WrData::Register(x) => RdData::Register(x), |
|
|
|
WrData::ObjectPtr(x) => RdData::ObjectPtr(x), |
|
|
|
WrData::RegObject(x) => RdData::RegObject(x), |
|
|
|
WrData::Discard => RdData::Immediate(0), |
|
|
|
WrData::Discard => RdData::Immediate(0), // this should not be allowed by the assembler
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -149,8 +164,9 @@ impl TryFrom<DataDisp> for WrData { |
|
|
|
fn try_from(value: DataDisp) -> Result<Self, Self::Error> { |
|
|
|
fn try_from(value: DataDisp) -> Result<Self, Self::Error> { |
|
|
|
match value { |
|
|
|
match value { |
|
|
|
DataDisp::Immediate(_x) => Err(AsmError::ValueAsOutput), |
|
|
|
DataDisp::Immediate(_x) => Err(AsmError::ValueAsOutput), |
|
|
|
|
|
|
|
DataDisp::ImmObject(x) => Ok(WrData::ImmObject(x)), |
|
|
|
DataDisp::Register(x) => Ok(WrData::Register(x)), |
|
|
|
DataDisp::Register(x) => Ok(WrData::Register(x)), |
|
|
|
DataDisp::ObjectPtr(x) => Ok(WrData::ObjectPtr(x)), |
|
|
|
DataDisp::RegObject(x) => Ok(WrData::RegObject(x)), |
|
|
|
DataDisp::Discard => Ok(WrData::Discard), |
|
|
|
DataDisp::Discard => Ok(WrData::Discard), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|