feat: Add custom formatters for Shader::IR::Inst in formatters.h

- Created a new header file `formatters.h` under `shader_recompiler/frontend/ir/`.
- Added a custom `fmt::formatter` specialization for the `Shader::IR::Inst` type.
- This allows `Shader::IR::Inst` objects to be formatted using `fmt::format`, `fmt::print`, and similar functions from the `fmt` library.
- The formatter uses the `ToString` method of `Shader::IR::Inst` to generate a formatted string representation.
This commit is contained in:
Phoenix 2024-08-31 23:32:25 +10:00
parent 4b35c8c259
commit c56306393b

View File

@ -0,0 +1,20 @@
// shader_recompiler/frontend/ir/formatters.h
#pragma once
#include <fmt/format.h>
#include "shader_recompiler/frontend/ir/value.h"
namespace Shader::IR {
// Custom formatter for Shader::IR::Inst
template <>
struct fmt::formatter<Shader::IR::Inst> {
constexpr auto parse(fmt::format_parse_context& ctx) {
return ctx.begin();
}
template <typename FormatContext>
auto format(const Shader::IR::Inst& inst, FormatContext& ctx) {
return fmt::format_to(ctx.out(), "{}", inst.ToString());
}
};
}