diff options
Diffstat (limited to 'src/shader_recompiler/frontend/ir/value.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/value.cpp | 124 |
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 | |||
| 9 | namespace Shader::IR { | ||
| 10 | |||
| 11 | Value::Value(IR::Inst* value) noexcept : type{Type::Opaque}, inst{value} {} | ||
| 12 | |||
| 13 | Value::Value(IR::Block* value) noexcept : type{Type::Label}, label{value} {} | ||
| 14 | |||
| 15 | Value::Value(IR::Reg value) noexcept : type{Type::Reg}, reg{value} {} | ||
| 16 | |||
| 17 | Value::Value(IR::Pred value) noexcept : type{Type::Pred}, pred{value} {} | ||
| 18 | |||
| 19 | Value::Value(IR::Attribute value) noexcept : type{Type::Attribute}, attribute{value} {} | ||
| 20 | |||
| 21 | Value::Value(bool value) noexcept : type{Type::U1}, imm_u1{value} {} | ||
| 22 | |||
| 23 | Value::Value(u8 value) noexcept : type{Type::U8}, imm_u8{value} {} | ||
| 24 | |||
| 25 | Value::Value(u16 value) noexcept : type{Type::U16}, imm_u16{value} {} | ||
| 26 | |||
| 27 | Value::Value(u32 value) noexcept : type{Type::U32}, imm_u32{value} {} | ||
| 28 | |||
| 29 | Value::Value(u64 value) noexcept : type{Type::U64}, imm_u64{value} {} | ||
| 30 | |||
| 31 | bool Value::IsIdentity() const noexcept { | ||
| 32 | return type == Type::Opaque && inst->Opcode() == Opcode::Identity; | ||
| 33 | } | ||
| 34 | |||
| 35 | bool Value::IsEmpty() const noexcept { | ||
| 36 | return type == Type::Void; | ||
| 37 | } | ||
| 38 | |||
| 39 | bool Value::IsImmediate() const noexcept { | ||
| 40 | if (IsIdentity()) { | ||
| 41 | return inst->Arg(0).IsImmediate(); | ||
| 42 | } | ||
| 43 | return type != Type::Opaque; | ||
| 44 | } | ||
| 45 | |||
| 46 | bool Value::IsLabel() const noexcept { | ||
| 47 | return type == Type::Label; | ||
| 48 | } | ||
| 49 | |||
| 50 | IR::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 | |||
| 60 | IR::Inst* Value::Inst() const { | ||
| 61 | ValidateAccess(Type::Opaque); | ||
| 62 | return inst; | ||
| 63 | } | ||
| 64 | |||
| 65 | IR::Block* Value::Label() const { | ||
| 66 | ValidateAccess(Type::Label); | ||
| 67 | return label; | ||
| 68 | } | ||
| 69 | |||
| 70 | IR::Inst* Value::InstRecursive() const { | ||
| 71 | ValidateAccess(Type::Opaque); | ||
| 72 | if (IsIdentity()) { | ||
| 73 | return inst->Arg(0).InstRecursive(); | ||
| 74 | } | ||
| 75 | return inst; | ||
| 76 | } | ||
| 77 | |||
| 78 | IR::Reg Value::Reg() const { | ||
| 79 | ValidateAccess(Type::Reg); | ||
| 80 | return reg; | ||
| 81 | } | ||
| 82 | |||
| 83 | IR::Pred Value::Pred() const { | ||
| 84 | ValidateAccess(Type::Pred); | ||
| 85 | return pred; | ||
| 86 | } | ||
| 87 | |||
| 88 | IR::Attribute Value::Attribute() const { | ||
| 89 | ValidateAccess(Type::Attribute); | ||
| 90 | return attribute; | ||
| 91 | } | ||
| 92 | |||
| 93 | bool Value::U1() const { | ||
| 94 | ValidateAccess(Type::U1); | ||
| 95 | return imm_u1; | ||
| 96 | } | ||
| 97 | |||
| 98 | u8 Value::U8() const { | ||
| 99 | ValidateAccess(Type::U8); | ||
| 100 | return imm_u8; | ||
| 101 | } | ||
| 102 | |||
| 103 | u16 Value::U16() const { | ||
| 104 | ValidateAccess(Type::U16); | ||
| 105 | return imm_u16; | ||
| 106 | } | ||
| 107 | |||
| 108 | u32 Value::U32() const { | ||
| 109 | ValidateAccess(Type::U32); | ||
| 110 | return imm_u32; | ||
| 111 | } | ||
| 112 | |||
| 113 | u64 Value::U64() const { | ||
| 114 | ValidateAccess(Type::U64); | ||
| 115 | return imm_u64; | ||
| 116 | } | ||
| 117 | |||
| 118 | void 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 | ||