From 9835359ed86e3cb570418bc15234fbb7aca4cee8 Mon Sep 17 00:00:00 2001 From: iximeow Date: Mon, 13 Jan 2020 19:58:05 -0800 Subject: add Default impl for Instruction to track yaxpeax-arch --- src/lib.rs | 8 ++++++++ test/test.rs | 22 ++-------------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index a2c27d0..9409ca9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2485,6 +2485,12 @@ impl Opcode { } } +impl Default for Instruction { + fn default() -> Self { + Instruction::invalid() + } +} + impl Instruction { pub fn operand(&self, i: u8) -> Operand { assert!(i < 4); @@ -2528,12 +2534,14 @@ impl Instruction { operands: [OperandSpec::Nothing; 4], } } + pub fn is_invalid(&self) -> bool { match self.opcode { Opcode::Invalid => true, _ => false } } + pub fn segment_override_for_op(&self, op: u8) -> Option { match self.opcode { Opcode::STOS => { diff --git a/test/test.rs b/test/test.rs index 7726bb7..0ffc1c4 100644 --- a/test/test.rs +++ b/test/test.rs @@ -3,26 +3,8 @@ extern crate yaxpeax_x86; use std::fmt::Write; -use yaxpeax_arch::Decoder; -use yaxpeax_x86::{Instruction, InstDecoder, decode_one}; - -#[allow(dead_code)] -fn decode(bytes: &[u8]) -> Option { - let mut instr = Instruction::invalid(); - match decode_one(&InstDecoder::default(), bytes.iter().map(|x| *x).take(16).collect::>(), &mut instr) { - Ok(()) => Some(instr), - _ => None - } -} - -#[allow(dead_code)] -fn decode_as(decoder: &InstDecoder, bytes: &[u8]) -> Option { - let mut instr = Instruction::invalid(); - match decode_one(decoder, bytes.iter().map(|x| *x).take(16).collect::>(), &mut instr) { - Ok(()) => Some(instr), - _ => None - } -} +use yaxpeax_arch::{Decoder, LengthedInstruction}; +use yaxpeax_x86::{Instruction, InstDecoder}; fn test_invalid(data: &[u8]) { test_invalid_under(&InstDecoder::default(), data); -- cgit v1.1