Merge pull request #8177 from lioncash/fmt

Common: Use fmt where applicable
This commit is contained in:
Anthony 2019-06-14 12:22:16 -07:00 committed by GitHub
commit 9cf6ba13df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 289 additions and 263 deletions

View File

@ -10,10 +10,11 @@
#include <sys/auxv.h> #include <sys/auxv.h>
#include <unistd.h> #include <unistd.h>
#include <fmt/format.h>
#include "Common/CPUDetect.h" #include "Common/CPUDetect.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/StringUtil.h"
const char procfile[] = "/proc/cpuinfo"; const char procfile[] = "/proc/cpuinfo";
@ -77,9 +78,9 @@ std::string CPUInfo::Summarize()
{ {
std::string sum; std::string sum;
if (num_cores == 1) if (num_cores == 1)
sum = StringFromFormat("%s, %i core", cpu_string, num_cores); sum = fmt::format("{}, 1 core", cpu_string);
else else
sum = StringFromFormat("%s, %i cores", cpu_string, num_cores); sum = fmt::format("{}, {} cores", cpu_string, num_cores);
if (bAES) if (bAES)
sum += ", AES"; sum += ", AES";

View File

@ -9,6 +9,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <fmt/format.h>
#include "Common/CDUtils.h" #include "Common/CDUtils.h"
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
@ -134,20 +136,23 @@ std::vector<std::string> GetCDDevices()
} }
#else #else
// checklist: /dev/cdrom, /dev/dvd /dev/hd?, /dev/scd? /dev/sr? // checklist: /dev/cdrom, /dev/dvd /dev/hd?, /dev/scd? /dev/sr?
static struct struct CheckListEntry
{ {
const char* format; const char* format;
unsigned int num_min; unsigned int num_min;
unsigned int num_max; unsigned int num_max;
} checklist[] = { };
constexpr CheckListEntry checklist[] = {
#ifdef __linux__ #ifdef __linux__
{"/dev/cdrom", 0, 0}, {"/dev/dvd", 0, 0}, {"/dev/hd%c", 'a', 'z'}, {"/dev/cdrom", 0, 0}, {"/dev/dvd", 0, 0}, {"/dev/hd{}", 'a', 'z'},
{"/dev/scd%d", 0, 27}, {"/dev/sr%d", 0, 27}, {"/dev/scd{}", 0, 27}, {"/dev/sr{}", 0, 27},
#else #else
{"/dev/acd%d", 0, 27}, {"/dev/acd{}", 0, 27},
{"/dev/cd%d", 0, 27}, {"/dev/cd{}", 0, 27},
#endif #endif
{nullptr, 0, 0}}; {nullptr, 0, 0},
};
// Returns true if a device is a block or char device and not a symbolic link // Returns true if a device is a block or char device and not a symbolic link
static bool IsDevice(const std::string& source_name) static bool IsDevice(const std::string& source_name)
@ -189,7 +194,7 @@ std::vector<std::string> GetCDDevices()
{ {
for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j) for (unsigned int j = checklist[i].num_min; j <= checklist[i].num_max; ++j)
{ {
std::string drive = StringFromFormat(checklist[i].format, j); std::string drive = fmt::format(checklist[i].format, j);
if (IsCDROM(drive)) if (IsCDROM(drive))
{ {
drives.push_back(std::move(drive)); drives.push_back(std::move(drive));

View File

@ -8,6 +8,8 @@
#include <vector> #include <vector>
#include <winternl.h> #include <winternl.h>
#include <fmt/format.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/LdrWatcher.h" #include "Common/LdrWatcher.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -213,7 +215,8 @@ void CompatPatchesInstall(LdrWatcher* watcher)
auto patcher = ImportPatcher(event.base_address); auto patcher = ImportPatcher(event.base_address);
patcher.PatchIAT("kernel32.dll", "HeapCreate", HeapCreateLow4GB); patcher.PatchIAT("kernel32.dll", "HeapCreate", HeapCreateLow4GB);
}}); }});
watcher->Install({{L"ucrtbase.dll"}, [](const LdrDllLoadEvent& event) { watcher->Install(
{{L"ucrtbase.dll"}, [](const LdrDllLoadEvent& event) {
// ucrtbase implements caching between fseek/fread, old versions have a bug // ucrtbase implements caching between fseek/fread, old versions have a bug
// such that some reads return incorrect data. This causes noticable bugs // such that some reads return incorrect data. This causes noticable bugs
// in dolphin since we use these APIs for reading game images. // in dolphin since we use these APIs for reading game images.
@ -237,16 +240,15 @@ void CompatPatchesInstall(LdrWatcher* watcher)
return; return;
} }
// If we reach here, the version is buggy (afaik) and patching failed // If we reach here, the version is buggy (afaik) and patching failed
auto msg = StringFromFormat( const auto msg =
"You are running %S version %d.%d.%d.%d.\n" fmt::format("You are running {} version {}.{}.{}.{}.\n"
"An important fix affecting Dolphin was introduced in build %d.\n" "An important fix affecting Dolphin was introduced in build {}.\n"
"You can use Dolphin, but there will be known bugs.\n" "You can use Dolphin, but there will be known bugs.\n"
"Please update this file by installing the latest Universal C Runtime.\n", "Please update this file by installing the latest Universal C Runtime.\n",
event.name.c_str(), version.major, version.minor, version.build, UTF16ToUTF8(event.name), version.major, version.minor, version.build,
version.qfe, fixed_build); version.qfe, fixed_build);
// Use MessageBox for maximal user annoyance // Use MessageBox for maximal user annoyance
MessageBoxA(nullptr, msg.c_str(), "WARNING: BUGGY UCRT VERSION", MessageBoxA(nullptr, msg.c_str(), "WARNING: BUGGY UCRT VERSION", MB_ICONEXCLAMATION);
MB_ICONEXCLAMATION);
}}); }});
} }

View File

