From 8713eca470b00a7afc2d3d18b3fbe13c77806bc0 Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 16 Jan 2020 23:53:37 -0800 Subject: compat with yaxpeax-arch changes, make microcorruption msp430 support optional --- src/display.rs | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'src/display.rs') 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 ShowContextual<::Address, [Option], T> for Instruction { +/// No per-operand when contextualizing an instruction. +struct NoContext; + +impl > ShowContextual<::Address, NoContext, Color, T, Y> for Instruction { + fn contextualize(&self, _colors: &Y, _address: ::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 > ShowContextual<::Address, [Option], Color, T, Y> for Instruction { fn contextualize(&self, _colors: Option<&ColorSettings>, _address: ::Address, _context: Option<&[Option]>, 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 Colorize for Operand { - fn colorize(&self, _colors: Option<&ColorSettings>, out: &mut T) -> std::fmt::Result { +impl > Colorize 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) -- cgit v1.1