diff --git a/src/dynarmic/frontend/A32/a32_location_descriptor.cpp b/src/dynarmic/frontend/A32/a32_location_descriptor.cpp index 62a94113..ac3a374e 100644 --- a/src/dynarmic/frontend/A32/a32_location_descriptor.cpp +++ b/src/dynarmic/frontend/A32/a32_location_descriptor.cpp @@ -5,20 +5,17 @@ #include "dynarmic/frontend/A32/a32_location_descriptor.h" -#include - #include namespace Dynarmic::A32 { -std::ostream& operator<<(std::ostream& o, const LocationDescriptor& descriptor) { - o << fmt::format("{{{:08x},{},{},{:08x}{}}}", - descriptor.PC(), - descriptor.TFlag() ? "T" : "!T", - descriptor.EFlag() ? "E" : "!E", - descriptor.FPSCR().Value(), - descriptor.SingleStepping() ? ",step" : ""); - return o; +std::string ToString(const LocationDescriptor& descriptor) { + return fmt::format("{{{:08x},{},{},{:08x}{}}}", + descriptor.PC(), + descriptor.TFlag() ? "T" : "!T", + descriptor.EFlag() ? "E" : "!E", + descriptor.FPSCR().Value(), + descriptor.SingleStepping() ? ",step" : ""); } } // namespace Dynarmic::A32 diff --git a/src/dynarmic/frontend/A32/a32_location_descriptor.h b/src/dynarmic/frontend/A32/a32_location_descriptor.h index 3bdb72c9..c53e75d4 100644 --- a/src/dynarmic/frontend/A32/a32_location_descriptor.h +++ b/src/dynarmic/frontend/A32/a32_location_descriptor.h @@ -6,9 +6,10 @@ #pragma once #include -#include +#include #include +#include #include #include "dynarmic/frontend/A32/FPSCR.h" @@ -131,10 +132,9 @@ private: /** * Provides a string representation of a LocationDescriptor. * - * @param o Output stream * @param descriptor The descriptor to get a string representation of */ -std::ostream& operator<<(std::ostream& o, const LocationDescriptor& descriptor); +std::string ToString(const LocationDescriptor& descriptor); } // namespace Dynarmic::A32 @@ -152,3 +152,11 @@ struct hash { } }; } // namespace std + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::A32::LocationDescriptor descriptor, FormatContext& ctx) const { + return formatter::format(Dynarmic::A32::ToString(descriptor), ctx); + } +}; diff --git a/src/dynarmic/frontend/A32/a32_types.cpp b/src/dynarmic/frontend/A32/a32_types.cpp index c922f57b..a47ce0b7 100644 --- a/src/dynarmic/frontend/A32/a32_types.cpp +++ b/src/dynarmic/frontend/A32/a32_types.cpp @@ -57,24 +57,4 @@ std::string RegListToString(RegList reg_list) { return ret; } -std::ostream& operator<<(std::ostream& o, Reg reg) { - o << RegToString(reg); - return o; -} - -std::ostream& operator<<(std::ostream& o, ExtReg reg) { - o << ExtRegToString(reg); - return o; -} - -std::ostream& operator<<(std::ostream& o, CoprocReg reg) { - o << CoprocRegToString(reg); - return o; -} - -std::ostream& operator<<(std::ostream& o, RegList reg_list) { - o << RegListToString(reg_list); - return o; -} - } // namespace Dynarmic::A32 diff --git a/src/dynarmic/frontend/A32/a32_types.h b/src/dynarmic/frontend/A32/a32_types.h index 5d1166f3..6f56bea5 100644 --- a/src/dynarmic/frontend/A32/a32_types.h +++ b/src/dynarmic/frontend/A32/a32_types.h @@ -5,10 +5,10 @@ #pragma once -#include #include #include +#include #include #include @@ -72,11 +72,6 @@ const char* ExtRegToString(ExtReg reg); const char* CoprocRegToString(CoprocReg reg); std::string RegListToString(RegList reg_list); -std::ostream& operator<<(std::ostream& o, Reg reg); -std::ostream& operator<<(std::ostream& o, ExtReg reg); -std::ostream& operator<<(std::ostream& o, CoprocReg reg); -std::ostream& operator<<(std::ostream& o, RegList reg_list); - constexpr bool IsSingleExtReg(ExtReg reg) { return reg >= ExtReg::S0 && reg <= ExtReg::S31; } @@ -148,3 +143,35 @@ inline ExtReg ToVector(bool Q, size_t base, bool bit) { } } // namespace Dynarmic::A32 + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::A32::Reg reg, FormatContext& ctx) const { + return formatter::format(Dynarmic::A32::RegToString(reg), ctx); + } +}; + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::A32::ExtReg reg, FormatContext& ctx) const { + return formatter::format(Dynarmic::A32::ExtRegToString(reg), ctx); + } +}; + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::A32::CoprocReg reg, FormatContext& ctx) const { + return formatter::format(Dynarmic::A32::CoprocRegToString(reg), ctx); + } +}; + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::A32::RegList reg_list, FormatContext& ctx) const { + return formatter::format(Dynarmic::A32::RegListToString(reg_list), ctx); + } +}; diff --git a/src/dynarmic/frontend/A64/a64_location_descriptor.cpp b/src/dynarmic/frontend/A64/a64_location_descriptor.cpp index 81c6cafe..83a931ff 100644 --- a/src/dynarmic/frontend/A64/a64_location_descriptor.cpp +++ b/src/dynarmic/frontend/A64/a64_location_descriptor.cpp @@ -5,15 +5,12 @@ #include "dynarmic/frontend/A64/a64_location_descriptor.h" -#include - #include namespace Dynarmic::A64 { -std::ostream& operator<<(std::ostream& o, const LocationDescriptor& descriptor) { - o << fmt::format("{{{}, {}{}}}", descriptor.PC(), descriptor.FPCR().Value(), descriptor.SingleStepping() ? ", step" : ""); - return o; +std::string ToString(const LocationDescriptor& descriptor) { + return fmt::format("{{{}, {}{}}}", descriptor.PC(), descriptor.FPCR().Value(), descriptor.SingleStepping() ? ", step" : ""); } } // namespace Dynarmic::A64 diff --git a/src/dynarmic/frontend/A64/a64_location_descriptor.h b/src/dynarmic/frontend/A64/a64_location_descriptor.h index 3301616f..122bebbc 100644 --- a/src/dynarmic/frontend/A64/a64_location_descriptor.h +++ b/src/dynarmic/frontend/A64/a64_location_descriptor.h @@ -6,9 +6,10 @@ #pragma once #include -#include +#include #include +#include #include #include @@ -84,10 +85,9 @@ private: /** * Provides a string representation of a LocationDescriptor. * - * @param o Output stream * @param descriptor The descriptor to get a string representation of */ -std::ostream& operator<<(std::ostream& o, const LocationDescriptor& descriptor); +std::string ToString(const LocationDescriptor& descriptor); } // namespace Dynarmic::A64 @@ -105,3 +105,11 @@ struct hash { } }; } // namespace std + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::A64::LocationDescriptor descriptor, FormatContext& ctx) const { + return formatter::format(Dynarmic::A64::ToString(descriptor), ctx); + } +}; diff --git a/src/dynarmic/frontend/A64/a64_types.cpp b/src/dynarmic/frontend/A64/a64_types.cpp index 822cf123..ca1c59ab 100644 --- a/src/dynarmic/frontend/A64/a64_types.cpp +++ b/src/dynarmic/frontend/A64/a64_types.cpp @@ -30,14 +30,4 @@ std::string VecToString(Vec vec) { return fmt::format("v{}", static_cast(vec)); } -std::ostream& operator<<(std::ostream& o, Reg reg) { - o << RegToString(reg); - return o; -} - -std::ostream& operator<<(std::ostream& o, Vec vec) { - o << VecToString(vec); - return o; -} - } // namespace Dynarmic::A64 diff --git a/src/dynarmic/frontend/A64/a64_types.h b/src/dynarmic/frontend/A64/a64_types.h index 3bcb84aa..6bc7a245 100644 --- a/src/dynarmic/frontend/A64/a64_types.h +++ b/src/dynarmic/frontend/A64/a64_types.h @@ -5,9 +5,9 @@ #pragma once -#include #include +#include #include #include @@ -101,9 +101,6 @@ const char* CondToString(Cond cond); std::string RegToString(Reg reg); std::string VecToString(Vec vec); -std::ostream& operator<<(std::ostream& o, Reg reg); -std::ostream& operator<<(std::ostream& o, Vec vec); - constexpr size_t RegNumber(Reg reg) { return static_cast(reg); } @@ -127,3 +124,19 @@ inline Vec operator+(Vec vec, size_t number) { } } // namespace Dynarmic::A64 + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::A64::Reg reg, FormatContext& ctx) const { + return formatter::format(Dynarmic::A64::RegToString(reg), ctx); + } +}; + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::A64::Vec vec, FormatContext& ctx) const { + return formatter::format(Dynarmic::A64::VecToString(vec), ctx); + } +}; diff --git a/src/dynarmic/ir/location_descriptor.cpp b/src/dynarmic/ir/location_descriptor.cpp index 19e67ea2..e7e64056 100644 --- a/src/dynarmic/ir/location_descriptor.cpp +++ b/src/dynarmic/ir/location_descriptor.cpp @@ -5,15 +5,12 @@ #include "dynarmic/ir/location_descriptor.h" -#include - #include namespace Dynarmic::IR { -std::ostream& operator<<(std::ostream& o, const LocationDescriptor& descriptor) { - o << fmt::format("{{{:016x}}}", descriptor.Value()); - return o; +std::string ToString(const LocationDescriptor& descriptor) { + return fmt::format("{{{:016x}}}", descriptor.Value()); } } // namespace Dynarmic::IR diff --git a/src/dynarmic/ir/location_descriptor.h b/src/dynarmic/ir/location_descriptor.h index 4b5d77d8..48e5e32b 100644 --- a/src/dynarmic/ir/location_descriptor.h +++ b/src/dynarmic/ir/location_descriptor.h @@ -6,8 +6,9 @@ #pragma once #include -#include +#include +#include #include namespace Dynarmic::IR { @@ -31,7 +32,7 @@ private: u64 value; }; -std::ostream& operator<<(std::ostream& o, const LocationDescriptor& descriptor); +std::string ToString(const LocationDescriptor& descriptor); inline bool operator<(const LocationDescriptor& x, const LocationDescriptor& y) noexcept { return x.Value() < y.Value(); @@ -53,3 +54,11 @@ struct hash { } }; } // namespace std + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::IR::LocationDescriptor descriptor, FormatContext& ctx) const { + return formatter::format(ToString(descriptor), ctx); + } +}; diff --git a/src/dynarmic/ir/microinstruction.cpp b/src/dynarmic/ir/microinstruction.cpp index 3fddb387..cf51363b 100644 --- a/src/dynarmic/ir/microinstruction.cpp +++ b/src/dynarmic/ir/microinstruction.cpp @@ -7,7 +7,6 @@ #include -#include #include #include "dynarmic/ir/opcodes.h" diff --git a/src/dynarmic/ir/opcodes.cpp b/src/dynarmic/ir/opcodes.cpp index 2741e5fb..e80915f9 100644 --- a/src/dynarmic/ir/opcodes.cpp +++ b/src/dynarmic/ir/opcodes.cpp @@ -73,8 +73,4 @@ std::string GetNameOf(Opcode op) { return OpcodeInfo::opcode_info.at(static_cast(op)).name; } -std::ostream& operator<<(std::ostream& o, Opcode opcode) { - return o << GetNameOf(opcode); -} - } // namespace Dynarmic::IR diff --git a/src/dynarmic/ir/opcodes.h b/src/dynarmic/ir/opcodes.h index 719fda00..404f4cdb 100644 --- a/src/dynarmic/ir/opcodes.h +++ b/src/dynarmic/ir/opcodes.h @@ -5,9 +5,9 @@ #pragma once -#include #include +#include #include namespace Dynarmic::IR { @@ -43,6 +43,12 @@ Type GetArgTypeOf(Opcode op, size_t arg_index); /// Get the name of an opcode. std::string GetNameOf(Opcode op); -std::ostream& operator<<(std::ostream& o, Opcode opcode); - } // namespace Dynarmic::IR + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::IR::Opcode op, FormatContext& ctx) const { + return formatter::format(Dynarmic::IR::GetNameOf(op), ctx); + } +}; diff --git a/src/dynarmic/ir/type.cpp b/src/dynarmic/ir/type.cpp index bf1a35c4..7c0f6bf6 100644 --- a/src/dynarmic/ir/type.cpp +++ b/src/dynarmic/ir/type.cpp @@ -43,8 +43,4 @@ bool AreTypesCompatible(Type t1, Type t2) { return t1 == t2 || t1 == Type::Opaque || t2 == Type::Opaque; } -std::ostream& operator<<(std::ostream& o, Type type) { - return o << GetNameOf(type); -} - } // namespace Dynarmic::IR diff --git a/src/dynarmic/ir/type.h b/src/dynarmic/ir/type.h index 7f99e474..65fe76dd 100644 --- a/src/dynarmic/ir/type.h +++ b/src/dynarmic/ir/type.h @@ -5,9 +5,9 @@ #pragma once -#include #include +#include #include namespace Dynarmic::IR { @@ -49,6 +49,12 @@ std::string GetNameOf(Type type); /// @returns true if t1 and t2 are compatible types bool AreTypesCompatible(Type t1, Type t2); -std::ostream& operator<<(std::ostream& o, Type type); - } // namespace Dynarmic::IR + +template<> +struct fmt::formatter : fmt::formatter { + template + auto format(Dynarmic::IR::Type type, FormatContext& ctx) const { + return formatter::format(Dynarmic::IR::GetNameOf(type), ctx); + } +};