remove magic_enum wrappers

Co-authored-by: Saadi <cosxmos@gmail.com>
This commit is contained in:
nmzik
2026-09-17 19:39:23 +04:00
parent c66d977c1d
commit cc8e02380f
9 changed files with 31 additions and 75 deletions
-42
View File
@@ -1,42 +0,0 @@
#ifndef KYTY_COMMON_MAGICENUM_H_
#define KYTY_COMMON_MAGICENUM_H_
#include "common/common.h"
#include "common/stringUtils.h"
#include "magic_enum.hpp" // IWYU pragma: export
namespace Common {
template <typename E>
inline std::string EnumName(E v) {
auto str = magic_enum::enum_name(v);
return std::string(str.data(), str.length());
}
template <typename E>
inline std::string EnumName8(E v) {
auto str = magic_enum::enum_name(v);
return std::string(str.data(), str.length());
}
template <typename E>
inline E EnumValue(const std::string& str, E default_value) {
auto v = magic_enum::enum_cast<E>(str.c_str());
if (v.has_value()) {
return v.value();
}
return default_value;
}
#define KYTY_ENUM_RANGE(e, mx, mn) \
namespace magic_enum::customize { \
template <> \
struct enum_range<e> { \
static constexpr int min = (mx); \
static constexpr int max = (mn); \
}; \
}
} // namespace Common
#endif /* KYTY_COMMON_MAGICENUM_H_ */
@@ -2,8 +2,8 @@
#define EMULATOR_INCLUDE_EMULATOR_GRAPHICS_SHADER_RECOMPILER_SHADERDECODER_H_
#include "common/common.h"
#include "common/magicEnum.h"
#include <magic_enum.hpp>
#include <span>
#include <string_view>
#include <vector>
-1
View File
@@ -4,7 +4,6 @@
#include "common/common.h"
#include "common/emulatorConfig.h"
#include "common/logging/log.h"
#include "common/magicEnum.h"
#include "common/profiler.h"
#include "common/stringUtils.h"
#include "graphics/guest_gpu/gpu_defs.h"
+7 -7
View File
@@ -2,7 +2,6 @@
#include "common/assert.h"
#include "common/logging/log.h"
#include "common/magicEnum.h"
#include "common/stringUtils.h"
#include "common/threads.h"
#include "common/virtualMemory.h"
@@ -17,6 +16,7 @@
#include <cstddef>
#include <cstdlib>
#include <cstring>
#include <magic_enum.hpp>
#include <map>
#include <memory>
#include <mutex>
@@ -2324,8 +2324,8 @@ int32_t KYTY_SYSV_ABI KernelMapNamedFlexibleMemory(void** addr_in_out, size_t le
"\t flags = 0x%08" PRIx32 "\n"
"\t name = %s\n"
"\t gpu_mode = %s\n",
in_addr, out_addr, len, Common::EnumName(mode).c_str(), static_cast<uint32_t>(flags), name,
Common::EnumName(gpu_mode).c_str());
in_addr, out_addr, len, magic_enum::enum_name(mode), static_cast<uint32_t>(flags), name,
magic_enum::enum_name(gpu_mode));
MapGpuRange(out_addr, len);
@@ -3041,8 +3041,8 @@ int KYTY_SYSV_ABI KernelMapDirectMemory(void** addr, size_t len, int prot, int f
"\t shared = %s\n"
"\t reason = %s\n",
in_addr, out_addr, static_cast<uint64_t>(direct_memory_start), len,
Common::EnumName(mode).c_str(), static_cast<uint32_t>(flags), alignment,
Common::EnumName(gpu_mode).c_str(), shared_backing ? "yes" : "no", shared_reason);
magic_enum::enum_name(mode), static_cast<uint32_t>(flags), alignment,
magic_enum::enum_name(gpu_mode), shared_backing ? "yes" : "no", shared_reason);
if (out_addr == 0) {
if (consumed_reservation) {
@@ -3305,7 +3305,7 @@ static bool ReplaceFixedRangeWithReserved(uint64_t start, uint64_t size) {
"\t reserve-fixed replace: backend unmap failed at 0x%016" PRIx64
", size=0x%016" PRIx64 ", type=%s\n",
chunk.range.start, chunk.range.size,
Common::EnumName(chunk.range.type).c_str());
magic_enum::enum_name(chunk.range.type));
if (!restore_chunks()) {
EXIT("reserve-fixed backend-unmap rollback failed\n");
}
@@ -3769,7 +3769,7 @@ int KYTY_SYSV_ABI KernelMprotect(const void* addr, size_t len, int prot) {
}
g_virtual_ranges->Protect(aligned_addr, aligned_len, prot);
LOGF("\t prot: %s -> %s\n", Common::EnumName(old_mode).c_str(), Common::EnumName(mode).c_str());
LOGF("\t prot: %s -> %s\n", magic_enum::enum_name(old_mode), magic_enum::enum_name(mode));
return OK;
}
+5 -6
View File
@@ -5,7 +5,6 @@
#include "common/common.h"
#include "common/emulatorConfig.h"
#include "common/logging/log.h"
#include "common/magicEnum.h"
#include "common/stringUtils.h"
#include "common/threads.h"
#include "kernel/pthread.h"
@@ -20,6 +19,7 @@
#include <cstdlib>
#include <cstring>
#include <limits>
#include <magic_enum.hpp>
#include <vector>
#include "libatrac9.h"
@@ -800,8 +800,7 @@ int KYTY_SYSV_ABI AudioOutOpen(int user_id, int type, int index, uint32_t len, u
default:;
}
LOGF("\t param = %u (format=%u, %s)\n", param, format_param,
Common::EnumName(format).c_str());
LOGF("\t param = %u (format=%u, %s)\n", param, format_param, magic_enum::enum_name(format));
EXIT_NOT_IMPLEMENTED(format == Audio::Format::Unknown);
@@ -966,7 +965,7 @@ static int OpenPort(int user_id, int type, int index, uint32_t len, uint32_t fre
default: return AUDIO_IN_ERROR_INVALID_PARAM;
}
LOGF("\t param = %u (%s)\n", param, Common::EnumName(format).c_str());
LOGF("\t param = %u (%s)\n", param, magic_enum::enum_name(format));
EXIT_IF(g_audio == nullptr);
@@ -2361,7 +2360,7 @@ int KYTY_SYSV_ABI Ngs2RackCreate(uintptr_t system_handle, uint32_t rack_id,
default: EXIT("unknown rack_id: 0x%" PRIx32 "\n", rack_id);
}
LOGF("\t type = %s\n", Common::EnumName(rack->type).c_str());
LOGF("\t type = %s\n", magic_enum::enum_name(rack->type));
rack->allocator = Ngs2BufferAllocator();
rack->buffer_info = *buffer_info;
@@ -3120,7 +3119,7 @@ int KYTY_SYSV_ABI Ngs2VoiceGetState(uintptr_t voice_handle, Ngs2VoiceState* stat
sampler->waveform_data = nullptr;
break;
}
default: EXIT("unknown type: %s\n", Common::EnumName(voice->rack->type).c_str());
default: EXIT("unknown type: %s\n", magic_enum::enum_name(voice->rack->type));
}
return OK;
+2 -2
View File
@@ -1,6 +1,5 @@
#include "common/common.h"
#include "common/logging/log.h"
#include "common/magicEnum.h"
#include "common/stringUtils.h"
#include "kernel/fileSystem.h"
#include "kernel/pthread.h"
@@ -16,6 +15,7 @@
#include <cstdio>
#include <cstring>
#include <deque>
#include <magic_enum.hpp>
#include <memory>
#include <mutex>
#include <optional>
@@ -1758,7 +1758,7 @@ static void log_init_common(const AvPlayerMemAllocator& mem, const AvPlayerFileR
"= %d\n\t base_priority "
" = %u\n\t auto_start = %u\n\t default_language "
" = %s\n",
Common::EnumName(debug_level).c_str(), buffers, priority, auto_start,
magic_enum::enum_name(debug_level), buffers, priority, auto_start,
language == nullptr ? "(null)" : language);
}
+11 -11
View File
@@ -6,7 +6,6 @@
#include "common/file.h"
#include "common/hostException.h"
#include "common/logging/log.h"
#include "common/magicEnum.h"
#include "common/platform/sysDbg.h"
#include "common/profiler.h"
#include "common/singleton.h"
@@ -29,6 +28,7 @@
#include <cstdlib>
#include <cstring>
#include <fmt/format.h>
#include <magic_enum.hpp>
#include <memory>
#include <vector>
@@ -330,7 +330,7 @@ static KYTY_SYSV_ABI uint64_t ResolveImportStubWithId(uint64_t record_id) {
LOGF("Unresolved import stub called [%u]: patch_vaddr=0x%016" PRIx64
" jmprela_index=%" PRIu32 " symbol=%s type=%s bind=%s program=%s\n",
log_index, record.patch_vaddr, record.index, record.name.c_str(),
Common::EnumName(record.type).c_str(), Common::EnumName(record.bind).c_str(),
magic_enum::enum_name(record.type), magic_enum::enum_name(record.bind),
record.program.c_str());
} else {
printf("Unresolved import stub called: <bad-record>\n");
@@ -1046,8 +1046,8 @@ static void RelocateRecord(uint32_t index, Elf64_Rela* r, Program* program, bool
patched = PatchGuestMemory64(ri.vaddr, value);
} else {
auto dbg_str = fmt::format("[{:016x}] <- {:016x}, {}, {}, {}, {}", ri.vaddr, ri.value,
ri.name.c_str(), Common::EnumName(ri.type).c_str(),
Common::EnumName(ri.bind).c_str(), ri.dbg_name.c_str());
ri.name.c_str(), magic_enum::enum_name(ri.type),
magic_enum::enum_name(ri.bind), ri.dbg_name.c_str());
if (unresolved != nullptr) {
unresolved->push_back(dbg_str);
@@ -1077,14 +1077,14 @@ static void RelocateRecord(uint32_t index, Elf64_Rela* r, Program* program, bool
const auto thunk = RegisterStubbedImport(index, program, ri);
LOGF("Relocate: unresolved PLT import patched to stub [%u] [%016" PRIx64 "] <- %016" PRIx64
", %s, %s, %s, %s\n",
index, ri.vaddr, thunk, ri.name.c_str(), Common::EnumName(ri.type).c_str(),
Common::EnumName(ri.bind).c_str(), Common::PathToString(program->file_name).c_str());
index, ri.vaddr, thunk, ri.name.c_str(), magic_enum::enum_name(ri.type),
magic_enum::enum_name(ri.bind), Common::PathToString(program->file_name).c_str());
} else if (patched && stubbed_func) {
const auto thunk = RegisterStubbedImport(index, program, ri);
LOGF("Relocate: unresolved non-PLT function patched to stub [%u] [%016" PRIx64
"] <- %016" PRIx64 ", %s, %s, %s, %s\n",
index, ri.vaddr, thunk, ri.name.c_str(), Common::EnumName(ri.type).c_str(),
Common::EnumName(ri.bind).c_str(), Common::PathToString(program->file_name).c_str());
index, ri.vaddr, thunk, ri.name.c_str(), magic_enum::enum_name(ri.type),
magic_enum::enum_name(ri.bind), Common::PathToString(program->file_name).c_str());
}
if (program->dbg_print_reloc) {
@@ -1092,8 +1092,8 @@ static void RelocateRecord(uint32_t index, Elf64_Rela* r, Program* program, bool
(ri.bind == BindType::Global || ri.bind == BindType::Weak ||
ri.type == SymbolType::TlsModule)) {
auto dbg_str = fmt::format("[{:016x}] <- {:016x}, {}, {}, {}, {}", ri.vaddr, ri.value,
ri.name.c_str(), Common::EnumName(ri.type).c_str(),
Common::EnumName(ri.bind).c_str(), ri.dbg_name.c_str());
ri.name.c_str(), magic_enum::enum_name(ri.type),
magic_enum::enum_name(ri.bind), ri.dbg_name.c_str());
LOGF("Relocate: %s\n", dbg_str.c_str());
}
@@ -2082,7 +2082,7 @@ void RuntimeLinker::LoadProgramToMemory(Program* program) {
"[%d] memory_size = %" PRIu64 "\n"
"[%d] mode = %s\n",
i, segment_addr, i, segment_file_size, i, segment_memory_size, i,
Common::EnumName(mode).c_str());
magic_enum::enum_name(mode));
program->elf->LoadSegment(segment_addr, phdr[i].p_offset, segment_file_size);
+4 -4
View File
@@ -1,9 +1,9 @@
#include "loader/symbolDatabase.h"
#include "common/file.h"
#include "common/magicEnum.h"
#include <fmt/format.h>
#include <magic_enum.hpp>
namespace Loader {
@@ -18,7 +18,7 @@ std::string SymbolDatabase::GenerateName(const SymbolResolve& s) {
auto module = UpdateName(s.module);
return fmt::format("{}[{}_v{}][{}_v{}.{}][{}]", s.name.c_str(), library.c_str(),
s.library_version, module.c_str(), s.module_version_major,
s.module_version_minor, Common::EnumName(s.type).c_str());
s.module_version_minor, magic_enum::enum_name(s.type));
}
void SymbolDatabase::Add(const SymbolResolve& s, uint64_t vaddr) {
@@ -67,7 +67,7 @@ const SymbolRecord* SymbolDatabase::Find(const SymbolResolve& s) const {
const SymbolRecord* SymbolDatabase::FindByNid(const std::string& nid, SymbolType type) const {
auto prefix = nid + "[";
auto suffix = fmt::format("[{}]", Common::EnumName(type).c_str());
auto suffix = fmt::format("[{}]", magic_enum::enum_name(type));
for (const auto& symbol: m_symbols) {
if (Common::StartsWith(symbol.name, prefix) && Common::EndsWith(symbol.name, suffix)) {
@@ -80,7 +80,7 @@ const SymbolRecord* SymbolDatabase::FindByNid(const std::string& nid, SymbolType
const SymbolRecord* SymbolDatabase::FindByName(const std::string& name, SymbolType type) const {
auto prefix = name + "[";
auto suffix = fmt::format("[{}]", Common::EnumName(type).c_str());
auto suffix = fmt::format("[{}]", magic_enum::enum_name(type));
for (const auto& symbol: m_symbols) {
if (Common::StartsWith(symbol.name, prefix) && Common::EndsWith(symbol.name, suffix)) {
+1 -1
View File
@@ -2,7 +2,6 @@
#include "common/dateTime.h"
#include "common/debug.h"
#include "common/file.h"
#include "common/magicEnum.h"
#include "common/stringUtils.h"
#include "common/threads.h"
#include "common/virtualMemory.h"
@@ -12,6 +11,7 @@
#include <charconv>
#include <cstdio>
#include <fmt/format.h>
#include <magic_enum.hpp>
using namespace Common;
using namespace Emulator;