diff options
Diffstat (limited to 'src/shader_recompiler/frontend/maxwell/translate/translate.cpp')
| -rw-r--r-- | src/shader_recompiler/frontend/maxwell/translate/translate.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/shader_recompiler/frontend/maxwell/translate/translate.cpp b/src/shader_recompiler/frontend/maxwell/translate/translate.cpp new file mode 100644 index 000000000..8e3c4c5d5 --- /dev/null +++ b/src/shader_recompiler/frontend/maxwell/translate/translate.cpp | |||
| @@ -0,0 +1,52 @@ | |||
| 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/environment.h" | ||
| 6 | #include "shader_recompiler/frontend/ir/basic_block.h" | ||
| 7 | #include "shader_recompiler/frontend/maxwell/decode.h" | ||
| 8 | #include "shader_recompiler/frontend/maxwell/location.h" | ||
| 9 | #include "shader_recompiler/frontend/maxwell/translate/impl/impl.h" | ||
| 10 | #include "shader_recompiler/frontend/maxwell/translate/translate.h" | ||
| 11 | |||
| 12 | namespace Shader::Maxwell { | ||
| 13 | |||
| 14 | template <auto method> | ||
| 15 | static void Invoke(TranslatorVisitor& visitor, Location pc, u64 insn) { | ||
| 16 | using MethodType = decltype(method); | ||
| 17 | if constexpr (std::is_invocable_r_v<void, MethodType, TranslatorVisitor&, Location, u64>) { | ||
| 18 | (visitor.*method)(pc, insn); | ||
| 19 | } else if constexpr (std::is_invocable_r_v<void, MethodType, TranslatorVisitor&, u64>) { | ||
| 20 | (visitor.*method)(insn); | ||
| 21 | } else { | ||
| 22 | (visitor.*method)(); | ||
| 23 | } | ||
| 24 | } | ||
| 25 | |||
| 26 | void Translate(Environment& env, IR::Block* block, u32 location_begin, u32 location_end) { | ||
| 27 | if (location_begin == location_end) { | ||
| 28 | return; | ||
| 29 | } | ||
| 30 | TranslatorVisitor visitor{env, *block}; | ||
| 31 | for (Location pc = location_begin; pc != location_end; ++pc) { | ||
| 32 | const u64 insn{env.ReadInstruction(pc.Offset())}; | ||
| 33 | try { | ||
| 34 | const Opcode opcode{Decode(insn)}; | ||
| 35 | switch (opcode) { | ||
| 36 | #define INST(name, cute, mask) \ | ||
| 37 | case Opcode::name: \ | ||
| 38 | Invoke<&TranslatorVisitor::name>(visitor, pc, insn); \ | ||
| 39 | break; | ||
| 40 | #include "shader_recompiler/frontend/maxwell/maxwell.inc" | ||
| 41 | #undef OPCODE | ||
| 42 | default: | ||
| 43 | throw LogicError("Invalid opcode {}", opcode); | ||
| 44 | } | ||
| 45 | } catch (Exception& exception) { | ||
| 46 | exception.Prepend(fmt::format("Translate {}: ", Decode(insn))); | ||
| 47 | throw; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | } // namespace Shader::Maxwell | ||