diff --git a/Libraries/LibX86/Instruction.cpp b/Libraries/LibX86/Instruction.cpp index ff58e6a7ab..3d0ade3375 100644 --- a/Libraries/LibX86/Instruction.cpp +++ b/Libraries/LibX86/Instruction.cpp @@ -867,7 +867,7 @@ unsigned Instruction::length() const return len; } -static SegmentRegister to_segment_prefix(u8 op) +static Optional to_segment_prefix(u8 op) { switch (op) { case 0x26: @@ -883,7 +883,7 @@ static SegmentRegister to_segment_prefix(u8 op) case 0x65: return SegmentRegister::GS; default: - return SegmentRegister::None; + return {}; } } @@ -912,7 +912,7 @@ Instruction::Instruction(InstructionStream& stream, bool o32, bool a32) continue; } auto segment_prefix = to_segment_prefix(opbyte); - if (segment_prefix != SegmentRegister::None) { + if (segment_prefix.has_value()) { m_segment_prefix = segment_prefix; continue; } @@ -1269,8 +1269,8 @@ String Instruction::to_string(u32 origin, const SymbolProvider* symbol_provider, String osize_prefix; String rep_prefix; String lock_prefix; - if (has_segment_prefix()) { - segment_prefix = String::format("%s: ", register_name(m_segment_prefix)); + if (m_segment_prefix.has_value()) { + segment_prefix = String::format("%s: ", register_name(m_segment_prefix.value())); } if (has_address_size_override_prefix()) { asize_prefix = m_a32 ? "a32 " : "a16 "; diff --git a/Libraries/LibX86/Instruction.h b/Libraries/LibX86/Instruction.h index fa312466e5..24818ddbf5 100644 --- a/Libraries/LibX86/Instruction.h +++ b/Libraries/LibX86/Instruction.h @@ -26,6 +26,7 @@ #pragma once +#include #include #include #include @@ -75,7 +76,6 @@ enum class SegmentRegister { GS, SegR6, SegR7, - None = 0xFF, }; enum RegisterIndex8 { @@ -223,7 +223,7 @@ private: void decode32(InstructionStream&); unsigned m_register_index { 0xffffffff }; - SegmentRegister m_segment { SegmentRegister::None }; + SegmentRegister m_segment; union { u32 m_offset32 { 0 }; u16 m_offset16; @@ -259,7 +259,9 @@ public: InstructionHandler handler() const; - bool has_segment_prefix() const { return m_segment_prefix != SegmentRegister::None; } + bool has_segment_prefix() const { return m_segment_prefix.has_value(); } + Optional segment_prefix() const { return m_segment_prefix; } + 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; } bool has_lock_prefix() const { return m_has_lock_prefix; } @@ -360,7 +362,7 @@ private: unsigned m_imm2_bytes { 0 }; unsigned m_prefix_bytes { 0 }; - SegmentRegister m_segment_prefix { SegmentRegister::None }; + Optional m_segment_prefix; bool m_has_operand_size_override_prefix { false }; bool m_has_address_size_override_prefix { false }; u8 m_rep_prefix { 0 };