mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 09:00:17 +02:00
Merge pull request #4799 from neobrain/refactor_ranges
VolatileMetadata: Clean up implementation using ranges::views::split
This commit is contained in:
5 files changed
+43
-49
No files matched your search
@@ -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
|
||||
@@ -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/)
|
||||
|
||||
|
||||
+1
Submodule External/range-v3 added at ca1388fb9d.
@@ -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)
|
||||
@@ -1,6 +1,9 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "Common/VolatileMetadata.h"
|
||||
|
||||
#include <range/v3/view/split.hpp>
|
||||
#include <range/v3/view/transform.hpp>
|
||||
|
||||
namespace FEX::VolatileMetadata {
|
||||
fextl::unordered_map<fextl::string, ExtendedVolatileMetadata> ParseExtendedVolatileMetadata(std::string_view ListOfDescriptors) {
|
||||
// Parsing: `<module>;<address begin>-<address-end>,<more addresses>;<instruction offset to force TSO>:`
|
||||
@@ -10,57 +13,44 @@ fextl::unordered_map<fextl::string, ExtendedVolatileMetadata> ParseExtendedVolat
|
||||
|
||||
fextl::unordered_map<fextl::string, ExtendedVolatileMetadata> 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<fextl::string, ExtendedVolatileMetadata> 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<fextl::string, ExtendedVolatileMetadata> 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;
|
||||
|
||||
Reference in new issue
Block a user