summaryrefslogtreecommitdiff
path: root/src/video_core/shader/expr.cpp
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.cpp
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.cpp')
-rw-r--r--src/video_core/shader/expr.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/video_core/shader/expr.cpp b/src/video_core/shader/expr.cpp
new file mode 100644
index 000000000..ca633ffb1
--- /dev/null
+++ b/src/video_core/shader/expr.cpp
@@ -0,0 +1,82 @@
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/shader/expr.h"
11
12namespace VideoCommon::Shader {
13
14bool ExprAnd::operator==(const ExprAnd& b) const {
15 return (*operand1 == *b.operand1) && (*operand2 == *b.operand2);
16}
17
18bool ExprOr::operator==(const ExprOr& b) const {
19 return (*operand1 == *b.operand1) && (*operand2 == *b.operand2);
20}
21
22bool ExprNot::operator==(const ExprNot& b) const {
23 return (*operand1 == *b.operand1);
24}
25
26bool ExprIsBoolean(Expr expr) {
27 return std::holds_alternative<ExprBoolean>(*expr);
28}
29
30bool ExprBooleanGet(Expr expr) {
31 return std::get_if<ExprBoolean>(expr.get())->value;
32}
33
34Expr MakeExprNot(Expr first) {
35 if (std::holds_alternative<ExprNot>(*first)) {
36 return std::get_if<ExprNot>(first.get())->operand1;
37 }
38 return MakeExpr<ExprNot>(first);
39}
40
41Expr MakeExprAnd(Expr first, Expr second) {
42 if (ExprIsBoolean(first)) {
43 return ExprBooleanGet(first) ? second : first;
44 }
45 if (ExprIsBoolean(second)) {
46 return ExprBooleanGet(second) ? first : second;
47 }
48 return MakeExpr<ExprAnd>(first, second);
49}
50
51Expr MakeExprOr(Expr first, Expr second) {
52 if (ExprIsBoolean(first)) {
53 return ExprBooleanGet(first) ? first : second;
54 }
55 if (ExprIsBoolean(second)) {
56 return ExprBooleanGet(second) ? second : first;
57 }
58 return MakeExpr<ExprOr>(first, second);
59}
60
61bool ExprAreEqual(Expr first, Expr second) {
62 return (*first) == (*second);
63}
64
65bool ExprAreOpposite(Expr first, Expr second) {
66 if (std::holds_alternative<ExprNot>(*first)) {
67 return ExprAreEqual(std::get_if<ExprNot>(first.get())->operand1, second);
68 }
69 if (std::holds_alternative<ExprNot>(*second)) {
70 return ExprAreEqual(std::get_if<ExprNot>(second.get())->operand1, first);
71 }
72 return false;
73}
74
75bool ExprIsTrue(Expr first) {
76 if (ExprIsBoolean(first)) {
77 return ExprBooleanGet(first);
78 }
79 return false;
80}
81
82} // namespace VideoCommon::Shader