2022-04-06 05:07:57 -07:00
|
|
|
use std::fmt::{Display, Formatter};
|
2021-08-15 01:32:46 -07:00
|
|
|
|
2021-08-28 21:06:08 -07:00
|
|
|
use crate::prelude::*;
|
2021-08-15 01:32:46 -07:00
|
|
|
|
2021-08-28 21:06:08 -07:00
|
|
|
pub struct FormattedIns(pub Ins);
|
2021-08-14 18:53:38 -07:00
|
|
|
|
2021-08-28 21:06:08 -07:00
|
|
|
impl Display for FormattedIns {
|
|
|
|
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
2022-04-06 17:14:11 -07:00
|
|
|
let simple = self.0.clone().simplified();
|
2022-10-10 14:53:24 -07:00
|
|
|
write!(f, "{}{}", simple.mnemonic, simple.suffix)?;
|
2021-08-28 21:06:08 -07:00
|
|
|
let mut writing_offset = false;
|
2022-04-06 17:14:11 -07:00
|
|
|
for (i, arg) in simple.args.iter().enumerate() {
|
2022-04-06 17:36:49 -07:00
|
|
|
if i == 0 {
|
|
|
|
write!(f, " ")?;
|
|
|
|
}
|
|
|
|
if i > 0 && !writing_offset {
|
2022-04-06 17:14:11 -07:00
|
|
|
write!(f, ", ")?;
|
2022-04-06 05:07:57 -07:00
|
|
|
}
|
2022-04-06 17:36:49 -07:00
|
|
|
if let Argument::Offset(val) = arg {
|
|
|
|
write!(f, "{}(", val)?;
|
2021-08-28 21:06:08 -07:00
|
|
|
writing_offset = true;
|
|
|
|
continue;
|
2022-04-06 17:14:11 -07:00
|
|
|
} else {
|
|
|
|
write!(f, "{}", arg)?;
|
2021-08-28 21:06:08 -07:00
|
|
|
}
|
|
|
|
if writing_offset {
|
|
|
|
write!(f, ")")?;
|
2021-08-28 21:29:49 -07:00
|
|
|
writing_offset = false;
|
2021-08-28 21:06:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
2021-08-14 18:53:38 -07:00
|
|
|
}
|
|
|
|
}
|