From bf422a190a26bdc058867b314c7c241566b689cf Mon Sep 17 00:00:00 2001 From: Merry Date: Sun, 21 Aug 2022 17:50:10 +0100 Subject: [PATCH] decoder_detail: Simplify DYNARMIC_DECODER_GET_MATCHER --- .../frontend/decoder/decoder_detail.h | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/dynarmic/frontend/decoder/decoder_detail.h b/src/dynarmic/frontend/decoder/decoder_detail.h index 55d745c7..ae5062b5 100644 --- a/src/dynarmic/frontend/decoder/decoder_detail.h +++ b/src/dynarmic/frontend/decoder/decoder_detail.h @@ -17,7 +17,7 @@ namespace Dynarmic::Decoder { namespace detail { template -inline constexpr std::array StringToArray(const char (&str)[N + 1]) { +inline consteval std::array StringToArray(const char (&str)[N + 1]) { std::array result{}; for (size_t i = 0; i < N; i++) { result[i] = str[i]; @@ -42,7 +42,11 @@ struct detail { * A '0' in a bitstring indicates that a zero must be present at that bit position. * A '1' in a bitstring indicates that a one must be present at that bit position. */ +#ifdef __APPLE__ // AppleClang workaround static constexpr auto GetMaskAndExpect(std::array bitstring) { +#else + static consteval auto GetMaskAndExpect(std::array bitstring) { +#endif const auto one = static_cast(1); opcode_type mask = 0, expect = 0; for (size_t i = 0; i < opcode_bitsize; i++) { @@ -69,7 +73,7 @@ struct detail { * An argument is specified by a continuous string of the same character. */ template - static constexpr auto GetArgInfo(std::array bitstring) { + static consteval auto GetArgInfo(std::array bitstring) { std::array masks = {}; std::array shifts = {}; size_t arg_index = 0; @@ -164,19 +168,23 @@ struct detail { * Creates a matcher that can match and parse instructions based on bitstring. * See also: GetMaskAndExpect and GetArgInfo for format of bitstring. */ - template> - static auto GetMatcher(FnT fn, const char* const name, std::tuple mask_and_expect, std::tuple, std::array> masks_and_shifts) { + template + static auto GetMatcher(FnT fn, const char* const name) { + constexpr size_t args_count = mcl::parameter_count_v; + + constexpr auto mask = std::get<0>(GetMaskAndExpect(bitstring)); + constexpr auto expect = std::get<1>(GetMaskAndExpect(bitstring)); + constexpr auto arg_masks = std::get<0>(GetArgInfo(bitstring)); + constexpr auto arg_shifts = std::get<1>(GetArgInfo(bitstring)); + using Iota = std::make_index_sequence; - const auto [mask, expect] = mask_and_expect; - const auto [arg_masks, arg_shifts] = masks_and_shifts; const auto proxy_fn = VisitorCaller::Make(Iota(), fn, arg_masks, arg_shifts); - return MatcherT(name, mask, expect, proxy_fn); } }; -#define DYNARMIC_DECODER_GET_MATCHER(MatcherT, fn, name, bitstring) Decoder::detail::detail>::GetMatcher(&V::fn, name, Decoder::detail::detail>::GetMaskAndExpect(bitstring), Decoder::detail::detail>::template GetArgInfo>(bitstring)) +#define DYNARMIC_DECODER_GET_MATCHER(MatcherT, fn, name, bitstring) Decoder::detail::detail>::template GetMatcher(&V::fn, name) } // namespace detail } // namespace Dynarmic::Decoder