use std::fmt;
#[derive(Clone, Debug, PartialEq)]
pub enum Op {
Aaa,
Aad,
Aam,
Aas,
Adc8, Adc16, Adc32,
Add8, Add16, Add32,
And8, And16, And32,
Arpl,
Bound,
Bsf,
Bt,
Bts,
CallNear, CallFar,
Cbw,
Clc,
Cld,
Cli,
Cmc,
Cmp8, Cmp16, Cmp32,
Cmpsb, Cmpsw,
Cwd16, Cwde32,
Daa,
Das,
Dec8, Dec16, Dec32,
Div8, Div16, Div32,
Enter,
Hlt,
Idiv8, Idiv16, Idiv32,
Imul8, Imul16, Imul32,
In8, In16,
Inc8, Inc16, Inc32,
Insb, Insw,
Int,
Into,
Iret,
Ja,
Jc,
Jcxz,
Jg,
Jl,
JmpShort, JmpNear, JmpFar,
Jna,
Jnc,
Jng,
Jnl,
Jno,
Jns,
Jnz,
Jo,
Jpe,
Jpo,
Js,
Jz,
Lahf,
Lds,
Lea16,
Leave,
Les,
Lodsb, Lodsw, Lodsd,
Loop, Loope, Loopne,
Mov8, Mov16, Mov32,
Movsb, Movsw, Movsd,
Movsx16, Movsx32,
Movzx16, Movzx32,
Mul8, Mul16, Mul32,
Neg8, Neg16, Neg32,
Nop,
Not8, Not16, Not32,
Or8, Or16, Or32,
Out8, Out16,
Outsb, Outsw,
Pop16, Pop32,
Popa16,
Popad32,
Popf,
Push16, Push32,
Pusha16,
Pushad32,
Pushf,
Rcl8, Rcl16, Rcl32,
Rcr8, Rcr16, Rcr32,
Retn, Retf, RetImm16,
Rol8, Rol16, Rol32,
Ror8, Ror16, Ror32,
Sahf,
Salc,
Sar8, Sar16, Sar32,
Sbb8, Sbb16, Sbb32,
Scasb, Scasw,
Setc,
Setg,
Setnz,
Shl8, Shl16, Shl32,
Shld,
Shr8, Shr16, Shr32,
Shrd,
Sldt,
Stc,
Std,
Sti,
Stosb, Stosw, Stosd,
Sub8, Sub16, Sub32,
Test8, Test16, Test32,
Xchg8, Xchg16, Xchg32,
Xlatb,
Xor8, Xor16, Xor32,
Uninitialized,
Invalid(Vec<u8>, Invalid),
}
impl fmt::Display for Op {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Op::Invalid(bytes, _) => {
let mut x = Vec::new();
for b in bytes {
x.push(format!("{:02X}", b));
}
write!(f, "INVALID {}", x.join(", "))
}
_ => write!(f, "{:?}", self),
}
}
}
impl Op {
pub fn is_valid(&self) -> bool {
match *self {
Op::Uninitialized | Op::Invalid(_, _) => false,
_ => true,
}
}
pub fn f6_index(&self) -> u8 {
match *self {
Op::Test8 => 0,
Op::Not8 => 2,
Op::Neg8 => 3,
Op::Mul8 => 4,
Op::Imul8 => 5,
Op::Div8 => 6,
Op::Idiv8 => 7,
_ => panic!("f6_index {:?}", self),
}
}
pub fn feff_index(&self) -> u8 {
match *self {
Op::Inc8 | Op::Inc16 | Op::Inc32 => 0,
Op::Dec8 | Op::Dec16 | Op::Dec32 => 1,
Op::CallNear => 2,
Op::JmpNear => 4,
Op::Push16 => 6,
_ => panic!("feff_index {:?}", self),
}
}
}
#[derive(Clone, Debug, PartialEq)]
pub enum Invalid {
Reg(u8),
Op,
FPUOp,
}