diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-04 12:58:30 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-04 13:49:15 +0200 |
commit | a75af443d4a3a8fd266d701677a38bae659088cb (patch) | |
tree | dc54ef298cbc8f89887859c205a9bd4df7be8d83 /Libraries | |
parent | 57b2b96a6728bd86d3a9fc20dc4c80385a535a0d (diff) | |
download | serenity-a75af443d4a3a8fd266d701677a38bae659088cb.zip |
LibX86: Simplify "register index to string" functions a bit
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibX86/Instruction.cpp | 111 |
1 files changed, 10 insertions, 101 deletions
diff --git a/Libraries/LibX86/Instruction.cpp b/Libraries/LibX86/Instruction.cpp index e97c40ea3f..b9083a377c 100644 --- a/Libraries/LibX86/Instruction.cpp +++ b/Libraries/LibX86/Instruction.cpp @@ -1770,123 +1770,32 @@ String Instruction::mnemonic() const const char* register_name(SegmentRegister index) { - switch (index) { - case SegmentRegister::CS: - return "cs"; - case SegmentRegister::DS: - return "ds"; - case SegmentRegister::ES: - return "es"; - case SegmentRegister::SS: - return "ss"; - case SegmentRegister::FS: - return "fs"; - case SegmentRegister::GS: - return "gs"; - case SegmentRegister::SegR6: - return "segr6"; - case SegmentRegister::SegR7: - return "segr7"; - default: - ASSERT_NOT_REACHED(); - return nullptr; - } + static constexpr const char* names[] = { "es", "cs", "ss", "ds", "fs", "gs", "segr6", "segr7" }; + return names[(int)index & 7]; } const char* register_name(RegisterIndex8 register_index) { - switch (register_index) { - case RegisterAL: - return "al"; - case RegisterBL: - return "bl"; - case RegisterCL: - return "cl"; - case RegisterDL: - return "dl"; - case RegisterAH: - return "ah"; - case RegisterBH: - return "bh"; - case RegisterCH: - return "ch"; - case RegisterDH: - return "dh"; - } - ASSERT_NOT_REACHED(); - return nullptr; + static constexpr const char* names[] = { "al", "cl", "dl", "bl", "ah", "ch", "dh", "bh" }; + return names[register_index & 7]; } const char* register_name(RegisterIndex16 register_index) { - switch (register_index) { - case RegisterAX: - return "ax"; - case RegisterBX: - return "bx"; - case RegisterCX: - return "cx"; - case RegisterDX: - return "dx"; - case RegisterBP: - return "bp"; - case RegisterSP: - return "sp"; - case RegisterSI: - return "si"; - case RegisterDI: - return "di"; - } - ASSERT_NOT_REACHED(); - return nullptr; + static constexpr const char* names[] = { "ax", "cx", "dx", "bx", "sp", "bp", "si", "di" }; + return names[register_index & 7]; } const char* register_name(RegisterIndex32 register_index) { - switch (register_index) { - case RegisterEAX: - return "eax"; - case RegisterEBX: - return "ebx"; - case RegisterECX: - return "ecx"; - case RegisterEDX: - return "edx"; - case RegisterEBP: - return "ebp"; - case RegisterESP: - return "esp"; - case RegisterESI: - return "esi"; - case RegisterEDI: - return "edi"; - } - ASSERT_NOT_REACHED(); - return nullptr; + static constexpr const char* names[] = { "eax", "ecx", "edx", "ebx", "esp", "ebp", "esi", "edi" }; + return names[register_index & 7]; } const char* register_name(MMXRegisterIndex register_index) { - switch (register_index) { - case RegisterMM0: - return "mm0"; - case RegisterMM1: - return "mm1"; - case RegisterMM2: - return "mm2"; - case RegisterMM3: - return "mm3"; - case RegisterMM4: - return "mm4"; - case RegisterMM5: - return "mm5"; - case RegisterMM6: - return "mm6"; - case RegisterMM7: - return "mm7"; - } - ASSERT_NOT_REACHED(); - return nullptr; + static constexpr const char* names[] = { "mm0", "mm1", "mm2", "mm3", "mm4", "mm5", "mm6", "mm7" }; + return names[register_index & 7]; } void MemoryOrRegisterReference::decode(InstructionStream& stream, bool a32) |