disassembler: Deduplicate SignStr
Also just makes it return a character, rather than a pointer to a string.
This commit is contained in:
parent
8bed891011
commit
867d345fdc
3 changed files with 10 additions and 15 deletions
|
@ -21,5 +21,10 @@ std::string StringFromFormat(
|
||||||
#endif
|
#endif
|
||||||
;
|
;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr char SignToChar(T value) {
|
||||||
|
return value >= 0 ? '+' : '-';
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
} // namespace Dynarmic
|
} // namespace Dynarmic
|
||||||
|
|
|
@ -18,11 +18,6 @@ namespace Arm {
|
||||||
|
|
||||||
class DisassemblerVisitor {
|
class DisassemblerVisitor {
|
||||||
public:
|
public:
|
||||||
template<typename T>
|
|
||||||
const char* SignStr(T value) {
|
|
||||||
return value >= 0 ? "+" : "-";
|
|
||||||
}
|
|
||||||
|
|
||||||
u32 rotr(u32 x, int shift) {
|
u32 rotr(u32 x, int shift) {
|
||||||
shift &= 31;
|
shift &= 31;
|
||||||
if (!shift) return x;
|
if (!shift) return x;
|
||||||
|
@ -105,15 +100,15 @@ public:
|
||||||
// Branch instructions
|
// Branch instructions
|
||||||
std::string arm_B(Cond cond, Imm24 imm24) {
|
std::string arm_B(Cond cond, Imm24 imm24) {
|
||||||
s32 offset = Common::SignExtend<26, s32>(imm24 << 2) + 8;
|
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) {
|
std::string arm_BL(Cond cond, Imm24 imm24) {
|
||||||
s32 offset = Common::SignExtend<26, s32>(imm24 << 2) + 8;
|
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) {
|
std::string arm_BLX_imm(bool H, Imm24 imm24) {
|
||||||
s32 offset = Common::SignExtend<26, s32>(imm24 << 2) + 8 + (H ? 2 : 0);
|
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) {
|
std::string arm_BLX_reg(Cond cond, Reg m) {
|
||||||
return Common::StringFromFormat("blx%s %s", CondToString(cond), RegToString(m));
|
return Common::StringFromFormat("blx%s %s", CondToString(cond), RegToString(m));
|
||||||
|
|
|
@ -17,11 +17,6 @@ namespace Arm {
|
||||||
|
|
||||||
class DisassemblerVisitor {
|
class DisassemblerVisitor {
|
||||||
public:
|
public:
|
||||||
template<typename T>
|
|
||||||
const char* SignStr(T value) {
|
|
||||||
return value >= 0 ? "+" : "-";
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string thumb16_LSL_imm(Imm5 imm5, Reg m, Reg d) {
|
std::string thumb16_LSL_imm(Imm5 imm5, Reg m, Reg d) {
|
||||||
return Common::StringFromFormat("lsls %s, %s, #%u", RegToString(d), RegToString(m), imm5);
|
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) {
|
std::string thumb16_B_t1(Cond cond, Imm8 imm8) {
|
||||||
s32 imm32 = Common::SignExtend<9, s32>(imm8 << 1) + 4;
|
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) {
|
std::string thumb16_B_t2(Imm11 imm11) {
|
||||||
s32 imm32 = Common::SignExtend<12, s32>(imm11 << 1) + 4;
|
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));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue