summaryrefslogtreecommitdiff
path: root/src/video_core/shader/expr.h
diff options
context:
space:
mode:
authorGravatar David2019-10-05 21:52:20 +1000
committerGravatar GitHub2019-10-05 21:52:20 +1000
commit3728bbc22a9224ff75fff22487a47bcaaf6ac2be (patch)
tree80809634787307002bf9e07b710a4aa968019f26 /src/video_core/shader/expr.h
parentMerge pull request #2917 from FernandoS27/fermi-deduction-2 (diff)
parentShader_ir: Address feedback (diff)
downloadyuzu-3728bbc22a9224ff75fff22487a47bcaaf6ac2be.tar.gz
yuzu-3728bbc22a9224ff75fff22487a47bcaaf6ac2be.tar.xz
yuzu-3728bbc22a9224ff75fff22487a47bcaaf6ac2be.zip
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.h120
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 @@
1// Copyright 2019 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 <memory>
8#include <variant>
9
10#include "video_core/engines/shader_bytecode.h"
11
12namespace VideoCommon::Shader {
13
14using Tegra::Shader::ConditionCode;
15using Tegra::Shader::Pred;
16
17class ExprAnd;
18class ExprOr;
19class ExprNot;
20class ExprPredicate;
21class ExprCondCode;
22class ExprVar;
23class ExprBoolean;
24
25using ExprData =
26 std::variant<ExprVar, ExprCondCode, ExprPredicate, ExprNot, ExprOr, ExprAnd, ExprBoolean>;
27using Expr = std::shared_ptr<ExprData>;
28
29class ExprAnd final {
30public:
31 explicit ExprAnd(Expr a, Expr b) : operand1{a}, operand2{b} {}
32
33 bool operator==(const ExprAnd& b) const;
34
35 Expr operand1;
36 Expr operand2;
37};
38
39class ExprOr final {
40public:
41 explicit ExprOr(Expr a, Expr b) : operand1{a}, operand2{b} {}
42
43 bool operator==(const ExprOr& b) const;
44
45 Expr operand1;
46 Expr operand2;
47};
48
49class ExprNot final {
50public:
51 explicit ExprNot(Expr a) : operand1{a} {}
52
53 bool operator==(const ExprNot& b) const;
54
55 Expr operand1;
56};
57
58class ExprVar final {
59public:
60 explicit ExprVar(u32 index) : var_index{index} {}
61
62 bool operator==(const ExprVar& b) const {
63 return var_index == b.var_index;
64 }
65
66 u32 var_index;
67};
68
69class ExprPredicate final {
70public:
71 explicit ExprPredicate(u32 predicate) : predicate{predicate} {}
72
73 bool operator==(const ExprPredicate& b) const {
74 return predicate == b.predicate;
75 }
76
77 u32 predicate;
78};
79
80class ExprCondCode final {
81public:
82 explicit ExprCondCode(ConditionCode cc) : cc{cc} {}
83
84 bool operator==(const ExprCondCode& b) const {
85 return cc == b.cc;
86 }
87
88 ConditionCode cc;
89};
90
91class ExprBoolean final {
92public:
93 explicit ExprBoolean(bool val) : value{val} {}
94
95 bool operator==(const ExprBoolean& b) const {
96 return value == b.value;
97 }
98
99 bool value;
100};
101
102template <typename T, typename... Args>
103Expr MakeExpr(Args&&... args) {
104 static_assert(std::is_convertible_v<T, ExprData>);
105 return std::make_shared<ExprData>(T(std::forward<Args>(args)...));
106}
107
108bool ExprAreEqual(Expr first, Expr second);
109
110bool ExprAreOpposite(Expr first, Expr second);
111
112Expr MakeExprNot(Expr first);
113
114Expr MakeExprAnd(Expr first, Expr second);
115
116Expr MakeExprOr(Expr first, Expr second);
117
118bool ExprIsTrue(Expr first);
119
120} // namespace VideoCommon::Shader