From 220e421c22d9b413a0f19802883e4c211ce60f1e Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Fri, 22 Aug 2025 09:11:23 +0200 Subject: [PATCH 1/2] External: Add range-v3 submodule --- .gitmodules | 3 +++ CMakeLists.txt | 6 ++++++ External/range-v3 | 1 + 3 files changed, 10 insertions(+) create mode 160000 External/range-v3 diff --git a/.gitmodules b/.gitmodules index df920087b..35c6317dc 100644 --- a/.gitmodules +++ b/.gitmodules @@ -46,3 +46,6 @@ [submodule "External/tracy"] path = External/tracy url = https://github.com/wolfpld/tracy +[submodule "External/range-v3"] + path = External/range-v3 + url = https://github.com/ericniebler/range-v3.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f02e2a9a..94f2b8f85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,6 +354,12 @@ if (NOT fmt_FOUND) add_subdirectory(External/fmt/) endif() +find_package(range-v3 QUIET) +if (NOT range-v3_FOUND) + add_subdirectory(External/range-v3/) + target_compile_definitions(range-v3 INTERFACE RANGES_DISABLE_DEPRECATED_WARNINGS) +endif() + add_subdirectory(External/tiny-json/) include_directories(External/tiny-json/) diff --git a/External/range-v3 b/External/range-v3 new file mode 160000 index 000000000..ca1388fb9 --- /dev/null +++ b/External/range-v3 @@ -0,0 +1 @@ +Subproject commit ca1388fb9da8e69314dda222dc7b139ca84e092f From 16310c91c970197299f6afb6dbc309e35cae7e32 Mon Sep 17 00:00:00 2001 From: Tony Wasserka Date: Mon, 25 Aug 2025 08:45:21 +0200 Subject: [PATCH 2/2] VolatileMetadata: Clean up implementation using ranges::views::split --- Source/Common/CMakeLists.txt | 2 +- Source/Common/VolatileMetadata.cpp | 80 ++++++++++++------------------ 2 files changed, 33 insertions(+), 49 deletions(-) diff --git a/Source/Common/CMakeLists.txt b/Source/Common/CMakeLists.txt index 95cd7feb7..f76082be5 100644 --- a/Source/Common/CMakeLists.txt +++ b/Source/Common/CMakeLists.txt @@ -20,5 +20,5 @@ if (NOT MINGW_BUILD) endif() add_library(${NAME} STATIC ${SRCS}) -target_link_libraries(${NAME} FEXCore_Base cpp-optparse tiny-json FEXHeaderUtils) +target_link_libraries(${NAME} FEXCore_Base cpp-optparse tiny-json FEXHeaderUtils range-v3::range-v3) target_include_directories(${NAME} PRIVATE ${CMAKE_BINARY_DIR}/generated) diff --git a/Source/Common/VolatileMetadata.cpp b/Source/Common/VolatileMetadata.cpp index 90ace901f..d334e2ecf 100644 --- a/Source/Common/VolatileMetadata.cpp +++ b/Source/Common/VolatileMetadata.cpp @@ -1,6 +1,9 @@ // SPDX-License-Identifier: MIT #include "Common/VolatileMetadata.h" +#include +#include + namespace FEX::VolatileMetadata { fextl::unordered_map ParseExtendedVolatileMetadata(std::string_view ListOfDescriptors) { // Parsing: `;
-,;:` @@ -10,57 +13,44 @@ fextl::unordered_map ParseExtendedVolat fextl::unordered_map ExtendedMetaData {}; - auto current_module = ExtendedMetaData.end(); - - for (size_t module_offset = 0; module_offset != ListOfDescriptors.npos;) { - size_t end_of_module = ListOfDescriptors.find(":", module_offset); - std::string_view module_config = ListOfDescriptors.substr(module_offset, end_of_module - module_offset); - + auto to_string_view = [](auto rng) { + return std::string_view(&*rng.begin(), ranges::distance(rng)); + }; + for (auto module_config : ranges::views::split(ListOfDescriptors, ':') | ranges::views::transform(to_string_view)) { if (module_config.empty()) { - module_offset = end_of_module == ListOfDescriptors.npos ? ListOfDescriptors.npos : end_of_module + 1; continue; } - size_t end_of_name = module_config.find(";"); - size_t end_of_address_ranges = module_config.npos; - size_t end_of_individual_inst = module_config.npos; + auto sections = ranges::views::split(module_config, ';') | ranges::views::transform(to_string_view); + auto section = ranges::begin(sections); + const auto sections_end = ranges::end(sections); // Module name handling - { - std::string_view section_str = module_config.substr(0, end_of_name); - - if (section_str.empty()) { - module_offset = end_of_module == ListOfDescriptors.npos ? ListOfDescriptors.npos : end_of_module + 1; - continue; - } - - current_module = ExtendedMetaData - .insert_or_assign(fextl::string(section_str), - ExtendedVolatileMetadata { - .ModuleTSODisabled = true, - }) - .first; + std::string_view section_str = *section; + if (section_str.empty()) { + continue; } - // Address range handling - if (end_of_name != module_config.npos) { - end_of_address_ranges = module_config.find(";", end_of_name + 1); - std::string_view section_str = module_config.substr(end_of_name + 1, end_of_address_ranges - (end_of_name + 1)); + auto current_module = ExtendedMetaData + .insert_or_assign(fextl::string(section_str), + ExtendedVolatileMetadata { + .ModuleTSODisabled = true, + }) + .first; + ++section; + // Address range handling + if (section != sections_end) { + std::string_view section_str = *section; if (section_str.empty()) { - module_offset = end_of_module == ListOfDescriptors.npos ? ListOfDescriptors.npos : end_of_module + 1; continue; } current_module->second.ModuleTSODisabled = false; // Walk all the address ranges provided. - for (size_t non_tso_region_offset = 0; non_tso_region_offset != section_str.npos;) { - size_t end_of_region_substr = section_str.find(",", non_tso_region_offset); - std::string_view tso_region_view = section_str.substr(non_tso_region_offset, end_of_region_substr - non_tso_region_offset); - + for (auto tso_region_view : ranges::views::split(section_str, ',') | ranges::views::transform(to_string_view)) { if (tso_region_view.empty()) { - non_tso_region_offset = end_of_region_substr == section_str.npos ? section_str.npos : end_of_region_substr + 1; continue; } @@ -78,26 +68,20 @@ fextl::unordered_map ParseExtendedVolat LOGMAN_THROW_A_FMT(str_begin != str_end, "Couldn't parse end {}", tso_region_view); current_module->second.VolatileValidRanges.Insert({begin, end}); - non_tso_region_offset = end_of_region_substr == section_str.npos ? section_str.npos : end_of_region_substr + 1; } + + ++section; } // Individual instruction handling - if (end_of_address_ranges != module_config.npos) { - end_of_individual_inst = module_config.find(";", end_of_address_ranges + 1); - std::string_view section_str = module_config.substr(end_of_address_ranges + 1, end_of_individual_inst); - + if (section != sections_end) { + std::string_view section_str = *section; if (section_str.empty()) { - module_offset = end_of_module == ListOfDescriptors.npos ? ListOfDescriptors.npos : end_of_module + 1; continue; } - for (size_t force_tso_region_offset = 0; force_tso_region_offset != section_str.npos;) { - size_t end_of_region_substr = section_str.find(",", force_tso_region_offset); - std::string_view tso_region_view = section_str.substr(force_tso_region_offset, end_of_region_substr - force_tso_region_offset); - + for (auto tso_region_view : ranges::views::split(section_str, ',') | ranges::views::transform(to_string_view)) { if (tso_region_view.empty()) { - force_tso_region_offset = end_of_region_substr == section_str.npos ? section_str.npos : end_of_region_substr + 1; continue; } @@ -107,12 +91,12 @@ fextl::unordered_map ParseExtendedVolat LOGMAN_THROW_A_FMT(tso_region_view.data() != str_end, "Couldn't parse offset {}", tso_region_view); current_module->second.VolatileInstructions.insert(offset); - - force_tso_region_offset = end_of_region_substr == section_str.npos ? section_str.npos : end_of_region_substr + 1; } + + ++section; } - module_offset = end_of_module == ListOfDescriptors.npos ? ListOfDescriptors.npos : end_of_module + 1; + LOGMAN_THROW_A_FMT(section == sections_end, "Expected ':' or end of input, got {}", *section); } return ExtendedMetaData;