summaryrefslogtreecommitdiff
path: root/src/shader_recompiler/frontend/ir/opcodes.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/shader_recompiler/frontend/ir/opcodes.h')
-rw-r--r--src/shader_recompiler/frontend/ir/opcodes.h14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/shader_recompiler/frontend/ir/opcodes.h b/src/shader_recompiler/frontend/ir/opcodes.h
index b5697c7f9..2b9c0ed8c 100644
--- a/src/shader_recompiler/frontend/ir/opcodes.h
+++ b/src/shader_recompiler/frontend/ir/opcodes.h
@@ -4,8 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
8#include <algorithm> 7#include <algorithm>
8#include <array>
9#include <string_view> 9#include <string_view>
10 10
11#include <fmt/format.h> 11#include <fmt/format.h>
@@ -21,7 +21,6 @@ enum class Opcode {
21}; 21};
22 22
23namespace Detail { 23namespace Detail {
24
25struct OpcodeMeta { 24struct OpcodeMeta {
26 std::string_view name; 25 std::string_view name;
27 Type type; 26 Type type;
@@ -57,9 +56,9 @@ constexpr Type F64x2{Type::F64x2};
57constexpr Type F64x3{Type::F64x3}; 56constexpr Type F64x3{Type::F64x3};
58constexpr Type F64x4{Type::F64x4}; 57constexpr Type F64x4{Type::F64x4};
59 58
60constexpr std::array META_TABLE{ 59constexpr OpcodeMeta META_TABLE[]{
61#define OPCODE(name_token, type_token, ...) \ 60#define OPCODE(name_token, type_token, ...) \
62 OpcodeMeta{ \ 61 { \
63 .name{#name_token}, \ 62 .name{#name_token}, \
64 .type = type_token, \ 63 .type = type_token, \
65 .arg_types{__VA_ARGS__}, \ 64 .arg_types{__VA_ARGS__}, \
@@ -67,14 +66,13 @@ constexpr std::array META_TABLE{
67#include "opcodes.inc" 66#include "opcodes.inc"
68#undef OPCODE 67#undef OPCODE
69}; 68};
70
71constexpr size_t CalculateNumArgsOf(Opcode op) { 69constexpr size_t CalculateNumArgsOf(Opcode op) {
72 const auto& arg_types{META_TABLE[static_cast<size_t>(op)].arg_types}; 70 const auto& arg_types{META_TABLE[static_cast<size_t>(op)].arg_types};
73 return std::distance(arg_types.begin(), std::ranges::find(arg_types, Type::Void)); 71 return std::distance(arg_types.begin(), std::ranges::find(arg_types, Type::Void));
74} 72}
75 73
76constexpr std::array NUM_ARGS{ 74constexpr u8 NUM_ARGS[]{
77#define OPCODE(name_token, type_token, ...) CalculateNumArgsOf(Opcode::name_token), 75#define OPCODE(name_token, type_token, ...) static_cast<u8>(CalculateNumArgsOf(Opcode::name_token)),
78#include "opcodes.inc" 76#include "opcodes.inc"
79#undef OPCODE 77#undef OPCODE
80}; 78};
@@ -87,7 +85,7 @@ constexpr std::array NUM_ARGS{
87 85
88/// Get the number of arguments an opcode accepts 86/// Get the number of arguments an opcode accepts
89[[nodiscard]] inline size_t NumArgsOf(Opcode op) noexcept { 87[[nodiscard]] inline size_t NumArgsOf(Opcode op) noexcept {
90 return Detail::NUM_ARGS[static_cast<size_t>(op)]; 88 return static_cast<size_t>(Detail::NUM_ARGS[static_cast<size_t>(op)]);
91} 89}
92 90
93/// Get the required type of an argument of an opcode 91/// Get the required type of an argument of an opcode