From 867d345fdca007b6fcf696c6863939578267f5e5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 23 Aug 2016 10:50:06 -0400 Subject: [PATCH] disassembler: Deduplicate SignStr Also just makes it return a character, rather than a pointer to a string. --- src/common/string_util.h | 5 +++++ src/frontend/disassembler/disassembler_arm.cpp | 11 +++-------- src/frontend/disassembler/disassembler_thumb.cpp | 9 ++------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/common/string_util.h b/src/common/string_util.h index b7595d75..08392b66 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -21,5 +21,10 @@ std::string StringFromFormat( #endif ; +template +constexpr char SignToChar(T value) { + return value >= 0 ? '+' : '-'; +} + } // namespace Common } // namespace Dynarmic diff --git a/src/frontend/disassembler/disassembler_arm.cpp b/src/frontend/disassembler/disassembler_arm.cpp index 1c9a0320..a2ddb1bb 100644 --- a/src/frontend/disassembler/disassembler_arm.cpp +++ b/src/frontend/disassembler/disassembler_arm.cpp @@ -18,11 +18,6 @@ namespace Arm { class DisassemblerVisitor { public: - template - const char* SignStr(T value) { - return value >= 0 ? "+" : "-"; - } - u32 rotr(u32 x, int shift) { shift &= 31; if (!shift) return x; @@ -105,15 +100,15 @@ public: // Branch instructions std::string arm_B(Cond cond, Imm24 imm24) { s32 offset = Common::SignExtend<26, s32>(imm24 << 2) + 8; - return Common::StringFromFormat("b%s %s#%i", CondToString(cond), SignStr(offset), abs(offset)); + return Common::StringFromFormat("b%s %c#%i", CondToString(cond), Common::SignToChar(offset), abs(offset)); } std::string arm_BL(Cond cond, Imm24 imm24) { s32 offset = Common::SignExtend<26, s32>(imm24 << 2) + 8; - return Common::StringFromFormat("bl%s %s#%i", CondToString(cond), SignStr(offset), abs(offset)); + return Common::StringFromFormat("bl%s %c#%i", CondToString(cond), Common::SignToChar(offset), abs(offset)); } std::string arm_BLX_imm(bool H, Imm24 imm24) { s32 offset = Common::SignExtend<26, s32>(imm24 << 2) + 8 + (H ? 2 : 0); - return Common::StringFromFormat("blx %s#%i", SignStr(offset), abs(offset)); + return Common::StringFromFormat("blx %c#%i", Common::SignToChar(offset), abs(offset)); } std::string arm_BLX_reg(Cond cond, Reg m) { return Common::StringFromFormat("blx%s %s", CondToString(cond), RegToString(m)); diff --git a/src/frontend/disassembler/disassembler_thumb.cpp b/src/frontend/disassembler/disassembler_thumb.cpp index 1a3fd998..f7b1c05b 100644 --- a/src/frontend/disassembler/disassembler_thumb.cpp +++ b/src/frontend/disassembler/disassembler_thumb.cpp @@ -17,11 +17,6 @@ namespace Arm { class DisassemblerVisitor { public: - template - const char* SignStr(T value) { - return value >= 0 ? "+" : "-"; - } - std::string thumb16_LSL_imm(Imm5 imm5, Reg m, Reg d) { return Common::StringFromFormat("lsls %s, %s, #%u", RegToString(d), RegToString(m), imm5); } @@ -308,12 +303,12 @@ public: std::string thumb16_B_t1(Cond cond, Imm8 imm8) { s32 imm32 = Common::SignExtend<9, s32>(imm8 << 1) + 4; - return Common::StringFromFormat("b%s %s#%u", CondToString(cond), SignStr(imm32), abs(imm32)); + return Common::StringFromFormat("b%s %c#%u", CondToString(cond), Common::SignToChar(imm32), abs(imm32)); } std::string thumb16_B_t2(Imm11 imm11) { s32 imm32 = Common::SignExtend<12, s32>(imm11 << 1) + 4; - return Common::StringFromFormat("b %s#%u", SignStr(imm32), abs(imm32)); + return Common::StringFromFormat("b %c#%u", Common::SignToChar(imm32), abs(imm32)); } };