#ifndef EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_DECOMPILER_OPCODETABLE_H_ #define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_DECOMPILER_OPCODETABLE_H_ #include "graphics/shader/recompiler/frontend/decode/ShaderDecoder.h" #include #include #include namespace Libs::Graphics::ShaderRecompiler::Decoder::Detail { struct OpcodeMap { uint32_t encoding = 0; Opcode decoded = Opcode::Unknown; }; template struct OpcodeTable { std::array entries = {}; std::array indices = {}; }; template consteval auto MakeOpcodeTable(const Entry (&entries)[EntryCount]) { static_assert(EntryCount < UINT16_MAX); OpcodeTable table; for (size_t i = 0; i < EntryCount; i++) { const auto encoding = entries[i].encoding; if (encoding >= EncodingCount || table.indices[encoding] != 0) { throw "invalid opcode table"; } table.entries[i] = entries[i]; table.indices[encoding] = static_cast(i + 1); } return table; } template constexpr const Entry* FindOpcode(const OpcodeTable& table, uint32_t encoding) { if (table.indices[encoding] == 0) { return nullptr; } return &table.entries[table.indices[encoding] - 1]; } template constexpr Opcode LookupOpcode(const OpcodeTable& table, uint32_t encoding) { const auto* entry = FindOpcode(table, encoding); return entry != nullptr ? entry->decoded : Opcode::Unsupported; } } // namespace Libs::Graphics::ShaderRecompiler::Decoder::Detail #endif // EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_DECOMPILER_OPCODETABLE_H_