aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2021-07-03 16:18:28 -0700
committeriximeow <me@iximeow.net>2021-07-03 16:18:28 -0700
commit3a1de246641e14e51dc138120d67842448c2bf21 (patch)
tree0702a788bf16db67b0559aa49f44604564dd9ebb
parent282645e18ac920b2c1051a0bdf3e3236ee5839d6 (diff)
factor out MemoryAccessSize
-rw-r--r--src/lib.rs28
-rw-r--r--src/long_mode/display.rs6
-rw-r--r--src/long_mode/mod.rs30
-rw-r--r--src/protected_mode/display.rs13
-rw-r--r--src/protected_mode/mod.rs30
-rw-r--r--test/long_mode/operand.rs3
-rw-r--r--test/protected_mode/operand.rs3
7 files changed, 42 insertions, 71 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 30ac2e7..664307f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -18,3 +18,31 @@ pub use protected_mode::Arch as x86_32;
mod real_mode;
pub use real_mode::Arch as x86_16;
+
+const MEM_SIZE_STRINGS: [&'static str; 64] = [
+ "byte", "word", "BUG", "dword", "far", "ptr", "BUG", "qword",
+ "far", "mword", "BUG", "BUG", "BUG", "BUG", "BUG", "xmmword",
+ "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
+ "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ymmword",
+ "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
+ "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
+ "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
+ "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ptr", "zmmword",
+];
+
+pub struct MemoryAccessSize {
+ size: u8,
+}
+impl MemoryAccessSize {
+ pub fn bytes_size(&self) -> Option<u8> {
+ if self.size == 63 {
+ None
+ } else {
+ Some(self.size)
+ }
+ }
+
+ pub fn size_name(&self) -> &'static str {
+ MEM_SIZE_STRINGS[self.size as usize - 1]
+ }
+}
diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs
index d042119..f4d7a2c 100644
--- a/src/long_mode/display.rs
+++ b/src/long_mode/display.rs
@@ -1,5 +1,7 @@
extern crate yaxpeax_arch;
+use MEM_SIZE_STRINGS;
+
use core::fmt;
use yaxpeax_arch::{Colorize, ShowContextual, NoColors, YaxColors};
@@ -3334,7 +3336,7 @@ fn contextualize_intel<T: fmt::Write, Y: YaxColors>(instr: &Instruction, colors:
let x = Operand::from_spec(instr, instr.operands[0]);
if x.is_memory() {
- out.write_str(super::MEM_SIZE_STRINGS[instr.mem_size as usize - 1])?;
+ out.write_str(MEM_SIZE_STRINGS[instr.mem_size as usize - 1])?;
out.write_str(" ")?;
}
@@ -3354,7 +3356,7 @@ fn contextualize_intel<T: fmt::Write, Y: YaxColors>(instr: &Instruction, colors:
out.write_str(", ")?;
let x = Operand::from_spec(instr, instr.operands[i as usize]);
if x.is_memory() {
- out.write_str(super::MEM_SIZE_STRINGS[instr.mem_size as usize - 1])?;
+ out.write_str(MEM_SIZE_STRINGS[instr.mem_size as usize - 1])?;
out.write_str(" ")?;
}
if let Some(prefix) = instr.segment_override_for_op(i) {
diff --git a/src/long_mode/mod.rs b/src/long_mode/mod.rs
index 4babca3..2cda6e4 100644
--- a/src/long_mode/mod.rs
+++ b/src/long_mode/mod.rs
@@ -4,6 +4,8 @@ mod evex;
mod display;
pub mod uarch;
+use MemoryAccessSize;
+
#[cfg(feature = "fmt")]
pub use self::display::DisplayStyle;
@@ -4203,34 +4205,6 @@ impl Default for Instruction {
}
}
-const MEM_SIZE_STRINGS: [&'static str; 64] = [
- "byte", "word", "BUG", "dword", "BUG", "BUG", "BUG", "qword",
- "far", "mword", "BUG", "BUG", "BUG", "BUG", "BUG", "xmmword",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ymmword",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ptr", "zmmword",
-];
-
-pub struct MemoryAccessSize {
- size: u8,
-}
-impl MemoryAccessSize {
- pub fn bytes_size(&self) -> Option<u8> {
- if self.size == 63 {
- None
- } else {
- Some(self.size)
- }
- }
-
- pub fn size_name(&self) -> &'static str {
- MEM_SIZE_STRINGS[self.size as usize - 1]
- }
-}
-
impl Instruction {
pub fn opcode(&self) -> Opcode {
self.opcode
diff --git a/src/protected_mode/display.rs b/src/protected_mode/display.rs
index ac869aa..32eeace 100644
--- a/src/protected_mode/display.rs
+++ b/src/protected_mode/display.rs
@@ -1,5 +1,7 @@
extern crate yaxpeax_arch;
+use MEM_SIZE_STRINGS;
+
use core::fmt;
use yaxpeax_arch::{Colorize, ShowContextual, NoColors, YaxColors};
@@ -3321,17 +3323,6 @@ impl Instruction {
}
}
-const MEM_SIZE_STRINGS: [&'static str; 64] = [
- "byte", "word", "BUG", "dword", "far", "ptr", "BUG", "qword",
- "BUG", "mword", "BUG", "BUG", "BUG", "BUG", "BUG", "xmmword",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ymmword",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ptr", "zmmword",
-];
-
fn contextualize_intel<T: fmt::Write, Y: YaxColors>(instr: &Instruction, colors: &Y, _address: u32, _context: Option<&NoContext>, out: &mut T) -> fmt::Result {
if instr.prefixes.lock() {
write!(out, "lock ")?;
diff --git a/src/protected_mode/mod.rs b/src/protected_mode/mod.rs
index a088ad6..5e19676 100644
--- a/src/protected_mode/mod.rs
+++ b/src/protected_mode/mod.rs
@@ -4,6 +4,8 @@ mod evex;
mod display;
pub mod uarch;
+use MemoryAccessSize;
+
#[cfg(feature = "fmt")]
pub use self::display::DisplayStyle;
@@ -4112,34 +4114,6 @@ impl Default for Instruction {
}
}
-const MEM_SIZE_STRINGS: [&'static str; 64] = [
- "byte", "word", "BUG", "dword", "far", "ptr", "BUG", "qword",
- "BUG", "mword", "BUG", "BUG", "BUG", "BUG", "BUG", "xmmword",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ymmword",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "BUG",
- "BUG", "BUG", "BUG", "BUG", "BUG", "BUG", "ptr", "zmmword",
-];
-
-pub struct MemoryAccessSize {
- size: u8,
-}
-impl MemoryAccessSize {
- pub fn bytes_size(&self) -> Option<u8> {
- if self.size == 63 {
- None
- } else {
- Some(self.size)
- }
- }
-
- pub fn size_name(&self) -> &'static str {
- MEM_SIZE_STRINGS[self.size as usize - 1]
- }
-}
-
impl Instruction {
pub fn opcode(&self) -> Opcode {
self.opcode
diff --git a/test/long_mode/operand.rs b/test/long_mode/operand.rs
index 5a51ef3..7be8d82 100644
--- a/test/long_mode/operand.rs
+++ b/test/long_mode/operand.rs
@@ -1,4 +1,5 @@
-use yaxpeax_x86::long_mode::{InstDecoder, MemoryAccessSize, Operand, RegSpec};
+use yaxpeax_x86::long_mode::{InstDecoder, Operand, RegSpec};
+use yaxpeax_x86::MemoryAccessSize;
#[test]
fn register_widths() {
diff --git a/test/protected_mode/operand.rs b/test/protected_mode/operand.rs
index b2d3624..fd850da 100644
--- a/test/protected_mode/operand.rs
+++ b/test/protected_mode/operand.rs
@@ -1,4 +1,5 @@
-use yaxpeax_x86::protected_mode::{InstDecoder, MemoryAccessSize, Operand, RegSpec};
+use yaxpeax_x86::protected_mode::{InstDecoder, Operand, RegSpec};
+use yaxpeax_x86::MemoryAccessSize;
#[test]
fn register_widths() {