From 3a1de246641e14e51dc138120d67842448c2bf21 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 3 Jul 2021 16:18:28 -0700 Subject: factor out MemoryAccessSize --- src/lib.rs | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/lib.rs') 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 { + if self.size == 63 { + None + } else { + Some(self.size) + } + } + + pub fn size_name(&self) -> &'static str { + MEM_SIZE_STRINGS[self.size as usize - 1] + } +} -- cgit v1.1