From 6440e59ead712220eaed225769082bb37d683b92 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 7 Jul 2020 21:12:40 +0200 Subject: [PATCH] LibX86: Expose some more things on X86::Instruction --- Libraries/LibX86/Instruction.cpp | 6 ++++++ Libraries/LibX86/Instruction.h | 11 +++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Libraries/LibX86/Instruction.cpp b/Libraries/LibX86/Instruction.cpp index 6f23c40d5c..ff58e6a7ab 100644 --- a/Libraries/LibX86/Instruction.cpp +++ b/Libraries/LibX86/Instruction.cpp @@ -1906,4 +1906,10 @@ void MemoryOrRegisterReference::decode32(InstructionStream& stream) } } +InstructionHandler Instruction::handler() const +{ + ASSERT(m_descriptor->handler); + return m_descriptor->handler; +} + } diff --git a/Libraries/LibX86/Instruction.h b/Libraries/LibX86/Instruction.h index 4dfa29aa0b..676dbb29f9 100644 --- a/Libraries/LibX86/Instruction.h +++ b/Libraries/LibX86/Instruction.h @@ -198,6 +198,8 @@ public: String to_string_mm() const; bool is_register() const { return m_register_index != 0xffffffff; } + + unsigned register_index() const { return m_register_index; } SegmentRegister segment() const { ASSERT(!is_register()); @@ -237,17 +239,22 @@ private: bool m_has_sib { false }; }; +class Interpreter; +typedef void (Interpreter::*InstructionHandler)(const Instruction&); + class Instruction { public: static Instruction from_stream(InstructionStream&, bool o32, bool a32); ~Instruction() {} - MemoryOrRegisterReference& modrm() + MemoryOrRegisterReference& modrm() const { ASSERT(has_rm()); return m_modrm; } + InstructionHandler handler() const; + bool has_segment_prefix() const { return m_segment_prefix != SegmentRegister::None; } bool has_address_size_override_prefix() const { return m_has_address_size_override_prefix; } bool has_operand_size_override_prefix() const { return m_has_operand_size_override_prefix; } @@ -350,7 +357,7 @@ private: bool m_has_address_size_override_prefix { false }; u8 m_rep_prefix { 0 }; - MemoryOrRegisterReference m_modrm; + mutable MemoryOrRegisterReference m_modrm; InstructionDescriptor* m_descriptor { nullptr }; };