diff options
Diffstat (limited to 'src/shader_recompiler/frontend/ir/condition.h')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/condition.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/condition.h b/src/shader_recompiler/frontend/ir/condition.h new file mode 100644 index 000000000..aa8597c60 --- /dev/null +++ b/src/shader_recompiler/frontend/ir/condition.h | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | // Copyright 2021 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <compare> | ||
| 8 | #include <string> | ||
| 9 | |||
| 10 | #include <fmt/format.h> | ||
| 11 | |||
| 12 | #include "common/common_types.h" | ||
| 13 | #include "shader_recompiler/frontend/ir/flow_test.h" | ||
| 14 | #include "shader_recompiler/frontend/ir/pred.h" | ||
| 15 | |||
| 16 | namespace Shader::IR { | ||
| 17 | |||
| 18 | class Condition { | ||
| 19 | public: | ||
| 20 | Condition() noexcept = default; | ||
| 21 | |||
| 22 | explicit Condition(FlowTest flow_test_, Pred pred_, bool pred_negated_ = false) noexcept | ||
| 23 | : flow_test{static_cast<u16>(flow_test_)}, pred{static_cast<u8>(pred_)}, | ||
| 24 | pred_negated{pred_negated_ ? u8{1} : u8{0}} {} | ||
| 25 | |||
| 26 | explicit Condition(Pred pred_, bool pred_negated_ = false) noexcept | ||
| 27 | : Condition(FlowTest::T, pred_, pred_negated_) {} | ||
| 28 | |||
| 29 | explicit Condition(bool value) : Condition(Pred::PT, !value) {} | ||
| 30 | |||
| 31 | auto operator<=>(const Condition&) const noexcept = default; | ||
| 32 | |||
| 33 | [[nodiscard]] IR::FlowTest GetFlowTest() const noexcept { | ||
| 34 | return static_cast<IR::FlowTest>(flow_test); | ||
| 35 | } | ||
| 36 | |||
| 37 | [[nodiscard]] std::pair<IR::Pred, bool> GetPred() const noexcept { | ||
| 38 | return {static_cast<IR::Pred>(pred), pred_negated != 0}; | ||
| 39 | } | ||
| 40 | |||
| 41 | private: | ||
| 42 | u16 flow_test; | ||
| 43 | u8 pred; | ||
| 44 | u8 pred_negated; | ||
| 45 | }; | ||
| 46 | |||
| 47 | std::string NameOf(Condition condition); | ||
| 48 | |||
| 49 | } // namespace Shader::IR | ||
| 50 | |||
| 51 | template <> | ||
| 52 | struct fmt::formatter<Shader::IR::Condition> { | ||
| 53 | constexpr auto parse(format_parse_context& ctx) { | ||
| 54 | return ctx.begin(); | ||
| 55 | } | ||
| 56 | template <typename FormatContext> | ||
| 57 | auto format(const Shader::IR::Condition& cond, FormatContext& ctx) { | ||
| 58 | return fmt::format_to(ctx.out(), "{}", Shader::IR::NameOf(cond)); | ||
| 59 | } | ||
| 60 | }; | ||