use std::fmt;
use crate::syscalls;
use crate::util;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[non_exhaustive]
pub enum Operand {
I8(i8),
I16(i16),
I32(i32),
I64(i64),
Bytes(Vec<u8>),
Jump(i8),
Jump32(i32),
Syscall(u32),
U8(u8),
U16(u16),
U32(u32),
Bool(bool),
Null,
}
impl fmt::Display for Operand {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Operand::I8(v) => write!(f, "{v}"),
Operand::I16(v) => write!(f, "{v}"),
Operand::I32(v) => write!(f, "{v}"),
Operand::I64(v) => write!(f, "{v}"),
Operand::Bytes(bytes) => {
write!(f, "0x")?;
util::write_upper_hex(f, bytes)
}
Operand::Jump(offset) => write!(f, "{offset}"),
Operand::Jump32(offset) => write!(f, "{offset}"),
Operand::Syscall(hash) => {
if let Some(info) = syscalls::lookup(*hash) {
write!(f, "{} (0x{hash:08X})", info.name)
} else {
write!(f, "0x{hash:08X}")
}
}
Operand::U8(value) => write!(f, "{value}"),
Operand::U16(value) => write!(f, "{value}"),
Operand::U32(value) => write!(f, "{value}"),
Operand::Bool(value) => write!(f, "{value}"),
Operand::Null => write!(f, "null"),
}
}
}