neo_decompiler/instruction/
operand.rs1use std::fmt;
2
3use crate::syscalls;
4use crate::util;
5
6#[derive(Debug, Clone, PartialEq, Eq, Hash)]
8#[non_exhaustive]
9pub enum Operand {
10 I8(i8),
12 I16(i16),
14 I32(i32),
16 I64(i64),
18 Bytes(Vec<u8>),
20 Jump(i8),
22 Jump32(i32),
24 Syscall(u32),
26 U8(u8),
28 U16(u16),
30 U32(u32),
32 Bool(bool),
34 Null,
36}
37
38impl fmt::Display for Operand {
39 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
40 match self {
41 Operand::I8(v) => write!(f, "{v}"),
42 Operand::I16(v) => write!(f, "{v}"),
43 Operand::I32(v) => write!(f, "{v}"),
44 Operand::I64(v) => write!(f, "{v}"),
45 Operand::Bytes(bytes) => {
46 write!(f, "0x")?;
47 util::write_upper_hex(f, bytes)
48 }
49 Operand::Jump(offset) => write!(f, "{offset}"),
50 Operand::Jump32(offset) => write!(f, "{offset}"),
51 Operand::Syscall(hash) => {
52 if let Some(info) = syscalls::lookup(*hash) {
53 write!(f, "{} (0x{hash:08X})", info.name)
54 } else {
55 write!(f, "0x{hash:08X}")
56 }
57 }
58 Operand::U8(value) => write!(f, "{value}"),
59 Operand::U16(value) => write!(f, "{value}"),
60 Operand::U32(value) => write!(f, "{value}"),
61 Operand::Bool(value) => write!(f, "{value}"),
62 Operand::Null => write!(f, "null"),
63 }
64 }
65}