From 07f507e52d39779554f4d7c5827141c28d3d95c1 Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 6 May 2021 22:14:02 -0700 Subject: remove unneeded termion dep color schemes are defined by the provided YaxColors, not hardcoded by the crate update to yaxpeax-arch 0.0.5, which itself swaps termion for crossterm --- Cargo.toml | 5 +- src/lib.rs | 161 ++++++++++++++++++++++++++++++------------------------------- 2 files changed, 82 insertions(+), 84 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 735fb74..f28950f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,14 @@ [package] name = "yaxpeax-pic17" -version = "0.0.3" +version = "0.0.4" authors = [ "iximeow " ] license = "0BSD" repository = "http://git.iximeow.net/yaxpeax-pic17/" description = "pic17 decoders for the yaxpeax project" [dependencies] -yaxpeax-arch = { version = "0.0.4", default-features = false, features = [] } -"termion" = "1.4.0" +yaxpeax-arch = { version = "0.0.5", default-features = false, features = [] } "serde" = { version = "1.0", optional = true } "serde_derive" = { version = "1.0", optional = true } diff --git a/src/lib.rs b/src/lib.rs index 3083938..4d40e4a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,14 +6,11 @@ extern crate serde; //use serde::{Serialize, Deserialize}; extern crate yaxpeax_arch; -extern crate termion; use yaxpeax_arch::{Arch, AddressDiff, Colorize, Decoder, LengthedInstruction, ShowContextual, YaxColors}; use std::fmt::{self, Display, Formatter}; -use termion::color; - #[derive(Debug, Copy, Clone)] pub struct Instruction { pub opcode: Opcode, @@ -498,82 +495,84 @@ impl Decoder for InstDecoder { } } -pub fn opcode_color(opcode: Opcode) -> &'static color::Fg<&'static dyn color::Color> { - match opcode { - Opcode::Invalid(_, _) => &color::Fg(&color::Red), - Opcode::NOP => &color::Fg(&color::Blue), - Opcode::CPFSLT | - Opcode::CPFSEQ | - Opcode::CPFSGT | - Opcode::TSTFSZ | - Opcode::BTFSS | - Opcode::BTFSC | - Opcode::RETLW | - Opcode::LCALL | - Opcode::GOTO | - Opcode::CALL | - Opcode::RETURN => &color::Fg(&color::Green), - Opcode::SLEEP | - Opcode::CLRWDT | - Opcode::RETFIE => &color::Fg(&color::Cyan), - Opcode::MOVWF | - Opcode::MOVFP | - Opcode::MOVPF | - Opcode::MOVLW | - Opcode::MOVLB | - Opcode::MOVLR => &color::Fg(&color::LightMagenta), - Opcode::BSF | - Opcode::BCF | - Opcode::IORWF | - Opcode::ANDWF | - Opcode::XORWF | - Opcode::IORLW | - Opcode::XORLW | - Opcode::ANDLW | - Opcode::CLRF | - Opcode::SETF | - Opcode::BTG | - Opcode::COMF | - Opcode::RRCF | - Opcode::RLCF | - Opcode::RRNCF | - Opcode::RLNCF | - Opcode::SWAPF => &color::Fg(&color::LightYellow), - - Opcode::INFSNZ | - Opcode::DCFSNZ | - Opcode::DECFSZ | - Opcode::INCFSZ | - Opcode::SUBWFB | - Opcode::SUBWF | - Opcode::DECF | - Opcode::ADDWF | - Opcode::ADDWFC | - Opcode::INCF | - Opcode::MULWF | - Opcode::NEGW | - Opcode::DAW | - Opcode::ADDLW | - Opcode::SUBLW | - Opcode::MULLW => &color::Fg(&color::Yellow), - - Opcode::TLRDL | - Opcode::TLRDH | - Opcode::TLWTL | - Opcode::TLWTH | - Opcode::TABLRDL | - Opcode::TABLRDLI | - Opcode::TABLRDH | - Opcode::TABLRDHI | - Opcode::TABLWTL | - Opcode::TABLWTLI | - Opcode::TABLWTH | - Opcode::TABLWTHI => &color::Fg(&color::Magenta), +impl Colorize for Opcode { + fn colorize(&self, colors: &Y, out: &mut T) -> fmt::Result { + match self { + Opcode::Invalid(_, _) => { write!(out, "{}", colors.invalid_op(self)) }, + Opcode::NOP => { write!(out, "{}", colors.nop_op(self)) }, + Opcode::CPFSLT | + Opcode::CPFSEQ | + Opcode::CPFSGT | + Opcode::TSTFSZ | + Opcode::BTFSS | + Opcode::BTFSC | + Opcode::RETLW | + Opcode::LCALL | + Opcode::GOTO | + Opcode::CALL | + Opcode::RETURN => { write!(out, "{}", colors.control_flow_op(self)) }, + Opcode::SLEEP | + Opcode::CLRWDT | + Opcode::RETFIE => { write!(out, "{}", colors.misc_op(self)) }, + Opcode::MOVWF | + Opcode::MOVFP | + Opcode::MOVPF | + Opcode::MOVLW | + Opcode::MOVLB | + Opcode::MOVLR => { write!(out, "{}", colors.data_op(self)) } + Opcode::BSF | + Opcode::BCF | + Opcode::IORWF | + Opcode::ANDWF | + Opcode::XORWF | + Opcode::IORLW | + Opcode::XORLW | + Opcode::ANDLW | + Opcode::CLRF | + Opcode::SETF | + Opcode::BTG | + Opcode::COMF | + Opcode::RRCF | + Opcode::RLCF | + Opcode::RRNCF | + Opcode::RLNCF | + Opcode::SWAPF => { write!(out, "{}", colors.arithmetic_op(self)) }, + + Opcode::INFSNZ | + Opcode::DCFSNZ | + Opcode::DECFSZ | + Opcode::INCFSZ | + Opcode::SUBWFB | + Opcode::SUBWF | + Opcode::DECF | + Opcode::ADDWF | + Opcode::ADDWFC | + Opcode::INCF | + Opcode::MULWF | + Opcode::NEGW | + Opcode::DAW | + Opcode::ADDLW | + Opcode::SUBLW | + Opcode::MULLW => { write!(out, "{}", colors.arithmetic_op(self)) }, + + Opcode::TLRDL | + Opcode::TLRDH | + Opcode::TLWTL | + Opcode::TLWTH | + Opcode::TABLRDL | + Opcode::TABLRDLI | + Opcode::TABLRDH | + Opcode::TABLRDHI | + Opcode::TABLWTL | + Opcode::TABLWTLI | + Opcode::TABLWTH | + Opcode::TABLWTHI => { write!(out, "{}", colors.platform_op(self)) }, + } } } -impl > Colorize for Operand { - fn colorize(&self, _colors: &Y, out: &mut T) -> 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) @@ -583,13 +582,13 @@ impl > Colorize for Ope }, Operand::File(f) => { if *f < 0x10 { - write!(out, "{}0x{:02x}{}", color::Fg(color::Yellow), f, color::Fg(color::Reset)) + write!(out, "{}", colors.number(format!("0x{:02x}", f))) } else { - write!(out, "{}[banked 0x{:02x}]{}", color::Fg(color::Yellow), f, color::Fg(color::Reset)) + write!(out, "{}", colors.number(format!("[banked 0x{:02x}]", f))) } }, Operand::W => { - write!(out, "{}W{}", color::Fg(color::Yellow), color::Fg(color::Reset)) + write!(out, "{}", colors.register("W")) }, _ => { Ok(()) @@ -598,9 +597,9 @@ impl > Colorize for Ope } } -impl > ShowContextual<::Address, [Option], C, T, Y> for Instruction { +impl ShowContextual<::Address, [Option], 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))?; + self.opcode.colorize(colors, out)?; match self.opcode { Opcode::LCALL => { -- cgit v1.1