@ -3,9 +3,12 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Common/DynamicLibrary.h" #include "Common/DynamicLibrary.h"
#include <cstring> #include <cstring>
#include <fmt/format.h>
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/StringUtil.h"
#ifdef _WIN32 #ifdef _WIN32
#include <Windows.h> #include <Windows.h>
@ -42,27 +45,27 @@ std::string DynamicLibrary::GetVersionedFilename(const char* libname, int major,
{ {
#if defined(_WIN32) #if defined(_WIN32)
if (major >= 0 && minor >= 0) if (major >= 0 && minor >= 0)
return StringFromFormat("%s-%d-%d.dll", libname, major, minor); return fmt::format("{}-{}-{}.dll", libname, major, minor);
else if (major >= 0) else if (major >= 0)
return StringFromFormat("%s-%d.dll", libname, major); return fmt::format("{}-{}.dll", libname, major);
else else
return StringFromFormat("%s.dll", libname); return fmt::format("{}.dll", libname);
#elif defined(__APPLE__) #elif defined(__APPLE__)
const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : ""; const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : "";
if (major >= 0 && minor >= 0) if (major >= 0 && minor >= 0)
return StringFromFormat("%s%s.%d.%d.dylib", prefix, libname, major, minor); return fmt::format("{}{}.{}.{}.dylib", prefix, libname, major, minor);
else if (major >= 0) else if (major >= 0)
return StringFromFormat("%s%s.%d.dylib", prefix, libname, major); return fmt::format("{}{}.{}.dylib", prefix, libname, major);
else else
return StringFromFormat("%s%s.dylib", prefix, libname); return fmt::format("{}{}.dylib", prefix, libname);
#else #else
const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : ""; const char* prefix = std::strncmp(libname, "lib", 3) ? "lib" : "";
if (major >= 0 && minor >= 0) if (major >= 0 && minor >= 0)
return StringFromFormat("%s%s.so.%d.%d", prefix, libname, major, minor); return fmt::format("{}{}.so.{}.{}", prefix, libname, major, minor);
else if (major >= 0) else if (major >= 0)
return StringFromFormat("%s%s.so.%d", prefix, libname, major); return fmt::format("{}{}.so.{}", prefix, libname, major);
else else
return StringFromFormat("%s%s.so", prefix, libname); return fmt::format("{}{}.so", prefix, libname);
#endif #endif
} }

View File

@ -32,10 +32,13 @@
// Modified for use with Dolphin // Modified for use with Dolphin
#include "Common/GekkoDisassembler.h"
#include <string> #include <string>
#include <fmt/format.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/GekkoDisassembler.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
namespace Common namespace Common
@ -125,6 +128,45 @@ unsigned char GekkoDisassembler::m_flags = PPCF_ILLEGAL;
unsigned short GekkoDisassembler::m_sreg = 0; unsigned short GekkoDisassembler::m_sreg = 0;
u32 GekkoDisassembler::m_displacement = 0; u32 GekkoDisassembler::m_displacement = 0;
static u32 HelperRotateMask(int r, int mb, int me)
{
// first make 001111111111111 part
unsigned int begin = 0xFFFFFFFF >> mb;
// then make 000000000001111 part, which is used to flip the bits of the first one
unsigned int end = me < 31 ? (0xFFFFFFFF >> (me + 1)) : 0;
// do the bitflip
unsigned int mask = begin ^ end;
// and invert if backwards
if (me < mb)
mask = ~mask;
// rotate the mask so it can be applied to source reg
// return _rotl(mask, 32 - r);
return (mask << (32 - r)) | (mask >> r);
}
static std::string ldst_offs(u32 val)
{
if (val == 0)
{
return "0";
}
if (val & 0x8000)
{
return fmt::format("-0x{:.4X}", ((~val) & 0xffff) + 1);
}
return fmt::format("0x{:.4X}", val);
}
static int SEX12(u32 x)
{
if ((x & 0x800) != 0)
return static_cast<int>(x | 0xFFFFF000);
return static_cast<int>(x);
}
static std::string spr_name(int i) static std::string spr_name(int i)
{ {
switch (i) switch (i)
@ -275,7 +317,7 @@ static std::string spr_name(int i)
return "THRM3"; return "THRM3";
} }
return StringFromFormat("%d", i); return std::to_string(i);
} }
static u32 swapda(u32 w) static u32 swapda(u32 w)
@ -298,7 +340,7 @@ void GekkoDisassembler::ill(u32 in)
else else
{ {
m_opcode = "(ill)"; m_opcode = "(ill)";
m_operands = StringFromFormat("%08x", in); m_operands = fmt::format("{:08x}", in);
} }
m_flags |= PPCF_ILLEGAL; m_flags |= PPCF_ILLEGAL;
@ -330,34 +372,31 @@ std::string GekkoDisassembler::imm(u32 in, int uimm, int type, bool hex)
switch (type) switch (type)
{ {
case 0: case 0:
return StringFromFormat("%s, %s, %d", regnames[(int)PPCGETD(in)], regnames[(int)PPCGETA(in)], return fmt::format("{}, {}, {}", regnames[PPCGETD(in)], regnames[PPCGETA(in)], i);
i);
case 1: case 1:
if (hex) if (hex)
return StringFromFormat("%s, %s, 0x%.4X", regnames[(int)PPCGETA(in)], return fmt::format("{}, {}, 0x{:.4X}", regnames[PPCGETA(in)], regnames[PPCGETD(in)], i);
regnames[(int)PPCGETD(in)], i);
else else
return StringFromFormat("%s, %s, %d", regnames[(int)PPCGETA(in)], regnames[(int)PPCGETD(in)], return fmt::format("{}, {}, {}", regnames[PPCGETA(in)], regnames[PPCGETD(in)], i);
i);
case 2: case 2:
return StringFromFormat("%s, %d", regnames[(int)PPCGETA(in)], i); return fmt::format("{}, {}", regnames[PPCGETA(in)], i);
case 3: case 3:
if (hex) if (hex)
return StringFromFormat("%s, 0x%.4X", regnames[(int)PPCGETD(in)], i); return fmt::format("{}, 0x{:.4X}", regnames[PPCGETD(in)], i);
else else
return StringFromFormat("%s, %d", regnames[(int)PPCGETD(in)], i); return fmt::format("{}, {}", regnames[PPCGETD(in)], i);
default: default:
return StringFromFormat("%s", "imm(): Wrong type"); return "imm(): Wrong type";
} }
} }
std::string GekkoDisassembler::ra_rb(u32 in) std::string GekkoDisassembler::ra_rb(u32 in)
{ {
return StringFromFormat("%s, %s", regnames[(int)PPCGETA(in)], regnames[(int)PPCGETB(in)]); return fmt::format("{}, {}", regnames[PPCGETA(in)], regnames[PPCGETB(in)]);
} }
std::string GekkoDisassembler::rd_ra_rb(u32 in, int mask) std::string GekkoDisassembler::rd_ra_rb(u32 in, int mask)
@ -367,11 +406,11 @@ std::string GekkoDisassembler::rd_ra_rb(u32 in, int mask)
if (mask) if (mask)
{ {
if (mask & 4) if (mask & 4)
result += StringFromFormat("%s, ", regnames[(int)PPCGETD(in)]); result += fmt::format("{}, ", regnames[PPCGETD(in)]);
if (mask & 2) if (mask & 2)
result += StringFromFormat("%s, ", regnames[(int)PPCGETA(in)]); result += fmt::format("{}, ", regnames[PPCGETA(in)]);
if (mask & 1) if (mask & 1)
result += StringFromFormat("%s, ", regnames[(int)PPCGETB(in)]); result += fmt::format("{}, ", regnames[PPCGETB(in)]);
size_t pos = result.rfind(", "); size_t pos = result.rfind(", ");
if (pos != std::string::npos) if (pos != std::string::npos)
@ -390,11 +429,11 @@ std::string GekkoDisassembler::fd_ra_rb(u32 in, int mask)
if (mask) if (mask)
{ {
if (mask & 4) if (mask & 4)
result += StringFromFormat("f%d,", (int)PPCGETD(in)); result += fmt::format("f{},", PPCGETD(in));
if (mask & 2) if (mask & 2)
result += StringFromFormat("%s,", regnames[(int)PPCGETA(in)]); result += fmt::format("{},", regnames[PPCGETA(in)]);
if (mask & 1) if (mask & 1)
result += StringFromFormat("%s,", regnames[(int)PPCGETB(in)]); result += fmt::format("{},", regnames[PPCGETB(in)]);
// Drop the trailing comma // Drop the trailing comma
result.pop_back(); result.pop_back();
@ -410,12 +449,12 @@ void GekkoDisassembler::trapi(u32 in, unsigned char dmode)
m_flags |= dmode; m_flags |= dmode;
if (cnd != nullptr) if (cnd != nullptr)
{ {
m_opcode = StringFromFormat("t%c%s", dmode ? 'd' : 'w', cnd); m_opcode = fmt::format("t{}{}", dmode ? 'd' : 'w', cnd);
} }
else else
{ {
m_opcode = StringFromFormat("t%ci", dmode ? 'd' : 'w'); m_opcode = fmt::format("t{}i", dmode ? 'd' : 'w');
m_operands = StringFromFormat("%d, ", PPCGETD(in)); m_operands = fmt::format("{}, ", PPCGETD(in));
} }
m_operands += imm(in, 0, 2, false); m_operands += imm(in, 0, 2, false);
} }
@ -429,12 +468,12 @@ void GekkoDisassembler::cmpi(u32 in, int uimm)
if (i != 0) if (i != 0)
m_flags |= PPCF_64; m_flags |= PPCF_64;
m_opcode = StringFromFormat("%si", cmpname[uimm * 2 + i]); m_opcode = fmt::format("{}i", cmpname[uimm * 2 + i]);
i = (int)PPCGETCRD(in); i = (int)PPCGETCRD(in);
if (i != 0) if (i != 0)
{ {
m_operands += StringFromFormat("cr%c, ", '0' + i); m_operands += fmt::format("cr{}, ", '0' + i);
} }
m_operands += imm(in, uimm, 2, false); m_operands += imm(in, uimm, 2, false);
@ -449,7 +488,8 @@ void GekkoDisassembler::addi(u32 in, const std::string& ext)
{ {
if ((in & 0x08000000) && !PPCGETA(in)) if ((in & 0x08000000) && !PPCGETA(in))
{ {
m_opcode = StringFromFormat("l%s", ext.c_str()); // li, lis // li, lis
m_opcode = fmt::format("l{}", ext);
if (ext == "i") if (ext == "i")
m_operands = imm(in, 0, 3, false); m_operands = imm(in, 0, 3, false);
@ -458,7 +498,7 @@ void GekkoDisassembler::addi(u32 in, const std::string& ext)
} }
else else
{ {
m_opcode = StringFromFormat("%s%s", (in & 0x8000) ? "sub" : "add", ext.c_str()); m_opcode = fmt::format("{}{}", (in & 0x8000) ? "sub" : "add", ext);
if (in & 0x8000) if (in & 0x8000)
in = (in ^ 0xffff) + 1; in = (in ^ 0xffff) + 1;
@ -487,33 +527,32 @@ size_t GekkoDisassembler::branch(u32 in, const char* bname, int aform, int bdisp
// branch always // branch always
if (PPCGETIDX(in) != 16) if (PPCGETIDX(in) != 16)
{ {
m_opcode = StringFromFormat("b%s%s", bname, ext); m_opcode = fmt::format("b{}{}", bname, ext);
} }
else else
{ {
m_opcode = StringFromFormat("bc%s", ext); m_opcode = fmt::format("bc{}", ext);
m_operands = StringFromFormat("%d, %d", bo, bi); m_operands = fmt::format("{}, {}", bo, bi);
} }
} }
else // Branch conditional else // Branch conditional
{ {
m_opcode = m_opcode = fmt::format("b{}{}{}{}", b_condition[((bo & 8) >> 1) + (bi & 3)], bname, ext, y);
StringFromFormat("b%s%s%s%c", b_condition[((bo & 8) >> 1) + (bi & 3)], bname, ext, y);
if (bi >= 4) if (bi >= 4)
{ {
m_operands = StringFromFormat("cr%d", bi >> 2); m_operands = fmt::format("cr{}", bi >> 2);
} }
} }
} }
else else
{ {
// CTR is decremented and checked // CTR is decremented and checked
m_opcode = StringFromFormat("bd%s%s%s%c", b_decr[bo >> 1], bname, ext, y); m_opcode = fmt::format("bd{}{}{}{}", b_decr[bo >> 1], bname, ext, y);
if ((bo & 16) == 0) if ((bo & 16) == 0)
{ {
m_operands = StringFromFormat("%d", bi); m_operands = std::to_string(bi);
} }
} }
@ -530,9 +569,9 @@ void GekkoDisassembler::bc(u32 in)
branch(in, "", (in & 2) ? 1 : 0, d); branch(in, "", (in & 2) ? 1 : 0, d);
if (in & 2) // AA ? if (in & 2) // AA ?
m_operands = StringFromFormat("%s ->0x%.8X", m_operands.c_str(), d); m_operands = fmt::format("{} ->0x{:.8X}", m_operands, d);
else else
m_operands = StringFromFormat("%s ->0x%.8X", m_operands.c_str(), *m_iaddr + d); m_operands = fmt::format("{} ->0x{:.8X}", m_operands, *m_iaddr + d);
m_type = PPCINSTR_BRANCH; m_type = PPCINSTR_BRANCH;
m_displacement = d; m_displacement = d;
@ -545,12 +584,12 @@ void GekkoDisassembler::bli(u32 in)
if (d & 0x02000000) if (d & 0x02000000)
d |= 0xfc000000; d |= 0xfc000000;
m_opcode = StringFromFormat("b%s", b_ext[in & 3]); m_opcode = fmt::format("b{}", b_ext[in & 3]);
if (in & 2) // AA ? if (in & 2) // AA ?
m_operands = StringFromFormat("->0x%.8X", d); m_operands = fmt::format("->0x{:.8X}", d);
else else
m_operands = StringFromFormat("->0x%.8X", *m_iaddr + d); m_operands = fmt::format("->0x{:.8X}", *m_iaddr + d);
m_type = PPCINSTR_BRANCH; m_type = PPCINSTR_BRANCH;
m_displacement = d; m_displacement = d;
@ -560,8 +599,8 @@ void GekkoDisassembler::mcrf(u32 in, char c)
{ {
if ((in & 0x0063f801) == 0) if ((in & 0x0063f801) == 0)
{ {
m_opcode = StringFromFormat("mcrf%c", c); m_opcode = fmt::format("mcrf{}", c);
m_operands = StringFromFormat("cr%d, cr%d", (int)PPCGETCRD(in), (int)PPCGETCRA(in)); m_operands = fmt::format("cr{}, cr{}", PPCGETCRD(in), PPCGETCRA(in));
} }
else else
{ {
@ -577,11 +616,11 @@ void GekkoDisassembler::crop(u32 in, const char* n1, const char* n2)
if ((in & 1) == 0) if ((in & 1) == 0)
{ {
m_opcode = StringFromFormat("cr%s", (cra == crb && n2) ? n2 : n1); m_opcode = fmt::format("cr{}", (cra == crb && n2) ? n2 : n1);
if (cra == crb && n2) if (cra == crb && n2)
m_operands = StringFromFormat("%d, %d", crd, cra); m_operands = fmt::format("{}, {}", crd, cra);
else else
m_operands = StringFromFormat("%d, %d, %d", crd, cra, crb); m_operands = fmt::format("{}, {}, {}", crd, cra, crb);
} }
else else
{ {
@ -610,8 +649,8 @@ void GekkoDisassembler::rlw(u32 in, const char* name, int i)
int mb = (int)PPCGETC(in); int mb = (int)PPCGETC(in);
int me = (int)PPCGETM(in); int me = (int)PPCGETM(in);
m_opcode = StringFromFormat("rlw%s%c", name, in & 1 ? '.' : '\0'); m_opcode = fmt::format("rlw{}{}", name, (in & 1) ? '.' : '\0');
m_operands = StringFromFormat("%s, %s, %s%d, %d, %d (%08x)", regnames[a], regnames[s], regsel[i], m_operands = fmt::format("{}, {}, {}{}, {}, {} ({:08x})", regnames[a], regnames[s], regsel[i],
bsh, mb, me, HelperRotateMask(bsh, mb, me)); bsh, mb, me, HelperRotateMask(bsh, mb, me));
} }
@ -629,8 +668,8 @@ void GekkoDisassembler::rld(u32 in, const char* name, int i)
int m = (int)(in & 0x7e0) >> 5; int m = (int)(in & 0x7e0) >> 5;
m_flags |= PPCF_64; m_flags |= PPCF_64;
m_opcode = StringFromFormat("rld%s%c", name, in & 1 ? '.' : '\0'); m_opcode = fmt::format("rld{}{}", name, (in & 1) ? '.' : '\0');
m_operands = StringFromFormat("%s, %s, %s%d, %d", regnames[a], regnames[s], regsel[i], bsh, m); m_operands = fmt::format("{}, {}, {}{}, {}", regnames[a], regnames[s], regsel[i], bsh, m);
} }
void GekkoDisassembler::cmp(u32 in) void GekkoDisassembler::cmp(u32 in)
@ -646,7 +685,7 @@ void GekkoDisassembler::cmp(u32 in)
i = (int)PPCGETCRD(in); i = (int)PPCGETCRD(in);
if (i != 0) if (i != 0)
m_operands += StringFromFormat("cr%c,", '0' + i); m_operands += fmt::format("cr{},", static_cast<char>('0' + i));
m_operands += ra_rb(in); m_operands += ra_rb(in);
} }
@ -664,7 +703,7 @@ void GekkoDisassembler::trap(u32 in, unsigned char dmode)
if (cnd != nullptr) if (cnd != nullptr)
{ {
m_flags |= dmode; m_flags |= dmode;
m_opcode = StringFromFormat("t%c%s", dmode ? 'd' : 'w', cnd); m_opcode = fmt::format("t{}{}", dmode ? 'd' : 'w', cnd);
m_operands = ra_rb(in); m_operands = ra_rb(in);
} }
else else
@ -705,8 +744,8 @@ void GekkoDisassembler::dab(u32 in, const char* name, int mask, int smode, int c
if (smode) if (smode)
in = swapda(in); in = swapda(in);
m_opcode = StringFromFormat("%s%s%s", name, oesel[chkoe && (in & PPCOE)], m_opcode =
rcsel[(chkrc < 0) && (in & 1)]); fmt::format("{}{}{}", name, oesel[chkoe && (in & PPCOE)], rcsel[(chkrc < 0) && (in & 1)]);
m_operands = rd_ra_rb(in, mask); m_operands = rd_ra_rb(in, mask);
} }
} }
@ -727,11 +766,10 @@ void GekkoDisassembler::rrn(u32 in, const char* name, int smode, int chkoe, int
if (smode) if (smode)
in = swapda(in); in = swapda(in);
m_opcode = StringFromFormat("%s%s%s", name, oesel[chkoe && (in & PPCOE)], m_opcode =
rcsel[(chkrc < 0) && (in & 1)]); fmt::format("{}{}{}", name, oesel[chkoe && (in & PPCOE)], rcsel[(chkrc < 0) && (in & 1)]);
m_operands = rd_ra_rb(in, 6); m_operands = rd_ra_rb(in, 6);
m_operands += StringFromFormat(",%d", (int)PPCGETB(in)); m_operands += fmt::format(",{}", PPCGETB(in));
} }
} }
@ -746,10 +784,10 @@ void GekkoDisassembler::mtcr(u32 in)
} }
else else
{ {
m_opcode = StringFromFormat("mtcr%c", crm == 0xff ? '\0' : 'f'); m_opcode = fmt::format("mtcr{}", crm == 0xff ? '\0' : 'f');
if (crm != 0xff) if (crm != 0xff)
m_operands += StringFromFormat("0x%02x,", crm); m_operands += fmt::format("0x{:02x},", crm);
m_operands += regnames[s]; m_operands += regnames[s];
} }
@ -767,12 +805,12 @@ void GekkoDisassembler::msr(u32 in, int smode)
else else
{ {
m_flags |= PPCF_SUPER; m_flags |= PPCF_SUPER;
m_opcode = StringFromFormat("m%csr", smode ? 't' : 'f'); m_opcode = fmt::format("m{}sr", smode ? 't' : 'f');
if (smode) if (smode)
m_operands = StringFromFormat("%d, %s", sr, regnames[s]); m_operands = fmt::format("{}, {}", sr, regnames[s]);
else else
m_operands = StringFromFormat("%s, %d", regnames[s], sr); m_operands = fmt::format("{}, {}", regnames[s], sr);
} }
} }
@ -812,14 +850,14 @@ void GekkoDisassembler::mspr(u32 in, int smode)
break; break;
} }
m_opcode = StringFromFormat("m%c%s", smode ? 't' : 'f', x); m_opcode = fmt::format("m{}{}", smode ? 't' : 'f', x);
if (fmt) if (fmt)
{ {
if (smode) if (smode)
m_operands = StringFromFormat("%s, %s", spr_name(spr).c_str(), regnames[d]); m_operands = fmt::format("{}, {}", spr_name(spr), regnames[d]);
else else
m_operands = StringFromFormat("%s, %s", regnames[d], spr_name(spr).c_str()); m_operands = fmt::format("{}, {}", regnames[d], spr_name(spr));
} }
else else
{ {
@ -855,11 +893,11 @@ void GekkoDisassembler::mtb(u32 in)
default: default:
x = '\0'; x = '\0';
m_flags |= PPCF_SUPER; m_flags |= PPCF_SUPER;
m_operands += StringFromFormat(",%d", tbr); m_operands += fmt::format(",{}", tbr);
break; break;
} }
m_opcode = StringFromFormat("mftb%c", x); m_opcode = fmt::format("mftb{}", x);
} }
} }
@ -870,8 +908,8 @@ void GekkoDisassembler::sradi(u32 in)
int bsh = (int)(((in & 2) << 4) + PPCGETB(in)); int bsh = (int)(((in & 2) << 4) + PPCGETB(in));
m_flags |= PPCF_64; m_flags |= PPCF_64;
m_opcode = StringFromFormat("sradi%c", in & 1 ? '.' : '\0'); m_opcode = fmt::format("sradi{}", (in & 1) ? '.' : '\0');
m_operands = StringFromFormat("%s, %s, %d", regnames[a], regnames[s], bsh); m_operands = fmt::format("{}, {}, {}", regnames[a], regnames[s], bsh);
} }
void GekkoDisassembler::ldst(u32 in, const char* name, char reg, unsigned char dmode) void GekkoDisassembler::ldst(u32 in, const char* name, char reg, unsigned char dmode)
@ -890,11 +928,11 @@ void GekkoDisassembler::ldst(u32 in, const char* name, char reg, unsigned char d
if (reg == 'r') if (reg == 'r')
{ {
m_operands = StringFromFormat("%s, %s (%s)", regnames[s], ldst_offs(d).c_str(), regnames[a]); m_operands = fmt::format("{}, {} ({})", regnames[s], ldst_offs(d), regnames[a]);
} }
else else
{ {
m_operands = StringFromFormat("%c%d, %s (%s)", reg, s, ldst_offs(d).c_str(), regnames[a]); m_operands = fmt::format("{}{}, {} ({})", reg, s, ldst_offs(d), regnames[a]);
} }
} }
@ -904,21 +942,21 @@ void GekkoDisassembler::fdabc(u32 in, const char* name, int mask, unsigned char
int err = 0; int err = 0;
m_flags |= dmode; m_flags |= dmode;
m_opcode = StringFromFormat("f%s%s", name, rcsel[in & 1]); m_opcode = fmt::format("f{}{}", name, rcsel[in & 1]);
m_operands += StringFromFormat("f%d,", (int)PPCGETD(in)); m_operands += fmt::format("f{},", PPCGETD(in));
if (mask & 4) if (mask & 4)
m_operands += StringFromFormat("f%d,", (int)PPCGETA(in)); m_operands += fmt::format("f{},", PPCGETA(in));
else if ((mask & 8) == 0) else if ((mask & 8) == 0)
err |= (int)PPCGETA(in); err |= (int)PPCGETA(in);
if (mask & 2) if (mask & 2)
m_operands += StringFromFormat("f%d,", (int)PPCGETC(in)); m_operands += fmt::format("f{},", PPCGETC(in));
else if (PPCGETC(in) && (mask & 8) == 0) else if (PPCGETC(in) && (mask & 8) == 0)
err |= (int)PPCGETC(in); err |= (int)PPCGETC(in);
if (mask & 1) if (mask & 1)
m_operands += StringFromFormat("f%d,", (int)PPCGETB(in)); m_operands += fmt::format("f{},", PPCGETB(in));
else if (!(mask & 8)) else if (!(mask & 8))
err |= (int)PPCGETB(in); err |= (int)PPCGETB(in);
@ -931,8 +969,8 @@ void GekkoDisassembler::fdabc(u32 in, const char* name, int mask, unsigned char
void GekkoDisassembler::fmr(u32 in) void GekkoDisassembler::fmr(u32 in)
{ {
m_opcode = StringFromFormat("fmr%s", rcsel[in & 1]); m_opcode = fmt::format("fmr{}", rcsel[in & 1]);
m_operands = StringFromFormat("f%d, f%d", (int)PPCGETD(in), (int)PPCGETB(in)); m_operands = fmt::format("f{}, f{}", PPCGETD(in), PPCGETB(in));
} }
// Indexed float instruction: xxxx fD,rA,rB // Indexed float instruction: xxxx fD,rA,rB
@ -950,9 +988,8 @@ void GekkoDisassembler::fcmp(u32 in, char c)
} }
else else
{ {
m_opcode = StringFromFormat("fcmp%c", c); m_opcode = fmt::format("fcmp{}", c);
m_operands = m_operands = fmt::format("cr{},f{},f{}", PPCGETCRD(in), PPCGETA(in), PPCGETB(in));
StringFromFormat("cr%d,f%d,f%d", (int)PPCGETCRD(in), (int)PPCGETA(in), (int)PPCGETB(in));
} }
} }
@ -964,8 +1001,8 @@ void GekkoDisassembler::mtfsb(u32 in, int n)
} }
else else
{ {
m_opcode = StringFromFormat("mtfsb%d%s", n, rcsel[in & 1]); m_opcode = fmt::format("mtfsb{}{}", n, rcsel[in & 1]);
m_operands = StringFromFormat("%d", (int)PPCGETD(in)); m_operands = std::to_string(PPCGETD(in));
} }
} }
@ -1026,97 +1063,97 @@ void GekkoDisassembler::ps(u32 inst)
{ {
case 6: case 6:
m_opcode = inst & 0x40 ? "psq_lux" : "psq_lx"; m_opcode = inst & 0x40 ? "psq_lux" : "psq_lx";
m_operands = StringFromFormat("p%u, (r%u + r%u), %d, qr%d", FD, RA, RB, WX, IX); m_operands = fmt::format("p{}, (r{} + r{}), {}, qr{}", FD, RA, RB, WX, IX);
return; return;
case 7: case 7:
m_opcode = inst & 0x40 ? "psq_stux" : "psq_stx"; m_opcode = inst & 0x40 ? "psq_stux" : "psq_stx";
m_operands = StringFromFormat("p%u, r%u, r%u, %d, qr%d", FS, RA, RB, WX, IX); m_operands = fmt::format("p{}, r{}, r{}, {}, qr{}", FS, RA, RB, WX, IX);
return; return;
case 18: case 18:
m_opcode = "ps_div"; m_opcode = "ps_div";
m_operands = StringFromFormat("p%u, p%u/p%u", FD, FA, FB); m_operands = fmt::format("p{}, p{}/p{}", FD, FA, FB);
return; return;
case 20: case 20:
m_opcode = "ps_sub"; m_opcode = "ps_sub";
m_operands = StringFromFormat("p%u, p%u-p%u", FD, FA, FB); m_operands = fmt::format("p{}, p{}-p{}", FD, FA, FB);
return; return;
case 21: case 21:
m_opcode = "ps_add"; m_opcode = "ps_add";
m_operands = StringFromFormat("p%u, p%u+p%u", FD, FA, FB); m_operands = fmt::format("p{}, p{}+p{}", FD, FA, FB);
return; return;
case 23: case 23:
m_opcode = "ps_sel"; m_opcode = "ps_sel";
m_operands = StringFromFormat("p%u>=0?p%u:p%u", FD, FA, FC); m_operands = fmt::format("p{}>=0?p{}:p{}", FD, FA, FC);
return; return;
case 24: case 24:
m_opcode = "ps_res"; m_opcode = "ps_res";
m_operands = StringFromFormat("p%u, (1/p%u)", FD, FB); m_operands = fmt::format("p{}, (1/p{})", FD, FB);
return; return;
case 25: case 25:
m_opcode = "ps_mul"; m_opcode = "ps_mul";
m_operands = StringFromFormat("p%u, p%u*p%u", FD, FA, FC); m_operands = fmt::format("p{}, p{}*p{}", FD, FA, FC);
return; return;
case 26: // rsqrte case 26: // rsqrte
m_opcode = "ps_rsqrte"; m_opcode = "ps_rsqrte";
m_operands = StringFromFormat("p%u, p%u", FD, FB); m_operands = fmt::format("p{}, p{}", FD, FB);
return; return;
case 28: // msub case 28: // msub
m_opcode = "ps_msub"; m_opcode = "ps_msub";
m_operands = StringFromFormat("p%u, p%u*p%u-p%u", FD, FA, FC, FB); m_operands = fmt::format("p{}, p{}*p{}-p{}", FD, FA, FC, FB);
return; return;
case 29: // madd case 29: // madd
m_opcode = "ps_madd"; m_opcode = "ps_madd";
m_operands = StringFromFormat("p%u, p%u*p%u+p%u", FD, FA, FC, FB); m_operands = fmt::format("p{}, p{}*p{}+p{}", FD, FA, FC, FB);
return; return;
case 30: // nmsub case 30: // nmsub
m_opcode = "ps_nmsub"; m_opcode = "ps_nmsub";
m_operands = StringFromFormat("p%u, -(p%u*p%u-p%u)", FD, FA, FC, FB); m_operands = fmt::format("p{}, -(p{}*p{}-p{})", FD, FA, FC, FB);
return; return;
case 31: // nmadd case 31: // nmadd
m_opcode = "ps_nmadd"; m_opcode = "ps_nmadd";
m_operands = StringFromFormat("p%u, -(p%u*p%u+p%u)", FD, FA, FC, FB); m_operands = fmt::format("p{}, -(p{}*p{}+p{})", FD, FA, FC, FB);
return; return;
case 10: case 10:
m_opcode = "ps_sum0"; m_opcode = "ps_sum0";
m_operands = StringFromFormat("p%u, 0=p%u+p%u, 1=p%u", FD, FA, FB, FC); m_operands = fmt::format("p{}, 0=p{}+p{}, 1=p{}", FD, FA, FB, FC);
return; return;
case 11: case 11:
m_opcode = "ps_sum1"; m_opcode = "ps_sum1";
m_operands = StringFromFormat("p%u, 0=p%u, 1=p%u+p%u", FD, FC, FA, FB); m_operands = fmt::format("p{}, 0=p{}, 1=p{}+p{}", FD, FC, FA, FB);
return; return;
case 12: case 12:
m_opcode = "ps_muls0"; m_opcode = "ps_muls0";
m_operands = StringFromFormat("p%u, p%u*p%u[0]", FD, FA, FC); m_operands = fmt::format("p{}, p{}*p{}[0]", FD, FA, FC);
return; return;
case 13: case 13:
m_opcode = "ps_muls1"; m_opcode = "ps_muls1";
m_operands = StringFromFormat("p%u, p%u*p%u[1]", FD, FA, FC); m_operands = fmt::format("p{}, p{}*p{}[1]", FD, FA, FC);
return; return;
case 14: case 14:
m_opcode = "ps_madds0"; m_opcode = "ps_madds0";
m_operands = StringFromFormat("p%u, p%u*p%u[0]+p%u", FD, FA, FC, FB); m_operands = fmt::format("p{}, p{}*p{}[0]+p{}", FD, FA, FC, FB);
return; return;
case 15: case 15:
m_opcode = "ps_madds1"; m_opcode = "ps_madds1";
m_operands = StringFromFormat("p%u, p%u*p%u[1]+p%u", FD, FA, FC, FB); m_operands = fmt::format("p{}, p{}*p{}[1]+p{}", FD, FA, FC, FB);
return; return;
} }
@ -1125,22 +1162,22 @@ void GekkoDisassembler::ps(u32 inst)
// 10-bit suckers (?) // 10-bit suckers (?)
case 40: // nmadd case 40: // nmadd
m_opcode = "ps_neg"; m_opcode = "ps_neg";
m_operands = StringFromFormat("p%u, -p%u", FD, FB); m_operands = fmt::format("p{}, -p{}", FD, FB);
return; return;
case 72: // nmadd case 72: // nmadd
m_opcode = "ps_mr"; m_opcode = "ps_mr";
m_operands = StringFromFormat("p%u, p%u", FD, FB); m_operands = fmt::format("p{}, p{}", FD, FB);
return; return;
case 136: case 136:
m_opcode = "ps_nabs"; m_opcode = "ps_nabs";
m_operands = StringFromFormat("p%u, -|p%u|", FD, FB); m_operands = fmt::format("p{}, -|p{}|", FD, FB);
return; return;
case 264: case 264:
m_opcode = "ps_abs"; m_opcode = "ps_abs";
m_operands = StringFromFormat("p%u, |p%u|", FD, FB); m_operands = fmt::format("p{}, |p{}|", FD, FB);
return; return;
case 0: case 0:
@ -1152,28 +1189,28 @@ void GekkoDisassembler::ps(u32 inst)
int i = (int)PPCGETCRD(inst); int i = (int)PPCGETCRD(inst);
if (i != 0) if (i != 0)
m_operands += StringFromFormat("cr%c, ", '0' + i); m_operands += fmt::format("cr{}, ", '0' + i);
m_operands += StringFromFormat("p%u, p%u", FA, FB); m_operands += fmt::format("p{}, p{}", FA, FB);
return; return;
} }
case 528: case 528:
m_opcode = "ps_merge00"; m_opcode = "ps_merge00";
m_operands = StringFromFormat("p%u, p%u[0],p%u[0]", FD, FA, FB); m_operands = fmt::format("p{}, p{}[0],p{}[0]", FD, FA, FB);
return; return;
case 560: case 560:
m_opcode = "ps_merge01"; m_opcode = "ps_merge01";
m_operands = StringFromFormat("p%u, p%u[0],p%u[1]", FD, FA, FB); m_operands = fmt::format("p{}, p{}[0],p{}[1]", FD, FA, FB);
return; return;
case 592: case 592:
m_opcode = "ps_merge10"; m_opcode = "ps_merge10";
m_operands = StringFromFormat("p%u, p%u[1],p%u[0]", FD, FA, FB); m_operands = fmt::format("p{}, p{}[1],p{}[0]", FD, FA, FB);
return; return;
case 624: case 624:
m_opcode = "ps_merge11"; m_opcode = "ps_merge11";
m_operands = StringFromFormat("p%u, p%u[1],p%u[1]", FD, FA, FB); m_operands = fmt::format("p{}, p{}[1],p{}[1]", FD, FA, FB);
return; return;
case 1014: case 1014:
@ -1185,7 +1222,7 @@ void GekkoDisassembler::ps(u32 inst)
} }
// default: // default:
m_opcode = StringFromFormat("ps_%i", ((inst >> 1) & 0x1f)); m_opcode = fmt::format("ps_{}", ((inst >> 1) & 0x1f));
m_operands = "---"; m_operands = "---";
} }
@ -1195,23 +1232,23 @@ void GekkoDisassembler::ps_mem(u32 inst)
{ {
case 56: case 56:
m_opcode = "psq_l"; m_opcode = "psq_l";
m_operands = StringFromFormat("p%u, %i(r%u), %d, qr%d", RS, SEX12(inst & 0xFFF), RA, W, I); m_operands = fmt::format("p{}, {}(r{}), {}, qr{}", RS, SEX12(inst & 0xFFF), RA, W, I);
break; break;
case 57: case 57:
m_opcode = "psq_lu"; m_opcode = "psq_lu";
m_operands = StringFromFormat("p%u, %i(r%u), %d, qr%d", RS, SEX12(inst & 0xFFF), RA, W, I); m_operands = fmt::format("p{}, {}(r{}), {}, qr{}", RS, SEX12(inst & 0xFFF), RA, W, I);
; ;
break; break;
case 60: case 60:
m_opcode = "psq_st"; m_opcode = "psq_st";
m_operands = StringFromFormat("p%u, %i(r%u), %d, qr%d", RS, SEX12(inst & 0xFFF), RA, W, I); m_operands = fmt::format("p{}, {}(r{}), {}, qr{}", RS, SEX12(inst & 0xFFF), RA, W, I);
break; break;
case 61: case 61:
m_opcode = "psq_stu"; m_opcode = "psq_stu";
m_operands = StringFromFormat("p%u, %i(r%u), %d, qr%d", RS, SEX12(inst & 0xFFF), RA, W, I); m_operands = fmt::format("p{}, {}(r{}), {}, qr{}", RS, SEX12(inst & 0xFFF), RA, W, I);
break; break;
} }
} }
@ -1845,7 +1882,7 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian)
else else
{ {
m_opcode = "mcrxr"; m_opcode = "mcrxr";
m_operands = StringFromFormat("cr%d", (int)PPCGETCRD(in)); m_operands = fmt::format("cr{}", PPCGETCRD(in));
} }
break; break;
@ -2214,8 +2251,8 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian)
case 134: case 134:
if ((in & 0x006f0800) == 0) if ((in & 0x006f0800) == 0)
{ {
m_opcode = StringFromFormat("mtfsfi%s", rcsel[in & 1]); m_opcode = fmt::format("mtfsfi{}", rcsel[in & 1]);
m_operands = StringFromFormat("cr%d,%d", (int)PPCGETCRD(in), (int)(in & 0xf000) >> 12); m_operands = fmt::format("cr{},{}", PPCGETCRD(in), (in & 0xf000) >> 12);
} }
else else
{ {
@ -2241,8 +2278,8 @@ u32* GekkoDisassembler::DoDisassembly(bool big_endian)
case 711: case 711:
if ((in & 0x02010000) == 0) if ((in & 0x02010000) == 0)
{ {
m_opcode = StringFromFormat("mtfsf%s", rcsel[in & 1]); m_opcode = fmt::format("mtfsf{}", rcsel[in & 1]);
m_operands = StringFromFormat("0x%x, f%u", (in >> 17) & 0xff, PPCGETB(in)); m_operands = fmt::format("0x{:x}, f{}", (in >> 17) & 0xff, PPCGETB(in));
} }
else else
{ {

View File

@ -93,42 +93,6 @@ private:
static u32* DoDisassembly(bool big_endian); static u32* DoDisassembly(bool big_endian);
static u32 HelperRotateMask(int r, int mb, int me)
{
// first make 001111111111111 part
unsigned int begin = 0xFFFFFFFF >> mb;
// then make 000000000001111 part, which is used to flip the bits of the first one
unsigned int end = me < 31 ? (0xFFFFFFFF >> (me + 1)) : 0;
// do the bitflip
unsigned int mask = begin ^ end;
// and invert if backwards
if (me < mb)
mask = ~mask;
// rotate the mask so it can be applied to source reg
// return _rotl(mask, 32 - r);
return (mask << (32 - r)) | (mask >> r);
}
static std::string ldst_offs(u32 val)
{
if (val == 0)
{
return "0";
}
else
{
if (val & 0x8000)
{
return StringFromFormat("-0x%.4X", ((~val) & 0xffff) + 1);
}
else
{
return StringFromFormat("0x%.4X", val);
}
}
}
static int SEX12(u32 x) { return x & 0x800 ? (x | 0xFFFFF000) : x; }
enum InstructionType enum InstructionType
{ {
PPCINSTR_OTHER = 0, // No additional info for other instr. PPCINSTR_OTHER = 0, // No additional info for other instr.

View File

@ -2,16 +2,18 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cinttypes> #include "Common/JitRegister.h"
#include <cstddef> #include <cstddef>
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include <fmt/format.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/File.h" #include "Common/File.h"
#include "Common/JitRegister.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#ifdef _WIN32 #ifdef _WIN32
@ -48,8 +50,8 @@ void Init(const std::string& perf_dir)
if (!perf_dir.empty() || getenv("PERF_BUILDID_DIR")) if (!perf_dir.empty() || getenv("PERF_BUILDID_DIR"))
{ {
std::string dir = perf_dir.empty() ? "/tmp" : perf_dir; const std::string dir = perf_dir.empty() ? "/tmp" : perf_dir;
std::string filename = StringFromFormat("%s/perf-%d.map", dir.data(), getpid()); const std::string filename = fmt::format("{}/perf-{}.map", dir, getpid());
s_perf_map_file.Open(filename, "w"); s_perf_map_file.Open(filename, "w");
// Disable buffering in order to avoid missing some mappings // Disable buffering in order to avoid missing some mappings
// if the event of a crash: // if the event of a crash:
@ -90,7 +92,7 @@ void RegisterV(const void* base_address, u32 code_size, const char* format, va_l
std::string symbol_name = StringFromFormatV(format, args); std::string symbol_name = StringFromFormatV(format, args);
#if defined USE_OPROFILE && USE_OPROFILE #if defined USE_OPROFILE && USE_OPROFILE
op_write_native_code(s_agent, symbol_name.data(), (u64)base_address, base_address, code_size); op_write_native_code(s_agent, symbol_name.c_str(), (u64)base_address, base_address, code_size);
#endif #endif
#ifdef USE_VTUNE #ifdef USE_VTUNE
@ -98,16 +100,15 @@ void RegisterV(const void* base_address, u32 code_size, const char* format, va_l
jmethod.method_id = iJIT_GetNewMethodID(); jmethod.method_id = iJIT_GetNewMethodID();
jmethod.method_load_address = const_cast<void*>(base_address); jmethod.method_load_address = const_cast<void*>(base_address);
jmethod.method_size = code_size; jmethod.method_size = code_size;
jmethod.method_name = const_cast<char*>(symbol_name.data()); jmethod.method_name = const_cast<char*>(symbol_name.c_str());
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&jmethod); iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void*)&jmethod);
#endif #endif
// Linux perf /tmp/perf-$pid.map: // Linux perf /tmp/perf-$pid.map:
if (s_perf_map_file.IsOpen()) if (!s_perf_map_file.IsOpen())
{ return;
std::string entry =
StringFromFormat("%" PRIx64 " %x %s\n", (u64)base_address, code_size, symbol_name.data()); const auto entry = fmt::format("{} {:x} {}\n", fmt::ptr(base_address), code_size, symbol_name);
s_perf_map_file.WriteBytes(entry.data(), entry.size()); s_perf_map_file.WriteBytes(entry.data(), entry.size());
}
} }
} // namespace JitRegister } // namespace JitRegister

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Common/Logging/LogManager.h"
#include <algorithm> #include <algorithm>
#include <cstdarg> #include <cstdarg>
#include <cstring> #include <cstring>
@ -10,12 +12,13 @@
#include <ostream> #include <ostream>
#include <string> #include <string>
#include <fmt/format.h>
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
#include "Common/Config/Config.h" #include "Common/Config/Config.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/Logging/ConsoleListener.h" #include "Common/Logging/ConsoleListener.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/Logging/LogManager.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Common/Timer.h" #include "Common/Timer.h"
@ -207,9 +210,9 @@ void LogManager::LogWithFullPath(LogTypes::LOG_LEVELS level, LogTypes::LOG_TYPE
char temp[MAX_MSGLEN]; char temp[MAX_MSGLEN];
CharArrayFromFormatV(temp, MAX_MSGLEN, format, args); CharArrayFromFormatV(temp, MAX_MSGLEN, format, args);
std::string msg = const std::string msg =
StringFromFormat("%s %s:%u %c[%s]: %s\n", Common::Timer::GetTimeFormatted().c_str(), file, fmt::format("{} {}:{} {}[{}]: {}\n", Common::Timer::GetTimeFormatted(), file, line,
line, LogTypes::LOG_LEVEL_TO_CHAR[(int)level], GetShortName(type), temp); LogTypes::LOG_LEVEL_TO_CHAR[(int)level], GetShortName(type), temp);
for (auto listener_id : m_listener_ids) for (auto listener_id : m_listener_ids)
if (m_listeners[listener_id]) if (m_listeners[listener_id])

View File

@ -2,12 +2,15 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Common/MD5.h"
#include <fstream> #include <fstream>
#include <functional> #include <functional>
#include <mbedtls/md5.h> #include <mbedtls/md5.h>
#include <string> #include <string>
#include "Common/MD5.h" #include <fmt/format.h>
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "DiscIO/Blob.h" #include "DiscIO/Blob.h"
@ -45,7 +48,7 @@ std::string MD5Sum(const std::string& file_path, std::function<bool(int)> report
// Convert to hex // Convert to hex
for (u8 n : output) for (u8 n : output)
output_string += StringFromFormat("%02x", n); output_string += fmt::format("{:02x}", n);
return output_string; return output_string;
} }

View File

@ -9,6 +9,8 @@
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include <fmt/format.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/FileUtil.h" #include "Common/FileUtil.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
@ -28,21 +30,20 @@ static std::string RootUserPath(std::optional<FromWhichRoot> from)
std::string GetImportTitlePath(u64 title_id, std::optional<FromWhichRoot> from) std::string GetImportTitlePath(u64 title_id, std::optional<FromWhichRoot> from)
{ {
return RootUserPath(from) + StringFromFormat("/import/%08x/%08x", return RootUserPath(from) + fmt::format("/import/{:08x}/{:08x}", static_cast<u32>(title_id >> 32),
static_cast<u32>(title_id >> 32),
static_cast<u32>(title_id)); static_cast<u32>(title_id));
} }
std::string GetTicketFileName(u64 title_id, std::optional<FromWhichRoot> from) std::string GetTicketFileName(u64 title_id, std::optional<FromWhichRoot> from)
{ {
return StringFromFormat("%s/ticket/%08x/%08x.tik", RootUserPath(from).c_str(), return fmt::format("{}/ticket/{:08x}/{:08x}.tik", RootUserPath(from),
static_cast<u32>(title_id >> 32), static_cast<u32>(title_id)); static_cast<u32>(title_id >> 32), static_cast<u32>(title_id));
} }
std::string GetTitlePath(u64 title_id, std::optional<FromWhichRoot> from) std::string GetTitlePath(u64 title_id, std::optional<FromWhichRoot> from)
{ {
return StringFromFormat("%s/title/%08x/%08x", RootUserPath(from).c_str(), return fmt::format("{}/title/{:08x}/{:08x}", RootUserPath(from), static_cast<u32>(title_id >> 32),
static_cast<u32>(title_id >> 32), static_cast<u32>(title_id)); static_cast<u32>(title_id));
} }
std::string GetTitleDataPath(u64 title_id, std::optional<FromWhichRoot> from) std::string GetTitleDataPath(u64 title_id, std::optional<FromWhichRoot> from)
@ -62,7 +63,7 @@ std::string GetTMDFileName(u64 title_id, std::optional<FromWhichRoot> from)
std::string GetMiiDatabasePath(std::optional<FromWhichRoot> from) std::string GetMiiDatabasePath(std::optional<FromWhichRoot> from)
{ {
return StringFromFormat("%s/shared2/menu/FaceLib/RFL_DB.dat", RootUserPath(from).c_str()); return fmt::format("{}/shared2/menu/FaceLib/RFL_DB.dat", RootUserPath(from));
} }
bool IsTitlePath(const std::string& path, std::optional<FromWhichRoot> from, u64* title_id) bool IsTitlePath(const std::string& path, std::optional<FromWhichRoot> from, u64* title_id)
@ -111,7 +112,7 @@ std::string EscapeFileName(const std::string& filename)
for (char c : filename_with_escaped_double_underscores) for (char c : filename_with_escaped_double_underscores)
{ {
if ((c >= 0 && c <= 0x1F) || chars_to_replace.find(c) != chars_to_replace.end()) if ((c >= 0 && c <= 0x1F) || chars_to_replace.find(c) != chars_to_replace.end())
result.append(StringFromFormat("__%02x__", c)); result.append(fmt::format("__{:02x}__", c));
else else
result.push_back(c); result.push_back(c);
} }

View File

@ -9,8 +9,9 @@
#include <cstring> #include <cstring>
#include <ctime> #include <ctime>
#include <fmt/format.h>
#include "Common/Random.h" #include "Common/Random.h"
#include "Common/StringUtil.h"
namespace Common namespace Common
{ {
@ -38,8 +39,8 @@ MACAddress GenerateMacAddress(const MACConsumer type)
std::string MacAddressToString(const MACAddress& mac) std::string MacAddressToString(const MACAddress& mac)
{ {
return StringFromFormat("%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], return fmt::format("{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}", mac[0], mac[1], mac[2], mac[3],
mac[5]); mac[4], mac[5]);
} }
std::optional<MACAddress> StringToMacAddress(const std::string& mac_string) std::optional<MACAddress> StringToMacAddress(const std::string& mac_string)

View File

@ -2,8 +2,9 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include "Common/StringUtil.h"
#include <algorithm> #include <algorithm>
#include <cinttypes>
#include <cstdarg> #include <cstdarg>
#include <cstddef> #include <cstddef>
#include <cstdio> #include <cstdio>
@ -18,11 +19,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <fmt/format.h>
#include "Common/CommonFuncs.h" #include "Common/CommonFuncs.h"
#include "Common/CommonPaths.h" #include "Common/CommonPaths.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/StringUtil.h"
#include "Common/Swap.h" #include "Common/Swap.h"
#ifdef _WIN32 #ifdef _WIN32
@ -51,12 +53,12 @@ std::string HexDump(const u8* data, size_t size)
std::string out; std::string out;
for (size_t row_start = 0; row_start < size; row_start += BYTES_PER_LINE) for (size_t row_start = 0; row_start < size; row_start += BYTES_PER_LINE)
{ {
out += StringFromFormat("%06zx: ", row_start); out += fmt::format("{:06x}: ", row_start);
for (size_t i = 0; i < BYTES_PER_LINE; ++i) for (size_t i = 0; i < BYTES_PER_LINE; ++i)
{ {
if (row_start + i < size) if (row_start + i < size)
{ {
out += StringFromFormat("%02hhx ", data[row_start + i]); out += fmt::format("{:02x} ", data[row_start + i]);
} }
else else
{ {
@ -294,27 +296,27 @@ bool TryParse(const std::string& str, bool* const output)
std::string ValueToString(u16 value) std::string ValueToString(u16 value)
{ {
return StringFromFormat("0x%04x", value); return fmt::format("0x{:04x}", value);
} }
std::string ValueToString(u32 value) std::string ValueToString(u32 value)
{ {
return StringFromFormat("0x%08x", value); return fmt::format("0x{:08x}", value);
} }
std::string ValueToString(u64 value) std::string ValueToString(u64 value)
{ {
return StringFromFormat("0x%016" PRIx64, value); return fmt::format("0x{:016x}", value);
} }
std::string ValueToString(float value) std::string ValueToString(float value)
{ {
return StringFromFormat("%#.9g", value); return fmt::format("{:#.9g}", value);
} }
std::string ValueToString(double value) std::string ValueToString(double value)
{ {
return StringFromFormat("%#.17g", value); return fmt::format("{:#.17g}", value);
} }
std::string ValueToString(int value) std::string ValueToString(int value)
@ -324,7 +326,7 @@ std::string ValueToString(int value)
std::string ValueToString(s64 value) std::string ValueToString(s64 value)
{ {
return StringFromFormat("%" PRId64, value); return std::to_string(value);
} }
std::string ValueToString(bool value) std::string ValueToString(bool value)

View File

@ -2,7 +2,8 @@
// Licensed under GPLv2+ // Licensed under GPLv2+
// Refer to the license.txt file included. // Refer to the license.txt file included.
#include <cinttypes> #include "Common/Timer.h"
#include <ctime> #include <ctime>
#include <string> #include <string>
@ -16,9 +17,10 @@
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#include <fmt/format.h>
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Common/Timer.h"
namespace Common namespace Common
{ {
@ -149,9 +151,8 @@ std::string Timer::GetTimeElapsedFormatted() const
// Hours // Hours
u32 Hours = Minutes / 60; u32 Hours = Minutes / 60;
std::string TmpStr = StringFromFormat("%02i:%02i:%02i:%03" PRIu64, Hours, Minutes % 60, return fmt::format("{:02}:{:02}:{:02}:{:03}", Hours, Minutes % 60, Seconds % 60,
Seconds % 60, Milliseconds % 1000); Milliseconds % 1000);
return TmpStr;
} }
// Get current time // Get current time
@ -217,15 +218,15 @@ std::string Timer::GetTimeFormatted()
#ifdef _WIN32 #ifdef _WIN32
struct timeb tp; struct timeb tp;
(void)::ftime(&tp); (void)::ftime(&tp);
return UTF16ToUTF8(tmp) + StringFromFormat(":%03i", tp.millitm); return UTF16ToUTF8(tmp) + fmt::format(":{:03}", tp.millitm);
#elif defined __APPLE__ #elif defined __APPLE__
struct timeval t; struct timeval t;
(void)gettimeofday(&t, nullptr); (void)gettimeofday(&t, nullptr);
return StringFromFormat("%s:%03d", tmp, (int)(t.tv_usec / 1000)); return fmt::format("{}:{:03}", tmp, t.tv_usec / 1000);
#else #else
struct timespec t; struct timespec t;
(void)clock_gettime(CLOCK_MONOTONIC, &t); (void)clock_gettime(CLOCK_MONOTONIC, &t);
return StringFromFormat("%s:%03d", tmp, (int)(t.tv_nsec / 1000000)); return fmt::format("{}:{:03}", tmp, t.tv_nsec / 1000000);
#endif #endif
} }

View File

@ -41,6 +41,7 @@
<AdditionalIncludeDirectories>$(ExternalsDir)curl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)curl\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)enet\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)enet\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)ffmpeg\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)ffmpeg\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)fmt\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)GL;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)GL;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)glslang\glslang\Public;$(ExternalsDir)glslang\SPIRV;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)glslang\glslang\Public;$(ExternalsDir)glslang\SPIRV;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)imgui;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)imgui;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
@ -55,6 +56,7 @@
<AdditionalIncludeDirectories>$(ExternalsDir)xxhash;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)xxhash;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>$(ExternalsDir)zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> <AdditionalIncludeDirectories>$(ExternalsDir)zlib;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>HAVE_FFMPEG;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>HAVE_FFMPEG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>FMT_HEADER_ONLY=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>USE_UPNP;USE_USBDK;__LIBUSB__;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>USE_UPNP;USE_USBDK;__LIBUSB__;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>_M_X86=1;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions>_M_X86=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>