aboutsummaryrefslogtreecommitdiff
path: root/src/long_mode/display.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-06-18 23:14:03 -0700
committeriximeow <me@iximeow.net>2024-06-18 23:18:55 -0700
commitcc6f7cabfdd7e48f71241ffc8e4860be6d26ba93 (patch)
tree0e97e440fd503a4e77c367fdf4d14ba6ade1b210 /src/long_mode/display.rs
parent1dc74628d428e2e65c59147900ea44a9db7ab163 (diff)
helpers for those i8/u8 immediates too
Diffstat (limited to 'src/long_mode/display.rs')
-rw-r--r--src/long_mode/display.rs39
1 files changed, 2 insertions, 37 deletions
diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs
index d6e03a9..77111b8 100644
--- a/src/long_mode/display.rs
+++ b/src/long_mode/display.rs
@@ -1208,24 +1208,7 @@ impl <T: DisplaySink> crate::long_mode::OperandVisitor for ColorizingOperandVisi
fn visit_u8(&mut self, imm: u8) -> Result<Self::Ok, Self::Error> {
self.f.span_enter(TokenType::Immediate);
self.f.write_fixed_size("0x")?;
- let mut buf = [MaybeUninit::<u8>::uninit(); 2];
- let mut curr = buf.len();
- let mut v = imm;
- loop {
- let digit = v % 16;
- let c = c_to_hex(digit as u8);
- curr -= 1;
- buf[curr].write(c);
- v = v / 16;
- if v == 0 {
- break;
- }
- }
- let buf = &buf[curr..];
- let s: &str = unsafe {
- core::mem::transmute::<&[MaybeUninit<u8>], &str>(buf)
- };
- self.f.write_fixed_size(s)?;
+ self.f.write_u8(imm)?;
self.f.span_end(TokenType::Immediate);
Ok(())
}
@@ -1237,25 +1220,7 @@ impl <T: DisplaySink> crate::long_mode::OperandVisitor for ColorizingOperandVisi
v = -imm as u8;
}
self.f.write_fixed_size("0x")?;
- let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); 2];
- let mut curr = buf.len();
- loop {
- let digit = v % 16;
- let c = c_to_hex(digit as u8);
- curr -= 1;
- buf[curr].write(c);
- v = v / 16;
- if v == 0 {
- break;
- }
- }
- let buf = &buf[curr..];
- let s = unsafe {
- core::mem::transmute::<&[core::mem::MaybeUninit<u8>], &str>(buf)
- };
-
- // not actually fixed size, but this should optimize right i hope..
- self.f.write_fixed_size(s)?;
+ self.f.write_u8(v)?;
self.f.span_end(TokenType::Immediate);
Ok(())
}