improved StringUtil algo + some PhysicalMemory work

This commit is contained in:
georgemoralis 2023-08-01 00:42:49 +03:00
parent 818e0b7404
commit 692759099f
6 changed files with 42 additions and 21 deletions

View File

@ -34,7 +34,7 @@ add_executable(shadps4
src/Core/Memory.h
src/Core/PS4/Linker.cpp
src/Core/PS4/Linker.h
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/Debug.h" "src/Core/PS4/HLE/Kernel/MemoryManagement.cpp" "src/Core/PS4/HLE/Kernel/MemoryManagement.h" "src/Core/PS4/HLE/Kernel/MemMngCodes.h")
"src/Util/Singleton.h" "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/Util/StringUtil.h" "src/Core/PS4/Util/aerolib.h" "src/Core/PS4/Loader/SymbolsResolver.h" "src/Core/PS4/Loader/SymbolsResolver.cpp" "src/Core/PS4/HLE/Libs.cpp" "src/Core/PS4/HLE/Libs.h" "src/Core/PS4/HLE/LibC.cpp" "src/Core/PS4/HLE/LibC.h" "src/Lib/Timer.cpp" "src/Lib/Timer.h" "src/Core/PS4/HLE/LibKernel.cpp" "src/Core/PS4/HLE/LibKernel.h" "src/Core/PS4/HLE/LibSceVideoOut.cpp" "src/Core/PS4/HLE/LibSceVideoOut.h" "src/Core/PS4/HLE/LibSceGnmDriver.cpp" "src/Core/PS4/HLE/LibSceGnmDriver.h" "src/Core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/Core/PS4/HLE/Kernel/ThreadManagement.h" "src/Core/PS4/HLE/ErrorCodes.h" "src/Debug.h" "src/Core/PS4/HLE/Kernel/MemoryManagement.cpp" "src/Core/PS4/HLE/Kernel/MemoryManagement.h" "src/Core/PS4/HLE/Kernel/MemMngCodes.h" "src/Core/PS4/HLE/Kernel/PhysicalMemory.cpp" "src/Util/StringUtil.cpp")
find_package(OpenGL REQUIRED)
target_link_libraries(shadps4 PUBLIC fmt spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY})

View File

@ -0,0 +1,15 @@
#pragma once
namespace HLE::Libs::LibKernel::MemoryManagement {
class PysicalMemory {
struct AllocatedBlock {
u64 start_addr;
u64 size;
};
private:
std::vector<AllocatedBlock> m_allocatedBlocks;
};
} // namespace HLE::Libs::LibKernel::MemoryManagement

View File

@ -427,7 +427,7 @@ void Linker::LoadSymbols(Module* m)
sym++)
{
std::string id = std::string(m->dynamic_info->str_table + sym->st_name);
auto ids = StringUtil::split(id, '#');
auto ids = StringUtil::split_string(id, '#');
if (ids.size() == 3)//symbols are 3 parts name , library , module
{
const auto* library = FindLibrary(*m, ids.at(1));
@ -590,7 +590,7 @@ void Linker::Relocate(Module* m)
void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info) {
auto ids = StringUtil::split(name, '#');
auto ids = StringUtil::split_string(name, '#');
if (ids.size() == 3) // symbols are 3 parts name , library , module
{

23
src/Util/StringUtil.cpp Normal file
View File

@ -0,0 +1,23 @@
#include "StringUtil.h"
#include <algorithm>
#include <sstream>
#include <string>
namespace StringUtil {
std::vector<std::string> split_string(const std::string &str, char delimiter) {
std::stringstream str_stream(str);
std::string segment;
std::vector<std::string> seglist;
const size_t num_segments = std::count_if(str.begin(), str.end(), [&](char c) { return c == delimiter; }) + (str.empty() ? 1 : 0);
seglist.reserve(num_segments);
while (std::getline(str_stream, segment, delimiter)) {
seglist.push_back(segment);
}
return seglist;
}
} // namespace StringUtil

View File

@ -4,23 +4,6 @@
namespace StringUtil {
static std::vector<std::string> split(const std::string& s, char seperator)
{
std::vector<std::string> output;
std::vector<std::string> split_string(const std::string& str, char delimiter);
std::string::size_type prev_pos = 0, pos = 0;
while ((pos = s.find(seperator, pos)) != std::string::npos)
{
std::string substring(s.substr(prev_pos, pos - prev_pos));
output.push_back(substring);
prev_pos = ++pos;
}
output.push_back(s.substr(prev_pos, pos - prev_pos)); // Last word
return output;
}
}