summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2020-01-12 17:08:45 -0800
committeriximeow <me@iximeow.net>2020-01-12 17:08:45 -0800
commit9a1d438b6bfc38bfef1841786c03032143cad8b9 (patch)
treead041301a5fe94a1f1812f254aea704bb1c8f6d6 /src
parent8734e0cea4778fbdc9f93a70f86e709b14ce2fb3 (diff)
parent274fdaf33a7debb32e95ab57a41f9c03b173e164 (diff)
Merge remote-tracking branch 'master'
Diffstat (limited to 'src')
-rw-r--r--src/display.rs66
-rw-r--r--src/lib.rs1
2 files changed, 44 insertions, 23 deletions
diff --git a/src/display.rs b/src/display.rs
index 7864248..b51ae9b 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -1,25 +1,38 @@
-use std;
-use std::fmt::{Display, Formatter};
+use ::{MSP430, Operand, Opcode, Instruction, Width};
-use ::{Operand, Opcode, Instruction, Width};
+use std::collections::HashMap;
+use std::fmt::{Display, Formatter};
+use std::hash::Hash;
+use std::rc::Rc;
+use std;
+use termion::color;
+use yaxpeax_arch::{Arch, Colorize, ColorSettings, LengthedInstruction, ShowContextual};
impl Display for Instruction {
fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> {
- write!(f, "{}", self.opcode)?;
+ let mut s = String::new();
+ self.contextualize(None, 0, None, &mut s).unwrap();
+ write!(f, "{}", s)
+ }
+}
+
+impl <T: std::fmt::Write> ShowContextual<<MSP430 as Arch>::Address, [Option<String>], T> 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 {
- Width::B => { write!(f, ".b")? },
+ Width::B => { write!(out, ".b")? },
Width::W => { }
};
match self.operands[0] {
Operand::Nothing => return Ok(()),
x @ _ => {
- write!(f, " {}", x)?;
+ write!(out, " {}", x)?;
}
};
match self.operands[1] {
Operand::Nothing => return Ok(()),
x @ _ => {
- write!(f, ", {}", x)?;
+ write!(out, ", {}", x)?;
}
};
Ok(())
@@ -64,6 +77,14 @@ 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();
+ write!(f, "{}", s)
+ }
+}
+
+impl <T: std::fmt::Write> Colorize<T> for Operand {
+ fn colorize(&self, colors: Option<&ColorSettings>, out: &mut T) -> std::fmt::Result {
fn signed_hex(num: i16) -> String {
if num >= 0 {
format!("+{:#x}", num)
@@ -73,51 +94,50 @@ impl Display for Operand {
}
match self {
Operand::Register(reg) => {
- write!(f, "R{}", reg)
+ write!(out, "R{}", reg)
},
Operand::Indexed(reg, offset) => {
- write!(f, "{}(R{})", signed_hex(*offset as i16), reg)
+ write!(out, "{}(R{})", signed_hex(*offset as i16), reg)
},
Operand::RegisterIndirect(reg) => {
- write!(f, "@R{}", reg)
+ write!(out, "@R{}", reg)
},
Operand::IndirectAutoinc(reg) => {
- write!(f, "@R{}+", reg)
+ write!(out, "@R{}+", reg)
},
Operand::Offset(offset) => {
- write!(f, "${}", signed_hex(*offset as i16))
+ write!(out, "${}", signed_hex(*offset as i16))
},
Operand::Symbolic(offset) => {
- write!(f, "{}(PC)", signed_hex(*offset as i16))
+ write!(out, "{}(PC)", signed_hex(*offset as i16))
},
Operand::Immediate(imm) => {
- write!(f, "#0x{:x}", imm)
+ write!(out, "#0x{:x}", imm)
},
Operand::Absolute(offset) => {
- write!(f, "&0x{:x}", offset)
+ write!(out, "&0x{:x}", offset)
},
Operand::Const4 => {
- write!(f, "4")
+ write!(out, "4")
},
Operand::Const8 => {
- write!(f, "8")
+ write!(out, "8")
},
Operand::Const0 => {
- write!(f, "0")
+ write!(out, "0")
},
Operand::Const1 => {
- write!(f, "1")
+ write!(out, "1")
},
Operand::Const2 => {
- write!(f, "2")
+ write!(out, "2")
},
Operand::ConstNeg1 => {
- write!(f, "-1")
+ write!(out, "-1")
},
Operand::Nothing => {
- write!(f, "<No Operand>")
+ write!(out, "<No Operand>")
}
}
}
}
-
diff --git a/src/lib.rs b/src/lib.rs
index c215b68..81ceceb 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,4 +1,5 @@
extern crate yaxpeax_arch;
+extern crate termion;
use yaxpeax_arch::{Arch, Decodable, LengthedInstruction};