summaryrefslogtreecommitdiff
path: root/src/display.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/display.rs')
-rw-r--r--src/display.rs39
1 files changed, 33 insertions, 6 deletions
diff --git a/src/display.rs b/src/display.rs
index 7836d10..f523e65 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -2,12 +2,12 @@ use ::{MSP430, Operand, Opcode, Instruction, Width, DecodeError};
use std::fmt::{self, Display, Formatter};
use std;
-use yaxpeax_arch::{Arch, Colorize, ColorSettings, ShowContextual};
+use yaxpeax_arch::{Arch, Colorize, ColorSettings, NoColors, ShowContextual, YaxColors};
impl Display for Instruction {
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
let mut s = String::new();
- self.contextualize(None, 0, None, &mut s).unwrap();
+ self.contextualize(&NoColors, 0, Some(&NoContext), &mut s).unwrap();
write!(f, "{}", s)
}
}
@@ -22,7 +22,34 @@ impl fmt::Display for DecodeError {
}
}
-impl <T: std::fmt::Write> ShowContextual<<MSP430 as Arch>::Address, [Option<String>], T> for Instruction {
+/// No per-operand when contextualizing an instruction.
+struct NoContext;
+
+impl <T: std::fmt::Write, Color: fmt::Display, Y: YaxColors<Color>> ShowContextual<<MSP430 as Arch>::Address, NoContext, Color, T, Y> for Instruction {
+ fn contextualize(&self, _colors: &Y, _address: <MSP430 as Arch>::Address, _context: Option<&NoContext>, out: &mut T) -> std::fmt::Result {
+ write!(out, "{}", self.opcode)?;
+ match self.op_width {
+ Width::B => { write!(out, ".b")? },
+ Width::W => { }
+ };
+ match self.operands[0] {
+ Operand::Nothing => return Ok(()),
+ x @ _ => {
+ write!(out, " {}", x)?;
+ }
+ };
+ match self.operands[1] {
+ Operand::Nothing => return Ok(()),
+ x @ _ => {
+ write!(out, ", {}", x)?;
+ }
+ };
+ Ok(())
+ }
+}
+
+#[cfg(feature="std")]
+impl <T: std::fmt::Write, Color: fmt::Display, Y: YaxColors<Color>> ShowContextual<<MSP430 as Arch>::Address, [Option<String>], Color, T, Y> for Instruction {
fn contextualize(&self, _colors: Option<&ColorSettings>, _address: <MSP430 as Arch>::Address, _context: Option<&[Option<String>]>, out: &mut T) -> std::fmt::Result {
write!(out, "{}", self.opcode)?;
match self.op_width {
@@ -84,13 +111,13 @@ impl Display for Opcode {
impl Display for Operand {
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
let mut s = String::new();
- self.colorize(None, &mut s).unwrap();
+ self.colorize(&NoColors, &mut s).unwrap();
write!(f, "{}", s)
}
}
-impl <T: std::fmt::Write> Colorize<T> for Operand {
- fn colorize(&self, _colors: Option<&ColorSettings>, out: &mut T) -> std::fmt::Result {
+impl <T: std::fmt::Write, Color: fmt::Display, Y: YaxColors<Color>> Colorize<T, Color, Y> for Operand {
+ fn colorize(&self, _colors: &Y, out: &mut T) -> std::fmt::Result {
fn signed_hex(num: i16) -> String {
if num >= 0 {
format!("+{:#x}", num)