From 7bf72c8e37d252506b2a1474340d04482f117cf9 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 18 Jan 2020 14:32:37 -0800 Subject: start getting pic17 towards no_std, use yaxpeax-arch --- src/lib.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/lib.rs b/src/lib.rs index ebfb914..e8775eb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ extern crate serde; extern crate yaxpeax_arch; extern crate termion; -use yaxpeax_arch::{Arch, ColorSettings, Colorize, Decoder, LengthedInstruction, ShowContextual}; +use yaxpeax_arch::{Arch, Colorize, Decoder, LengthedInstruction, ShowContextual, YaxColors}; use std::fmt::{self, Display, Formatter}; @@ -37,7 +37,7 @@ impl Arch for PIC17 { } impl Display for Instruction { - fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { + fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { write!(f, "{}", self.opcode)?; match self.operands[0] { Operand::Nothing => return Ok(()), @@ -95,14 +95,16 @@ impl yaxpeax_arch::Instruction for Instruction { fn well_defined(&self) -> bool { true } } -impl Instruction { - pub fn blank() -> Instruction { +impl Default for Instruction { + fn default() -> Instruction { Instruction { opcode: Opcode::NOP, operands: [Operand::Nothing, Operand::Nothing] } } +} +impl Instruction { pub fn is_call(&self) -> bool { match self.opcode { Opcode::CALL | Opcode::LCALL => { true }, @@ -183,7 +185,7 @@ pub enum Opcode { } impl Display for Opcode { - fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { + fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { match self { Opcode::Invalid(a, b) => { write!(f, "invalid({:02x}{:02x})", a, b) }, Opcode::NOP => { write!(f, "nop") }, @@ -287,7 +289,7 @@ impl Operand { } impl Display for Operand { - fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { + fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> { match self { Operand::ImmediateU8(imm) => { write!(f, "#0x{:x}", imm) @@ -314,10 +316,6 @@ pub struct InstDecoder {} impl Decoder for InstDecoder { type Error = DecodeError; - fn decode>(&self, bytes: T) -> Result { - let mut blank = Instruction::blank(); - self.decode_into(&mut blank, bytes).map(|_: ()| blank) - } fn decode_into>(&self, inst: &mut Instruction, bytes: T) -> Result<(), DecodeError> { let mut bytes_iter = bytes.into_iter(); let word: Vec = bytes_iter.by_ref().take(2).collect(); @@ -574,8 +572,8 @@ pub fn opcode_color(opcode: Opcode) -> &'static color::Fg<&'static dyn color::Co } } -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) -> fmt::Result { match self { Operand::ImmediateU8(i) => { write!(out, "#{:02x}", i) @@ -600,8 +598,8 @@ impl Colorize for Operand { } } -impl ShowContextual<::Address, [Option], T> for Instruction { - fn contextualize(&self, colors: Option<&ColorSettings>, _address: ::Address, context: Option<&[Option]>, out: &mut T) -> std::fmt::Result { +impl > ShowContextual<::Address, [Option], C, T, Y> for Instruction { + fn contextualize(&self, colors: &Y, _address: ::Address, context: Option<&[Option]>, out: &mut T) -> fmt::Result { write!(out, "{}{}{}", opcode_color(self.opcode), self.opcode, color::Fg(color::Reset))?; match self.opcode { -- cgit v1.1