From a66be66c22bc31526ac35c1cffdb28992a392ccf Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 22 Jun 2024 11:03:43 -0700 Subject: move DisplaySink code out from yaxpeax-x86 it was built in-place around yaxpeax-x86, hoisted out once it seemed suitable and could be generalized. yay! also include a Makefile in yaxpeax-arch now to test that various crate feature flag combinations.. work. --- src/display.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/display.rs') diff --git a/src/display.rs b/src/display.rs index 789919e..77f6ba9 100644 --- a/src/display.rs +++ b/src/display.rs @@ -1,9 +1,32 @@ +// allow use of deprecated items in this module since some functions using `SignedHexDisplay` still +// exist here +#![allow(deprecated)] + use crate::YaxColors; use core::fmt; use core::num::Wrapping; use core::ops::Neg; +mod display_sink; + +pub use display_sink::{DisplaySink, FmtSink, InstructionTextSink}; + +/// translate a byte in range `[0, 15]` to a lowercase base-16 digit. +/// +/// if `c` is in range, the output is always valid as the sole byte in a utf-8 string. if `c` is out +/// of range, the returned character might not be a valid single-byte utf-8 codepoint. +fn u8_to_hex(c: u8) -> u8 { + // this conditional branch is faster than a lookup for... most architectures (especially x86 + // with cmov) + if c < 10 { + b'0' + c + } else { + b'a' + c - 10 + } +} + +#[deprecated(since="0.3.0", note="format_number_i32 does not optimize as expected and will be removed in the future. see DisplaySink instead.")] pub enum NumberStyleHint { Signed, HexSigned, @@ -17,6 +40,7 @@ pub enum NumberStyleHint { HexUnsignedWithSign } +#[deprecated(since="0.3.0", note="format_number_i32 is both slow and incorrect: YaxColors may not result in correct styling when writing anywhere other than a terminal, and both stylin and formatting does not inline as well as initially expected. see DisplaySink instead.")] pub fn format_number_i32(colors: &Y, f: &mut W, i: i32, hint: NumberStyleHint) -> fmt::Result { match hint { NumberStyleHint::Signed => { @@ -64,6 +88,7 @@ pub fn format_number_i32(colors: &Y, f: &mut W, i: } } +#[deprecated(since="0.3.0", note="SignedHexDisplay does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub struct SignedHexDisplay { value: T, negative: bool @@ -79,6 +104,7 @@ impl fmt::Display for SignedHexDisplay where W } } +#[deprecated(since="0.3.0", note="u8_hex does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub fn u8_hex(value: u8) -> SignedHexDisplay { SignedHexDisplay { value: value as i8, @@ -86,6 +112,7 @@ pub fn u8_hex(value: u8) -> SignedHexDisplay { } } +#[deprecated(since="0.3.0", note="signed_i8_hex does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub fn signed_i8_hex(imm: i8) -> SignedHexDisplay { SignedHexDisplay { value: imm, @@ -93,6 +120,7 @@ pub fn signed_i8_hex(imm: i8) -> SignedHexDisplay { } } +#[deprecated(since="0.3.0", note="u16_hex does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub fn u16_hex(value: u16) -> SignedHexDisplay { SignedHexDisplay { value: value as i16, @@ -100,6 +128,7 @@ pub fn u16_hex(value: u16) -> SignedHexDisplay { } } +#[deprecated(since="0.3.0", note="signed_i16_hex does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub fn signed_i16_hex(imm: i16) -> SignedHexDisplay { SignedHexDisplay { value: imm, @@ -107,6 +136,7 @@ pub fn signed_i16_hex(imm: i16) -> SignedHexDisplay { } } +#[deprecated(since="0.3.0", note="u32_hex does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub fn u32_hex(value: u32) -> SignedHexDisplay { SignedHexDisplay { value: value as i32, @@ -114,6 +144,7 @@ pub fn u32_hex(value: u32) -> SignedHexDisplay { } } +#[deprecated(since="0.3.0", note="signed_i32_hex does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub fn signed_i32_hex(imm: i32) -> SignedHexDisplay { SignedHexDisplay { value: imm, @@ -121,6 +152,7 @@ pub fn signed_i32_hex(imm: i32) -> SignedHexDisplay { } } +#[deprecated(since="0.3.0", note="u64_hex does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub fn u64_hex(value: u64) -> SignedHexDisplay { SignedHexDisplay { value: value as i64, @@ -128,6 +160,7 @@ pub fn u64_hex(value: u64) -> SignedHexDisplay { } } +#[deprecated(since="0.3.0", note="signed_i64_hex does not optimize like expected and will be removed in the future. see DisplaySink instead.")] pub fn signed_i64_hex(imm: i64) -> SignedHexDisplay { SignedHexDisplay { value: imm, -- cgit v1.1