mirror of
https://git.suyu.dev/suyu/dynarmic.git
synced 2025-12-25 16:54:40 +01:00
Convert formatting over to fmtlib
This commit is contained in:
parent
ee4b30eee4
commit
0102951bdd
9 changed files with 330 additions and 373 deletions
|
|
@ -9,8 +9,9 @@
|
|||
#include <map>
|
||||
#include <string>
|
||||
|
||||
#include <fmt/format.h>
|
||||
|
||||
#include "common/assert.h"
|
||||
#include "common/string_util.h"
|
||||
#include "frontend/ir/basic_block.h"
|
||||
#include "frontend/ir/opcodes.h"
|
||||
|
||||
|
|
@ -91,40 +92,40 @@ const size_t& Block::CycleCount() const {
|
|||
}
|
||||
|
||||
static std::string LocDescToString(const Arm::LocationDescriptor& loc) {
|
||||
return Common::StringFromFormat("{%u,%s,%s,%u}",
|
||||
loc.PC(),
|
||||
loc.TFlag() ? "T" : "!T",
|
||||
loc.EFlag() ? "E" : "!E",
|
||||
loc.FPSCR().Value());
|
||||
return fmt::format("{{{},{},{},{}}}",
|
||||
loc.PC(),
|
||||
loc.TFlag() ? "T" : "!T",
|
||||
loc.EFlag() ? "E" : "!E",
|
||||
loc.FPSCR().Value());
|
||||
}
|
||||
|
||||
static std::string TerminalToString(const Terminal& terminal_variant) {
|
||||
switch (terminal_variant.which()) {
|
||||
case 1: {
|
||||
auto terminal = boost::get<IR::Term::Interpret>(terminal_variant);
|
||||
return Common::StringFromFormat("Interpret{%s}", LocDescToString(terminal.next).c_str());
|
||||
return fmt::format("Interpret{{{}}}", LocDescToString(terminal.next));
|
||||
}
|
||||
case 2: {
|
||||
return Common::StringFromFormat("ReturnToDispatch{}");
|
||||
return "ReturnToDispatch{}";
|
||||
}
|
||||
case 3: {
|
||||
auto terminal = boost::get<IR::Term::LinkBlock>(terminal_variant);
|
||||
return Common::StringFromFormat("LinkBlock{%s}", LocDescToString(terminal.next).c_str());
|
||||
return fmt::format("LinkBlock{{{}}}", LocDescToString(terminal.next));
|
||||
}
|
||||
case 4: {
|
||||
auto terminal = boost::get<IR::Term::LinkBlockFast>(terminal_variant);
|
||||
return Common::StringFromFormat("LinkBlockFast{%s}", LocDescToString(terminal.next).c_str());
|
||||
return fmt::format("LinkBlockFast{{{}}}", LocDescToString(terminal.next));
|
||||
}
|
||||
case 5: {
|
||||
return Common::StringFromFormat("PopRSBHint{}");
|
||||
return "PopRSBHint{}";
|
||||
}
|
||||
case 6: {
|
||||
auto terminal = boost::get<IR::Term::If>(terminal_variant);
|
||||
return Common::StringFromFormat("If{%s, %s, %s}", CondToString(terminal.if_), TerminalToString(terminal.then_).c_str(), TerminalToString(terminal.else_).c_str());
|
||||
return fmt::format("If{{{}, {}, {}}}", CondToString(terminal.if_), TerminalToString(terminal.then_), TerminalToString(terminal.else_));
|
||||
}
|
||||
case 7: {
|
||||
auto terminal = boost::get<IR::Term::CheckHalt>(terminal_variant);
|
||||
return Common::StringFromFormat("CheckHalt{%s}", TerminalToString(terminal.else_).c_str());
|
||||
return fmt::format("CheckHalt{{{}}}", TerminalToString(terminal.else_));
|
||||
}
|
||||
default:
|
||||
return "<invalid terminal>";
|
||||
|
|
@ -134,13 +135,13 @@ static std::string TerminalToString(const Terminal& terminal_variant) {
|
|||
std::string DumpBlock(const IR::Block& block) {
|
||||
std::string ret;
|
||||
|
||||
ret += Common::StringFromFormat("Block: location=%s\n", LocDescToString(block.Location()).c_str());
|
||||
ret += Common::StringFromFormat("cycles=%zu", block.CycleCount());
|
||||
ret += Common::StringFromFormat(", entry_cond=%s", Arm::CondToString(block.GetCondition(), true));
|
||||
ret += fmt::format("Block: location={}\n", LocDescToString(block.Location()));
|
||||
ret += fmt::format("cycles={}", block.CycleCount());
|
||||
ret += fmt::format(", entry_cond={}", Arm::CondToString(block.GetCondition(), true));
|
||||
if (block.GetCondition() != Arm::Cond::AL) {
|
||||
ret += Common::StringFromFormat(", cond_fail=%s", LocDescToString(block.ConditionFailedLocation()).c_str());
|
||||
ret += fmt::format(", cond_fail={}", LocDescToString(block.ConditionFailedLocation()));
|
||||
}
|
||||
ret += "\n";
|
||||
ret += '\n';
|
||||
|
||||
std::map<const IR::Inst*, size_t> inst_to_index;
|
||||
size_t index = 0;
|
||||
|
|
@ -149,15 +150,15 @@ std::string DumpBlock(const IR::Block& block) {
|
|||
if (arg.IsEmpty()) {
|
||||
return "<null>";
|
||||
} else if (!arg.IsImmediate()) {
|
||||
return Common::StringFromFormat("%%%zu", inst_to_index.at(arg.GetInst()));
|
||||
return fmt::format("%{}", inst_to_index.at(arg.GetInst()));
|
||||
}
|
||||
switch (arg.GetType()) {
|
||||
case Type::U1:
|
||||
return Common::StringFromFormat("#%s", arg.GetU1() ? "1" : "0");
|
||||
return fmt::format("#{}", arg.GetU1() ? '1' : '0');
|
||||
case Type::U8:
|
||||
return Common::StringFromFormat("#%u", arg.GetU8());
|
||||
return fmt::format("#{}", arg.GetU8());
|
||||
case Type::U32:
|
||||
return Common::StringFromFormat("#%#x", arg.GetU32());
|
||||
return fmt::format("#{:#x}", arg.GetU32());
|
||||
case Type::RegRef:
|
||||
return Arm::RegToString(arg.GetRegRef());
|
||||
case Type::ExtRegRef:
|
||||
|
|
@ -171,7 +172,7 @@ std::string DumpBlock(const IR::Block& block) {
|
|||
const Opcode op = inst.GetOpcode();
|
||||
|
||||
if (GetTypeOf(op) != Type::Void) {
|
||||
ret += Common::StringFromFormat("%%%-5zu = ", index);
|
||||
ret += fmt::format("%{:<5} = ", index);
|
||||
} else {
|
||||
ret += " "; // '%00000 = ' -> 1 + 5 + 3 = 9 spaces
|
||||
}
|
||||
|
|
@ -188,15 +189,15 @@ std::string DumpBlock(const IR::Block& block) {
|
|||
Type actual_type = arg.GetType();
|
||||
Type expected_type = GetArgTypeOf(op, arg_index);
|
||||
if (!AreTypesCompatible(actual_type, expected_type)) {
|
||||
ret += Common::StringFromFormat("<type error: %s != %s>", GetNameOf(actual_type), GetNameOf(expected_type));
|
||||
ret += fmt::format("<type error: {} != {}>", GetNameOf(actual_type), GetNameOf(expected_type));
|
||||
}
|
||||
}
|
||||
|
||||
ret += "\n";
|
||||
ret += '\n';
|
||||
inst_to_index[&inst] = index++;
|
||||
}
|
||||
|
||||
ret += "terminal = " + TerminalToString(block.GetTerminal()) + "\n";
|
||||
ret += "terminal = " + TerminalToString(block.GetTerminal()) + '\n';
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue