summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/value.cpp
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2021-01-09 03:30:07 -0300
committerGravatar ameerj2021-07-22 21:51:21 -0400
commit2d48a7b4d0666ad16d03a22d85712617a0849046 (patch)
treedd1069afca86f66e77e3438da77421a43adf5091 /src/shader_recompiler/frontend/ir/value.cpp
parentthread_worker: Fix compile time error (diff)
downloadyuzu-2d48a7b4d0666ad16d03a22d85712617a0849046.tar.gz
yuzu-2d48a7b4d0666ad16d03a22d85712617a0849046.tar.xz
yuzu-2d48a7b4d0666ad16d03a22d85712617a0849046.zip
shader: Initial recompiler work
Diffstat (limited to 'src/shader_recompiler/frontend/ir/value.cpp')
-rw-r--r--src/shader_recompiler/frontend/ir/value.cpp124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/value.cpp b/src/shader_recompiler/frontend/ir/value.cpp
new file mode 100644
index 000000000..7b5b35d6c
--- /dev/null
+++ b/src/shader_recompiler/frontend/ir/value.cpp
@@ -0,0 +1,124 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include "shader_recompiler/frontend/ir/microinstruction.h"
6#include "shader_recompiler/frontend/ir/opcode.h"
7#include "shader_recompiler/frontend/ir/value.h"
8
9namespace Shader::IR {
10
11Value::Value(IR::Inst* value) noexcept : type{Type::Opaque}, inst{value} {}
12
13Value::Value(IR::Block* value) noexcept : type{Type::Label}, label{value} {}
14
15Value::Value(IR::Reg value) noexcept : type{Type::Reg}, reg{value} {}
16
17Value::Value(IR::Pred value) noexcept : type{Type::Pred}, pred{value} {}
18
19Value::Value(IR::Attribute value) noexcept : type{Type::Attribute}, attribute{value} {}
20
21Value::Value(bool value) noexcept : type{Type::U1}, imm_u1{value} {}
22
23Value::Value(u8 value) noexcept : type{Type::U8}, imm_u8{value} {}
24
25Value::Value(u16 value) noexcept : type{Type::U16}, imm_u16{value} {}
26
27Value::Value(u32 value) noexcept : type{Type::U32}, imm_u32{value} {}
28
29Value::Value(u64 value) noexcept : type{Type::U64}, imm_u64{value} {}
30
31bool Value::IsIdentity() const noexcept {
32 return type == Type::Opaque && inst->Opcode() == Opcode::Identity;
33}
34
35bool Value::IsEmpty() const noexcept {
36 return type == Type::Void;
37}
38
39bool Value::IsImmediate() const noexcept {
40 if (IsIdentity()) {
41 return inst->Arg(0).IsImmediate();
42 }
43 return type != Type::Opaque;
44}
45
46bool Value::IsLabel() const noexcept {
47 return type == Type::Label;
48}
49
50IR::Type Value::Type() const noexcept {
51 if (IsIdentity()) {
52 return inst->Arg(0).Type();
53 }
54 if (type == Type::Opaque) {
55 return inst->Type();
56 }
57 return type;
58}
59
60IR::Inst* Value::Inst() const {
61 ValidateAccess(Type::Opaque);
62 return inst;
63}
64
65IR::Block* Value::Label() const {
66 ValidateAccess(Type::Label);
67 return label;
68}
69
70IR::Inst* Value::InstRecursive() const {
71 ValidateAccess(Type::Opaque);
72 if (IsIdentity()) {
73 return inst->Arg(0).InstRecursive();
74 }
75 return inst;
76}
77
78IR::Reg Value::Reg() const {
79 ValidateAccess(Type::Reg);
80 return reg;
81}
82
83IR::Pred Value::Pred() const {
84 ValidateAccess(Type::Pred);
85 return pred;
86}
87
88IR::Attribute Value::Attribute() const {
89 ValidateAccess(Type::Attribute);
90 return attribute;
91}
92
93bool Value::U1() const {
94 ValidateAccess(Type::U1);
95 return imm_u1;
96}
97
98u8 Value::U8() const {
99 ValidateAccess(Type::U8);
100 return imm_u8;
101}
102
103u16 Value::U16() const {
104 ValidateAccess(Type::U16);
105 return imm_u16;
106}
107
108u32 Value::U32() const {
109 ValidateAccess(Type::U32);
110 return imm_u32;
111}
112
113u64 Value::U64() const {
114 ValidateAccess(Type::U64);
115 return imm_u64;
116}
117
118void Value::ValidateAccess(IR::Type expected) const {
119 if (type != expected) {
120 throw LogicError("Reading {} out of {}", expected, type);
121 }
122}
123
124} // namespace Shader::IR