diff options
| author | 2021-02-05 23:11:23 -0300 | |
|---|---|---|
| committer | 2021-07-22 21:51:21 -0400 | |
| commit | 16cb00c521cae6e93ec49d10e15b575b7bc4857e (patch) | |
| tree | 3b283895510af56fced7e62031c6beda999c0a1c /src/shader_recompiler/frontend/ir/opcodes.cpp | |
| parent | shader: Make typed IR (diff) | |
| download | yuzu-16cb00c521cae6e93ec49d10e15b575b7bc4857e.tar.gz yuzu-16cb00c521cae6e93ec49d10e15b575b7bc4857e.tar.xz yuzu-16cb00c521cae6e93ec49d10e15b575b7bc4857e.zip | |
shader: Add pools and rename files
Diffstat (limited to 'src/shader_recompiler/frontend/ir/opcodes.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/opcodes.cpp | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/ir/opcodes.cpp b/src/shader_recompiler/frontend/ir/opcodes.cpp new file mode 100644 index 000000000..1f188411a --- /dev/null +++ b/src/shader_recompiler/frontend/ir/opcodes.cpp | |||
| @@ -0,0 +1,67 @@ | |||
| 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 <algorithm> | ||
| 6 | #include <array> | ||
| 7 | #include <string_view> | ||
| 8 | |||
| 9 | #include "shader_recompiler/exception.h" | ||
| 10 | #include "shader_recompiler/frontend/ir/opcodes.h" | ||
| 11 | |||
| 12 | namespace Shader::IR { | ||
| 13 | namespace { | ||
| 14 | struct OpcodeMeta { | ||
| 15 | std::string_view name; | ||
| 16 | Type type; | ||
| 17 | std::array<Type, 4> arg_types; | ||
| 18 | }; | ||
| 19 | |||
| 20 | using enum Type; | ||
| 21 | |||
| 22 | constexpr std::array META_TABLE{ | ||
| 23 | #define OPCODE(name_token, type_token, ...) \ | ||
| 24 | OpcodeMeta{ \ | ||
| 25 | .name{#name_token}, \ | ||
| 26 | .type{type_token}, \ | ||
| 27 | .arg_types{__VA_ARGS__}, \ | ||
| 28 | }, | ||
| 29 | #include "opcodes.inc" | ||
| 30 | #undef OPCODE | ||
| 31 | }; | ||
| 32 | |||
| 33 | void ValidateOpcode(Opcode op) { | ||
| 34 | const size_t raw{static_cast<size_t>(op)}; | ||
| 35 | if (raw >= META_TABLE.size()) { | ||
| 36 | throw InvalidArgument("Invalid opcode with raw value {}", raw); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | } // Anonymous namespace | ||
| 40 | |||
| 41 | Type TypeOf(Opcode op) { | ||
| 42 | ValidateOpcode(op); | ||
| 43 | return META_TABLE[static_cast<size_t>(op)].type; | ||
| 44 | } | ||
| 45 | |||
| 46 | size_t NumArgsOf(Opcode op) { | ||
| 47 | ValidateOpcode(op); | ||
| 48 | const auto& arg_types{META_TABLE[static_cast<size_t>(op)].arg_types}; | ||
| 49 | const auto distance{std::distance(arg_types.begin(), std::ranges::find(arg_types, Type::Void))}; | ||
| 50 | return static_cast<size_t>(distance); | ||
| 51 | } | ||
| 52 | |||
| 53 | Type ArgTypeOf(Opcode op, size_t arg_index) { | ||
| 54 | ValidateOpcode(op); | ||
| 55 | const auto& arg_types{META_TABLE[static_cast<size_t>(op)].arg_types}; | ||
| 56 | if (arg_index >= arg_types.size() || arg_types[arg_index] == Type::Void) { | ||
| 57 | throw InvalidArgument("Out of bounds argument"); | ||
| 58 | } | ||
| 59 | return arg_types[arg_index]; | ||
| 60 | } | ||
| 61 | |||
| 62 | std::string_view NameOf(Opcode op) { | ||
| 63 | ValidateOpcode(op); | ||
| 64 | return META_TABLE[static_cast<size_t>(op)].name; | ||
| 65 | } | ||
| 66 | |||
| 67 | } // namespace Shader::IR | ||