diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/shader_recompiler/frontend/ir/opcodes.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/shader_recompiler/frontend/ir/opcodes.cpp b/src/shader_recompiler/frontend/ir/opcodes.cpp index 7f04b647b..4207d548c 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.cpp +++ b/src/shader_recompiler/frontend/ir/opcodes.cpp | |||
| @@ -57,6 +57,17 @@ constexpr std::array META_TABLE{ | |||
| 57 | #undef OPCODE | 57 | #undef OPCODE |
| 58 | }; | 58 | }; |
| 59 | 59 | ||
| 60 | constexpr size_t CalculateNumArgsOf(Opcode op) { | ||
| 61 | const auto& arg_types{META_TABLE[static_cast<size_t>(op)].arg_types}; | ||
| 62 | return std::distance(arg_types.begin(), std::ranges::find(arg_types, Type::Void)); | ||
| 63 | } | ||
| 64 | |||
| 65 | constexpr std::array NUM_ARGS{ | ||
| 66 | #define OPCODE(name_token, type_token, ...) CalculateNumArgsOf(Opcode::name_token), | ||
| 67 | #include "opcodes.inc" | ||
| 68 | #undef OPCODE | ||
| 69 | }; | ||
| 70 | |||
| 60 | void ValidateOpcode(Opcode op) { | 71 | void ValidateOpcode(Opcode op) { |
| 61 | const size_t raw{static_cast<size_t>(op)}; | 72 | const size_t raw{static_cast<size_t>(op)}; |
| 62 | if (raw >= META_TABLE.size()) { | 73 | if (raw >= META_TABLE.size()) { |
| @@ -72,9 +83,7 @@ Type TypeOf(Opcode op) { | |||
| 72 | 83 | ||
| 73 | size_t NumArgsOf(Opcode op) { | 84 | size_t NumArgsOf(Opcode op) { |
| 74 | ValidateOpcode(op); | 85 | ValidateOpcode(op); |
| 75 | const auto& arg_types{META_TABLE[static_cast<size_t>(op)].arg_types}; | 86 | return NUM_ARGS[static_cast<size_t>(op)]; |
| 76 | const auto distance{std::distance(arg_types.begin(), std::ranges::find(arg_types, Type::Void))}; | ||
| 77 | return static_cast<size_t>(distance); | ||
| 78 | } | 87 | } |
| 79 | 88 | ||
| 80 | Type ArgTypeOf(Opcode op, size_t arg_index) { | 89 | Type ArgTypeOf(Opcode op, size_t arg_index) { |