diff options
| author | David <25727384+ogniK5377@users.noreply.github.com> | 2019-10-05 21:52:20 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-05 21:52:20 +1000 |
| commit | 3728bbc22a9224ff75fff22487a47bcaaf6ac2be (patch) | |
| tree | 80809634787307002bf9e07b710a4aa968019f26 /src/video_core/shader/expr.h | |
| parent | 0a662d009b1567bde5b0aa91e07365224858ca18 (diff) | |
| parent | e6eae4b815bf4bc480d62677fdf9bdbf5d6cba82 (diff) | |
Merge pull request #2888 from FernandoS27/decompiler2
Shader_IR: Implement a full control flow decompiler for the shader IR.
Diffstat (limited to 'src/video_core/shader/expr.h')
| -rw-r--r-- | src/video_core/shader/expr.h | 120 |
1 files changed, 120 insertions, 0 deletions
diff --git a/src/video_core/shader/expr.h b/src/video_core/shader/expr.h new file mode 100644 index 000000000..4c399cef9 --- /dev/null +++ b/src/video_core/shader/expr.h @@ -0,0 +1,120 @@ +// Copyright 2019 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <memory> +#include <variant> + +#include "video_core/engines/shader_bytecode.h" + +namespace VideoCommon::Shader { + +using Tegra::Shader::ConditionCode; +using Tegra::Shader::Pred; + +class ExprAnd; +class ExprOr; +class ExprNot; +class ExprPredicate; +class ExprCondCode; +class ExprVar; +class ExprBoolean; + +using ExprData = + std::variant<ExprVar, ExprCondCode, ExprPredicate, ExprNot, ExprOr, ExprAnd, ExprBoolean>; +using Expr = std::shared_ptr<ExprData>; + +class ExprAnd final { +public: + explicit ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {} + + bool operator==(const ExprAnd& b) const; + + Expr operand1; + Expr operand2; +}; + +class ExprOr final { +public: + explicit ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {} + + bool operator==(const ExprOr& b) const; + + Expr operand1; + Expr operand2; +}; + +class ExprNot final { +public: + explicit ExprNot(Expr a) : operand1{a} {} + + bool operator==(const ExprNot& b) const; + + Expr operand1; +}; + +class ExprVar final { +public: + explicit ExprVar(u32 index) : var_index{index} {} + + bool operator==(const ExprVar& b) const { + return var_index == b.var_index; + } + + u32 var_index; +}; + +class ExprPredicate final { +public: + explicit ExprPredicate(u32 predicate) : predicate{predicate} {} + + bool operator==(const ExprPredicate& b) const { + return predicate == b.predicate; + } + + u32 predicate; +}; + +class ExprCondCode final { +public: + explicit ExprCondCode(ConditionCode cc) : cc{cc} {} + + bool operator==(const ExprCondCode& b) const { + return cc == b.cc; + } + + ConditionCode cc; +}; + +class ExprBoolean final { +public: + explicit ExprBoolean(bool val) : value{val} {} + + bool operator==(const ExprBoolean& b) const { + return value == b.value; + } + + bool value; +}; + +template <typename T, typename... Args> +Expr MakeExpr(Args&&... args) { + static_assert(std::is_convertible_v<T, ExprData>); + return std::make_shared<ExprData>(T(std::forward<Args>(args)...)); +} + +bool ExprAreEqual(Expr first, Expr second); + +bool ExprAreOpposite(Expr first, Expr second); + +Expr MakeExprNot(Expr first); + +Expr MakeExprAnd(Expr first, Expr second); + +Expr MakeExprOr(Expr first, Expr second); + +bool ExprIsTrue(Expr first); + +} // namespace VideoCommon::Shader |
