diff --git a/.github/workflows/linux-workflow.yaml b/.github/workflows/linux-workflow.yaml index 4a874449a8..d243ff83e1 100644 --- a/.github/workflows/linux-workflow.yaml +++ b/.github/workflows/linux-workflow.yaml @@ -45,7 +45,6 @@ jobs: key: submodules-${{ hashFiles('./.gitmodules') }} path: | ./third-party/googletest - ./third-party/spdlog ./third-party/zydis ./.git/modules/ diff --git a/.github/workflows/windows-workflow.yaml b/.github/workflows/windows-workflow.yaml index 1296841e43..df9d0f0c34 100644 --- a/.github/workflows/windows-workflow.yaml +++ b/.github/workflows/windows-workflow.yaml @@ -44,7 +44,6 @@ jobs: key: submodules-${{ hashFiles('./.gitmodules') }} path: | ./third-party/googletest - ./third-party/spdlog ./third-party/zydis ./.git/modules/ diff --git a/.gitignore b/.gitignore index c3c13dd1bb..00620b5359 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ cmake-build-debug/* build/* decompiler_out/* logs/* +log/* \ No newline at end of file diff --git a/.gitmodules b/.gitmodules index 4b8c68fa22..bed025c79f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,9 +1,6 @@ [submodule "third-party/googletest"] path = third-party/googletest url = https://github.com/google/googletest.git -[submodule "third-party/spdlog"] - path = third-party/spdlog - url = https://github.com/gabime/spdlog.git [submodule "third-party/zydis"] path = third-party/zydis url = https://github.com/zyantific/zydis.git diff --git a/CMakeLists.txt b/CMakeLists.txt index e953e7e99c..7fa5af6ec1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,28 +64,8 @@ include_directories(./) include_directories(SYSTEM third-party/inja) -# build spdlog as a shared library to improve compile times -# adding this as a SYSTEM include suppresses all the terrible warnings in spdlog -include_directories(SYSTEM third-party/spdlog/include) -# this makes spdlog generate a shared library that we can link against -set(SPDLOG_BUILD_SHARED ON CACHE BOOL "a" FORCE) -# this makes the spdlog includes not use the header only version, making compiling faster -add_definitions(-DSPDLOG_COMPILED_LIB) - -# build goos -add_subdirectory(common/goos) - -# build type_system library for compiler/decompiler -add_subdirectory(common/type_system) - -# build common_util library -add_subdirectory(common/util) - -# build cross platform socket library -add_subdirectory(common/cross_sockets) - -# build cross platform debug library -add_subdirectory(common/cross_os_debug) +# build common library +add_subdirectory(common) # build decompiler add_subdirectory(decompiler) @@ -108,9 +88,6 @@ add_subdirectory(third-party/minilzo) # build format library add_subdirectory(third-party/fmt) -# build spdlog library -add_subdirectory(third-party/spdlog) - # build zydis third party library for disassembling x86 option(ZYDIS_BUILD_TOOLS "" OFF) option(ZYDIS_BUILD_EXAMPLES "" OFF) diff --git a/README.md b/README.md index 0794efae36..eabd8b2437 100644 --- a/README.md +++ b/README.md @@ -165,7 +165,6 @@ The final component is the "runtime", located in `game`. This is the part of the - `mman`: Windows library used to emulate `mmap` on Linux - `run-clang-format`: Utility to check and enforce code formatting - `run-clang-tidy` - - `spdlog`: Logging library - `zydis`: x86-64 disassembler used in the OpenGOAL debugger - `json`: A JSON library - `linenoise`: Used for the REPL input. Support history and useful editing shortcuts. diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 0000000000..02a6f48f63 --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,28 @@ +add_library(common + SHARED + cross_os_debug/xdbg.cpp + cross_sockets/xsocket.cpp + goos/Interpreter.cpp + goos/Object.cpp + goos/ParseHelpers.cpp + goos/PrettyPrinter.cpp + goos/Reader.cpp + goos/TextDB.cpp + log/log.cpp + type_system/deftype.cpp + type_system/Type.cpp + type_system/TypeFieldLookup.cpp + type_system/TypeSpec.cpp + type_system/TypeSystem.cpp + util/DgoWriter.cpp + util/FileUtil.cpp + util/Timer.cpp + ) + +target_link_libraries(common fmt) + +IF(WIN32) + target_link_libraries(common wsock32 ws2_32) +ELSE() + target_link_libraries(common stdc++fs) +ENDIF() \ No newline at end of file diff --git a/common/cross_os_debug/CMakeLists.txt b/common/cross_os_debug/CMakeLists.txt deleted file mode 100644 index b29f36f8d5..0000000000 --- a/common/cross_os_debug/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ -add_library(cross_os_debug SHARED - xdbg.cpp) - -target_link_libraries(cross_os_debug fmt) \ No newline at end of file diff --git a/common/cross_sockets/CMakeLists.txt b/common/cross_sockets/CMakeLists.txt deleted file mode 100644 index f97ddd0f83..0000000000 --- a/common/cross_sockets/CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -add_library(cross_sockets - SHARED - "xsocket.h" - "xsocket.cpp") - -IF (WIN32) - # set stuff for windows - target_link_libraries(cross_sockets wsock32 ws2_32) -ELSE() - # set stuff for other systems - target_link_libraries(cross_sockets) -ENDIF() diff --git a/common/goos/CMakeLists.txt b/common/goos/CMakeLists.txt deleted file mode 100644 index 2000a6f58e..0000000000 --- a/common/goos/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ - -IF (WIN32) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /O2") -ELSE() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3") -ENDIF() - -add_library(goos SHARED Object.cpp ParseHelpers.cpp TextDB.cpp Reader.cpp Interpreter.cpp PrettyPrinter.cpp ParseHelpers.cpp ParseHelpers.h) -target_link_libraries(goos common_util fmt) \ No newline at end of file diff --git a/common/log/log.cpp b/common/log/log.cpp new file mode 100644 index 0000000000..0313852700 --- /dev/null +++ b/common/log/log.cpp @@ -0,0 +1,114 @@ +#include +#include +#include +#include +#include "third-party/fmt/color.h" +#include "log.h" + +namespace lg { +struct Logger { + Logger() = default; + + bool initialized = false; + FILE* fp = nullptr; + level stdout_log_level = level::trace; + level file_log_level = level::trace; + level flush_level = level::trace; + std::mutex mutex; + + ~Logger() { + // will run when program exits. + if (fp) { + fclose(fp); + } + } +}; + +Logger gLogger; + +namespace internal { +const char* log_level_names[] = {"trace", "debug", "info", "warn", "error", "die"}; +const fmt::color log_colors[] = {fmt::color::gray, fmt::color::turquoise, fmt::color::light_green, + fmt::color::yellow, fmt::color::red, fmt::color::hot_pink}; + +void log_message(level log_level, LogTime& now, const char* message) { +#ifdef __linux__ + char date_time_buffer[128]; + time_t now_seconds = now.tv.tv_sec; + auto now_milliseconds = now.tv.tv_usec / 1000; + strftime(date_time_buffer, 128, "%Y-%m-%d %H:%M:%S", localtime(&now_seconds)); + std::string date_string = fmt::format("[{}:{:03d}]", date_time_buffer, now_milliseconds); +#else + char date_time_buffer[128]; + strftime(date_time_buffer, 128, "%Y-%m-%d %H:%M:%S", localtime(&now.tim)); + std::string date_string = fmt::format("[{}]", date_time_buffer); +#endif + + { + std::lock_guard lock(gLogger.mutex); + if (gLogger.fp && log_level >= gLogger.file_log_level) { + // log to file + std::string file_string = + fmt::format("{} [{}] {}\n", date_string, log_level_names[int(log_level)], message); + fwrite(file_string.c_str(), file_string.length(), 1, gLogger.fp); + if (log_level >= gLogger.flush_level) { + fflush(gLogger.fp); + } + } + + if (log_level >= gLogger.stdout_log_level) { + fmt::print("{} [", date_string); + fmt::print(fg(log_colors[int(log_level)]), "{}", log_level_names[int(log_level)]); + fmt::print("] {}\n", message); + if (log_level >= gLogger.flush_level) { + fflush(stdout); + } + } + } + + if (log_level == level::die) { + exit(-1); + } +} +} // namespace internal + +void set_file(const std::string& filename) { + assert(!gLogger.fp); + gLogger.fp = fopen(filename.c_str(), "w"); + assert(gLogger.fp); +} + +void set_flush_level(level log_level) { + gLogger.flush_level = log_level; +} + +void set_file_level(level log_level) { + gLogger.file_log_level = log_level; +} + +void set_stdout_level(level log_level) { + gLogger.stdout_log_level = log_level; +} + +void set_max_debug_levels() { + gLogger.flush_level = level::trace; + gLogger.stdout_log_level = level::trace; + gLogger.file_log_level = level::trace; +} + +void initialize() { + assert(!gLogger.initialized); + gLogger.initialized = true; +} + +void finish() { + { + std::lock_guard lock(gLogger.mutex); + if (gLogger.fp) { + fclose(gLogger.fp); + gLogger.fp = nullptr; + } + } +} + +} // namespace lg \ No newline at end of file diff --git a/common/log/log.h b/common/log/log.h new file mode 100644 index 0000000000..5de1cca8e4 --- /dev/null +++ b/common/log/log.h @@ -0,0 +1,80 @@ +#pragma once + +#include + +#ifdef __linux__ +#include +#endif +#include +#include "third-party/fmt/core.h" + +namespace lg { + +#ifdef __linux__ +struct LogTime { + timeval tv; +}; +#else +struct LogTime { + time_t tim; +}; +#endif + +// Logging API +enum class level { trace = 0, debug = 1, info = 2, warn = 3, error = 4, die = 5 }; + +namespace internal { +// log implementation stuff, not to be called by the user +void log_message(level log_level, LogTime& now, const char* message); +} // namespace internal + +void set_file(const std::string& filename); +void set_flush_level(level log_level); +void set_file_level(level log_level); +void set_stdout_level(level log_level); +void set_max_debug_levels(); +void initialize(); +void finish(); + +template +void log(level log_level, const std::string& format, Args&&... args) { + LogTime now; +#ifdef __linux__ + gettimeofday(&now.tv, nullptr); +#else + now.tim = time(nullptr); +#endif + std::string formatted_message = fmt::format(format, std::forward(args)...); + internal::log_message(log_level, now, formatted_message.c_str()); +} + +template +void trace(const std::string& format, Args&&... args) { + log(level::trace, format, std::forward(args)...); +} + +template +void debug(const std::string& format, Args&&... args) { + log(level::debug, format, std::forward(args)...); +} + +template +void info(const std::string& format, Args&&... args) { + log(level::info, format, std::forward(args)...); +} + +template +void warn(const std::string& format, Args&&... args) { + log(level::warn, format, std::forward(args)...); +} + +template +void error(const std::string& format, Args&&... args) { + log(level::error, format, std::forward(args)...); +} + +template +void die(const std::string& format, Args&&... args) { + log(level::die, format, std::forward(args)...); +} +} // namespace lg diff --git a/common/type_system/CMakeLists.txt b/common/type_system/CMakeLists.txt deleted file mode 100644 index 2236c564ea..0000000000 --- a/common/type_system/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_library(type_system - SHARED - TypeSystem.cpp - Type.cpp - TypeSpec.cpp - deftype.cpp - TypeFieldLookup.cpp) - -target_link_libraries(type_system fmt goos) \ No newline at end of file diff --git a/common/util/CMakeLists.txt b/common/util/CMakeLists.txt deleted file mode 100644 index b2b4e92f32..0000000000 --- a/common/util/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -add_library(common_util - SHARED - FileUtil.cpp - DgoWriter.cpp - Timer.cpp) - -IF(UNIX) -target_link_libraries(common_util stdc++fs) -ENDIF() diff --git a/decompiler/CMakeLists.txt b/decompiler/CMakeLists.txt index 8dd17f2878..a5b650f4c2 100644 --- a/decompiler/CMakeLists.txt +++ b/decompiler/CMakeLists.txt @@ -30,9 +30,6 @@ add_executable(decompiler IR/IR_ExpressionStack.cpp) target_link_libraries(decompiler - goos + common minilzo - common_util - type_system - spdlog fmt) diff --git a/decompiler/Function/Function.cpp b/decompiler/Function/Function.cpp index cf38418282..eec3510805 100644 --- a/decompiler/Function/Function.cpp +++ b/decompiler/Function/Function.cpp @@ -1,7 +1,7 @@ #include #include #include "Function.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" #include "decompiler/Disasm/InstructionMatching.h" #include "decompiler/ObjectFile/LinkedObjectFile.h" #include "decompiler/util/DecompilerTypeSystem.h" @@ -92,8 +92,8 @@ void Function::analyze_prologue(const LinkedObjectFile& file) { // storing s7 on the stack is done by interrupt handlers, which we probably don't want to // support if (instr.kind == InstructionKind::SD && instr.get_src(0).get_reg() == make_gpr(Reg::S7)) { - spdlog::warn("{} Suspected ASM function based on this instruction in prologue: {}\n", - guessed_name.to_string(), instr.to_string(file)); + lg::warn("{} Suspected ASM function based on this instruction in prologue: {}\n", + guessed_name.to_string(), instr.to_string(file)); warnings += ";; Flagged as ASM function because of " + instr.to_string(file) + "\n"; suspected_asm = true; return; diff --git a/decompiler/ObjectFile/LinkedObjectFile.cpp b/decompiler/ObjectFile/LinkedObjectFile.cpp index 4944ab71ac..8ff14dca99 100644 --- a/decompiler/ObjectFile/LinkedObjectFile.cpp +++ b/decompiler/ObjectFile/LinkedObjectFile.cpp @@ -13,7 +13,7 @@ #include "decompiler/Disasm/InstructionDecode.h" #include "decompiler/config.h" #include "third-party/json.hpp" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" #include "common/goos/PrettyPrinter.h" /*! @@ -518,7 +518,7 @@ std::string LinkedObjectFile::to_asm_json(const std::string& obj_file_name) { auto& func = functions_by_seg.at(seg).at(fi); auto fname = func.guessed_name.to_string(); if (functions_seen.find(fname) != functions_seen.end()) { - spdlog::warn( + lg::warn( "Function {} appears multiple times in the same object file {} - it cannot be uniquely " "referenced from config", func.guessed_name.to_string(), obj_file_name); diff --git a/decompiler/ObjectFile/ObjectFileDB.cpp b/decompiler/ObjectFile/ObjectFileDB.cpp index 7bf06cad2e..3f28a38b5b 100644 --- a/decompiler/ObjectFile/ObjectFileDB.cpp +++ b/decompiler/ObjectFile/ObjectFileDB.cpp @@ -24,7 +24,7 @@ #include "decompiler/IR/BasicOpBuilder.h" #include "decompiler/IR/CfgBuilder.h" #include "decompiler/Function/TypeInspector.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" #include "third-party/json.hpp" namespace { @@ -112,32 +112,32 @@ ObjectFileDB::ObjectFileDB(const std::vector& _dgos, const std::vector& str_files) { Timer timer; - spdlog::info("-Loading types..."); + lg::info("-Loading types..."); dts.parse_type_defs({"decompiler", "config", "all-types.gc"}); if (!obj_file_name_map_file.empty()) { - spdlog::info("-Loading obj name map file..."); + lg::info("-Loading obj name map file..."); load_map_file(file_util::read_text_file(file_util::get_file_path({obj_file_name_map_file}))); } else { - spdlog::warn( + lg::warn( "Not using an obj name map file! The decompiler will automatically generate object file " "names and write them to out/objs.txt. It is recommended to reuse this map file to get " "consistent naming when doing a partial decompilation."); } - spdlog::info("-Loading DGOs..."); + lg::info("-Loading DGOs..."); for (auto& dgo : _dgos) { get_objs_from_dgo(dgo); } - spdlog::info("-Loading plain object files..."); + lg::info("-Loading plain object files..."); for (auto& obj : object_files) { auto data = file_util::read_binary_file(obj); auto name = obj_filename_to_name(obj); add_obj_from_dgo(name, name, data.data(), data.size(), "NO-XGO"); } - spdlog::info("-Loading streaming object files..."); + lg::info("-Loading streaming object files..."); for (auto& obj : str_files) { StrFileReader reader(obj); // name from the file name @@ -152,15 +152,15 @@ ObjectFileDB::ObjectFileDB(const std::vector& _dgos, } } - spdlog::info("ObjectFileDB Initialized:"); - spdlog::info("Total DGOs: {}", int(_dgos.size())); - spdlog::info("Total data: {} bytes", stats.total_dgo_bytes); - spdlog::info("Total objs: {}", stats.total_obj_files); - spdlog::info("Unique objs: {}", stats.unique_obj_files); - spdlog::info("Unique data: {} bytes", stats.unique_obj_bytes); - spdlog::info("Total {:.2f} ms ({:.3f} MB/sec, {:.2f} obj/sec)", timer.getMs(), - stats.total_dgo_bytes / ((1u << 20u) * timer.getSeconds()), - stats.total_obj_files / timer.getSeconds()); + lg::info("ObjectFileDB Initialized:"); + lg::info("Total DGOs: {}", int(_dgos.size())); + lg::info("Total data: {} bytes", stats.total_dgo_bytes); + lg::info("Total objs: {}", stats.total_obj_files); + lg::info("Unique objs: {}", stats.unique_obj_files); + lg::info("Unique data: {} bytes", stats.unique_obj_bytes); + lg::info("Total {:.2f} ms ({:.3f} MB/sec, {:.2f} obj/sec)", timer.getMs(), + stats.total_dgo_bytes / ((1u << 20u) * timer.getSeconds()), + stats.total_obj_files / timer.getSeconds()); } void ObjectFileDB::load_map_file(const std::string& map_data) { @@ -180,7 +180,7 @@ void ObjectFileDB::load_map_file(const std::string& map_data) { for (auto& dgo : dgo_names) { auto kv = dgo_obj_name_map[dgo].find(game_name_with_ag); if (kv != dgo_obj_name_map[dgo].end()) { - spdlog::error("Object {} in dgo {} occurs more than one time.", game_name_with_ag, dgo); + lg::error("Object {} in dgo {} occurs more than one time.", game_name_with_ag, dgo); assert(false); } dgo_obj_name_map[dgo][game_name_with_ag] = mapped_name; @@ -317,7 +317,7 @@ void ObjectFileDB::get_objs_from_dgo(const std::string& filename) { assert_string_empty_after(obj_header.name, 60); if (std::string(obj_header.name).find("-ag") != std::string::npos) { - spdlog::error( + lg::error( "Object file {} has \"-ag\" in its name. This will break any tools which use this to " "detect an art group", obj_header.name); @@ -388,14 +388,13 @@ void ObjectFileDB::add_obj_from_dgo(const std::string& obj_name, if (!dgo_obj_name_map.empty()) { auto dgo_kv = dgo_obj_name_map.find(strip_dgo_extension(dgo_name)); if (dgo_kv == dgo_obj_name_map.end()) { - spdlog::error("Object {} is from DGO {}, but this DGO wasn't in the map.", obj_name, - dgo_name); + lg::error("Object {} is from DGO {}, but this DGO wasn't in the map.", obj_name, dgo_name); assert(false); } auto name_kv = dgo_kv->second.find(obj_name); if (name_kv == dgo_kv->second.end()) { - spdlog::error("Object {} from DGO {} wasn't found in the name map.", obj_name, dgo_name); + lg::error("Object {} from DGO {} wasn't found in the name map.", obj_name, dgo_name); assert(false); } data.name_from_map = name_kv->second; @@ -481,7 +480,7 @@ std::string ObjectFileDB::generate_obj_listing() { * Process all of the linking data of all objects. */ void ObjectFileDB::process_link_data() { - spdlog::info("- Processing Link Data..."); + lg::info("- Processing Link Data..."); Timer process_link_timer; LinkedObjectFile::Stats combined_stats; @@ -491,26 +490,26 @@ void ObjectFileDB::process_link_data() { combined_stats.add(obj.linked_data.stats); }); - spdlog::info("Processed Link Data:"); - spdlog::info(" Code {} bytes", combined_stats.total_code_bytes); - spdlog::info(" v2 Code {} bytes", combined_stats.total_v2_code_bytes); - spdlog::info(" v2 Link Data {} bytes", combined_stats.total_v2_link_bytes); - spdlog::info(" v2 Pointers {}", combined_stats.total_v2_pointers); - spdlog::info(" v2 Pointer Seeks {}", combined_stats.total_v2_pointer_seeks); - spdlog::info(" v2 Symbols {}", combined_stats.total_v2_symbol_count); - spdlog::info(" v2 Symbol Links {}", combined_stats.total_v2_symbol_links); + lg::info("Processed Link Data:"); + lg::info(" Code {} bytes", combined_stats.total_code_bytes); + lg::info(" v2 Code {} bytes", combined_stats.total_v2_code_bytes); + lg::info(" v2 Link Data {} bytes", combined_stats.total_v2_link_bytes); + lg::info(" v2 Pointers {}", combined_stats.total_v2_pointers); + lg::info(" v2 Pointer Seeks {}", combined_stats.total_v2_pointer_seeks); + lg::info(" v2 Symbols {}", combined_stats.total_v2_symbol_count); + lg::info(" v2 Symbol Links {}", combined_stats.total_v2_symbol_links); - spdlog::info(" v3 Code {} bytes", combined_stats.v3_code_bytes); - spdlog::info(" v3 Link Data {} bytes", combined_stats.v3_link_bytes); - spdlog::info(" v3 Pointers {}", combined_stats.v3_pointers); - spdlog::info(" Split {}", combined_stats.v3_split_pointers); - spdlog::info(" Word {}", combined_stats.v3_word_pointers); - spdlog::info(" v3 Pointer Seeks {}", combined_stats.v3_pointer_seeks); - spdlog::info(" v3 Symbols {}", combined_stats.v3_symbol_count); - spdlog::info(" v3 Offset Symbol Links {}", combined_stats.v3_symbol_link_offset); - spdlog::info(" v3 Word Symbol Links {}", combined_stats.v3_symbol_link_word); + lg::info(" v3 Code {} bytes", combined_stats.v3_code_bytes); + lg::info(" v3 Link Data {} bytes", combined_stats.v3_link_bytes); + lg::info(" v3 Pointers {}", combined_stats.v3_pointers); + lg::info(" Split {}", combined_stats.v3_split_pointers); + lg::info(" Word {}", combined_stats.v3_word_pointers); + lg::info(" v3 Pointer Seeks {}", combined_stats.v3_pointer_seeks); + lg::info(" v3 Symbols {}", combined_stats.v3_symbol_count); + lg::info(" v3 Offset Symbol Links {}", combined_stats.v3_symbol_link_offset); + lg::info(" v3 Word Symbol Links {}", combined_stats.v3_symbol_link_word); - spdlog::info(" Total {} ms\n", process_link_timer.getMs()); + lg::info(" Total {} ms\n", process_link_timer.getMs()); // printf("\n"); } @@ -518,14 +517,14 @@ void ObjectFileDB::process_link_data() { * Process all of the labels generated from linking and give them reasonable names. */ void ObjectFileDB::process_labels() { - spdlog::info("- Processing Labels..."); + lg::info("- Processing Labels..."); Timer process_label_timer; uint32_t total = 0; for_each_obj([&](ObjectFileData& obj) { total += obj.linked_data.set_ordered_label_names(); }); - spdlog::info("Processed Labels:"); - spdlog::info(" Total {} labels", total); - spdlog::info(" Total {} ms", process_label_timer.getMs()); + lg::info("Processed Labels:"); + lg::info(" Total {} labels", total); + lg::info(" Total {} ms", process_label_timer.getMs()); // printf("\n"); } @@ -534,9 +533,9 @@ void ObjectFileDB::process_labels() { */ void ObjectFileDB::write_object_file_words(const std::string& output_dir, bool dump_v3_only) { if (dump_v3_only) { - spdlog::info("- Writing object file dumps (v3 only)..."); + lg::info("- Writing object file dumps (v3 only)..."); } else { - spdlog::info("- Writing object file dumps (all)..."); + lg::info("- Writing object file dumps (all)..."); } Timer timer; @@ -552,17 +551,17 @@ void ObjectFileDB::write_object_file_words(const std::string& output_dir, bool d } }); - spdlog::info("Wrote object file dumps:"); - spdlog::info(" Total {} files", total_files); - spdlog::info(" Total {:.3f} MB", total_bytes / ((float)(1u << 20u))); - spdlog::info(" Total {} ms ({:.3f} MB/sec)", timer.getMs(), - total_bytes / ((1u << 20u) * timer.getSeconds())); + lg::info("Wrote object file dumps:"); + lg::info(" Total {} files", total_files); + lg::info(" Total {:.3f} MB", total_bytes / ((float)(1u << 20u))); + lg::info(" Total {} ms ({:.3f} MB/sec)", timer.getMs(), + total_bytes / ((1u << 20u) * timer.getSeconds())); // printf("\n"); } void ObjectFileDB::write_debug_type_analysis(const std::string& output_dir, const std::string& suffix) { - spdlog::info("- Writing debug type analysis..."); + lg::info("- Writing debug type analysis..."); Timer timer; uint32_t total_bytes = 0, total_files = 0; @@ -578,11 +577,11 @@ void ObjectFileDB::write_debug_type_analysis(const std::string& output_dir, } }); - spdlog::info("Wrote functions dumps:"); - spdlog::info(" Total {} files", total_files); - spdlog::info(" Total {} MB", total_bytes / ((float)(1u << 20u))); - spdlog::info(" Total {} ms ({:.3f} MB/sec)", timer.getMs(), - total_bytes / ((1u << 20u) * timer.getSeconds())); + lg::info("Wrote functions dumps:"); + lg::info(" Total {} files", total_files); + lg::info(" Total {} MB", total_bytes / ((float)(1u << 20u))); + lg::info(" Total {} ms ({:.3f} MB/sec)", timer.getMs(), + total_bytes / ((1u << 20u) * timer.getSeconds())); } /*! @@ -592,7 +591,7 @@ void ObjectFileDB::write_disassembly(const std::string& output_dir, bool disassemble_objects_without_functions, bool write_json, const std::string& file_suffix) { - spdlog::info("- Writing functions..."); + lg::info("- Writing functions..."); Timer timer; uint32_t total_bytes = 0, total_files = 0; @@ -625,18 +624,18 @@ void ObjectFileDB::write_disassembly(const std::string& output_dir, file_util::write_text_file(file_util::combine_path(output_dir, "asm_functions.func"), asm_functions); - spdlog::info("Wrote functions dumps:"); - spdlog::info(" Total {} files", total_files); - spdlog::info(" Total {} MB", total_bytes / ((float)(1u << 20u))); - spdlog::info(" Total {} ms ({:.3f} MB/sec)", timer.getMs(), - total_bytes / ((1u << 20u) * timer.getSeconds())); + lg::info("Wrote functions dumps:"); + lg::info(" Total {} files", total_files); + lg::info(" Total {} MB", total_bytes / ((float)(1u << 20u))); + lg::info(" Total {} ms ({:.3f} MB/sec)", timer.getMs(), + total_bytes / ((1u << 20u) * timer.getSeconds())); } /*! * Find code/data zones, identify functions, and disassemble */ void ObjectFileDB::find_code() { - spdlog::info("- Finding code in object files..."); + lg::info("- Finding code in object files..."); LinkedObjectFile::Stats combined_stats; Timer timer; @@ -649,28 +648,28 @@ void ObjectFileDB::find_code() { if (get_config().game_version == 1 || obj.to_unique_name() != "effect-control-v0") { obj.linked_data.process_fp_relative_links(); } else { - spdlog::warn("Skipping process_fp_relative_links in {}", obj.to_unique_name().c_str()); + lg::warn("Skipping process_fp_relative_links in {}", obj.to_unique_name().c_str()); } auto& obj_stats = obj.linked_data.stats; if (obj_stats.code_bytes / 4 > obj_stats.decoded_ops) { - spdlog::warn("Failed to decode all in {} ({} / {})", obj.to_unique_name().c_str(), - obj_stats.decoded_ops, obj_stats.code_bytes / 4); + lg::warn("Failed to decode all in {} ({} / {})", obj.to_unique_name().c_str(), + obj_stats.decoded_ops, obj_stats.code_bytes / 4); } combined_stats.add(obj.linked_data.stats); }); - spdlog::info("Found code:"); - spdlog::info(" Code {:.3f} MB", combined_stats.code_bytes / (float)(1 << 20)); - spdlog::info(" Data {:.3f} MB", combined_stats.data_bytes / (float)(1 << 20)); - spdlog::info(" Functions: {}", combined_stats.function_count); - spdlog::info(" fp uses resolved: {} / {} ({:.3f} %)", combined_stats.n_fp_reg_use_resolved, - combined_stats.n_fp_reg_use, - 100.f * (float)combined_stats.n_fp_reg_use_resolved / combined_stats.n_fp_reg_use); + lg::info("Found code:"); + lg::info(" Code {:.3f} MB", combined_stats.code_bytes / (float)(1 << 20)); + lg::info(" Data {:.3f} MB", combined_stats.data_bytes / (float)(1 << 20)); + lg::info(" Functions: {}", combined_stats.function_count); + lg::info(" fp uses resolved: {} / {} ({:.3f} %)", combined_stats.n_fp_reg_use_resolved, + combined_stats.n_fp_reg_use, + 100.f * (float)combined_stats.n_fp_reg_use_resolved / combined_stats.n_fp_reg_use); auto total_ops = combined_stats.code_bytes / 4; - spdlog::info(" Decoded {} / {} ({:.3f} %)", combined_stats.decoded_ops, total_ops, - 100.f * (float)combined_stats.decoded_ops / total_ops); - spdlog::info(" Total {:.3f} ms", timer.getMs()); + lg::info(" Decoded {} / {} ({:.3f} %)", combined_stats.decoded_ops, total_ops, + 100.f * (float)combined_stats.decoded_ops / total_ops); + lg::info(" Total {:.3f} ms", timer.getMs()); // printf("\n"); } @@ -679,7 +678,7 @@ void ObjectFileDB::find_code() { * Doesn't change any state in ObjectFileDB. */ void ObjectFileDB::find_and_write_scripts(const std::string& output_dir) { - spdlog::info("- Finding scripts in object files..."); + lg::info("- Finding scripts in object files..."); Timer timer; std::string all_scripts; @@ -696,12 +695,12 @@ void ObjectFileDB::find_and_write_scripts(const std::string& output_dir) { auto file_name = file_util::combine_path(output_dir, "all_scripts.lisp"); file_util::write_text_file(file_name, all_scripts); - spdlog::info("Found scripts:"); - spdlog::info(" Total {:.3f} ms\n", timer.getMs()); + lg::info("Found scripts:"); + lg::info(" Total {:.3f} ms\n", timer.getMs()); } void ObjectFileDB::process_tpages() { - spdlog::info("- Finding textures in tpages..."); + lg::info("- Finding textures in tpages..."); std::string tpage_string = "tpage-"; int total = 0, success = 0; Timer timer; @@ -712,12 +711,12 @@ void ObjectFileDB::process_tpages() { success += statistics.successful_textures; } }); - spdlog::info("Processed {} / {} textures {:.2f}% in {:.2f} ms", success, total, - 100.f * float(success) / float(total), timer.getMs()); + lg::info("Processed {} / {} textures {:.2f}% in {:.2f} ms", success, total, + 100.f * float(success) / float(total), timer.getMs()); } std::string ObjectFileDB::process_game_text() { - spdlog::info("- Finding game text..."); + lg::info("- Finding game text..."); std::string text_string = "COMMON"; Timer timer; int file_count = 0; @@ -738,14 +737,14 @@ std::string ObjectFileDB::process_game_text() { } }); - spdlog::info("Processed {} text files ({} strings, {} characters) in {:.2f} ms", file_count, - string_count, char_count, timer.getMs()); + lg::info("Processed {} text files ({} strings, {} characters) in {:.2f} ms", file_count, + string_count, char_count, timer.getMs()); return write_game_text(text_by_language_by_id); } std::string ObjectFileDB::process_game_count() { - spdlog::info("- Finding game count file..."); + lg::info("- Finding game count file..."); bool found = false; std::string result; @@ -758,7 +757,7 @@ std::string ObjectFileDB::process_game_count() { }); if (!found) { - spdlog::warn("did not find game-cnt file"); + lg::warn("did not find game-cnt file"); } return result; @@ -768,7 +767,7 @@ std::string ObjectFileDB::process_game_count() { * This is the main decompiler routine which runs after we've identified functions. */ void ObjectFileDB::analyze_functions() { - spdlog::info("- Analyzing Functions..."); + lg::info("- Analyzing Functions..."); Timer timer; int total_functions = 0; @@ -777,7 +776,7 @@ void ObjectFileDB::analyze_functions() { // Step 1 - analyze the "top level" or "login" code for each object file. // this will give us type definitions, method definitions, and function definitions... - spdlog::info(" - Processing top levels..."); + lg::info(" - Processing top levels..."); timer.start(); for_each_obj([&](ObjectFileData& data) { @@ -921,8 +920,8 @@ void ObjectFileDB::analyze_functions() { if (func.cfg->is_fully_resolved()) { resolved_cfg_functions++; } else { - spdlog::warn("Function {} from {} failed cfg ir", func.guessed_name.to_string(), - data.to_unique_name()); + lg::warn("Function {} from {} failed cfg ir", func.guessed_name.to_string(), + data.to_unique_name()); } // type analysis @@ -936,15 +935,15 @@ void ObjectFileDB::analyze_functions() { auto kv = dts.symbol_types.find(func.guessed_name.function_name); if (kv != dts.symbol_types.end() && kv->second.arg_count() >= 1) { if (kv->second.base_type() != "function") { - spdlog::error("Found a function named {} but the symbol has type {}", - func.guessed_name.to_string(), kv->second.print()); + lg::error("Found a function named {} but the symbol has type {}", + func.guessed_name.to_string(), kv->second.print()); assert(false); } // GOOD! func.type = kv->second; func.attempted_type_analysis = true; attempted_type_analysis++; - // spdlog::info("Type Analysis on {} {}", func.guessed_name.to_string(), + // lg::info("Type Analysis on {} {}", func.guessed_name.to_string(), // kv->second.print()); if (func.run_type_analysis(kv->second, dts, data.linked_data, hints)) { successful_type_analysis++; @@ -963,15 +962,15 @@ void ObjectFileDB::analyze_functions() { dts.ts.lookup_method(func.guessed_name.type_name, func.guessed_name.method_id); if (info.type.arg_count() >= 1) { if (info.type.base_type() != "function") { - spdlog::error("Found a method named {} but the symbol has type {}", - func.guessed_name.to_string(), info.type.print()); + lg::error("Found a method named {} but the symbol has type {}", + func.guessed_name.to_string(), info.type.print()); assert(false); } // GOOD! func.type = info.type.substitute_for_method_call(func.guessed_name.type_name); func.attempted_type_analysis = true; attempted_type_analysis++; - // spdlog::info("Type Analysis on {} {}", + // lg::info("Type Analysis on {} {}", // func.guessed_name.to_string(), // func.type.print()); if (func.run_type_analysis(func.type, dts, data.linked_data, hints)) { @@ -1061,29 +1060,29 @@ void ObjectFileDB::analyze_functions() { // } }); - spdlog::info("Found {} functions ({} with no control flow)", total_functions, - total_trivial_cfg_functions); - spdlog::info("Named {}/{} functions ({:.3f}%)", total_named_functions, total_functions, - 100.f * float(total_named_functions) / float(total_functions)); - spdlog::info("Excluding {} asm functions", asm_funcs); - spdlog::info("Found {} basic blocks in {:.3f} ms", total_basic_blocks, timer.getMs()); - spdlog::info(" {}/{} functions passed cfg analysis stage ({:.3f}%)", resolved_cfg_functions, - non_asm_funcs, 100.f * float(resolved_cfg_functions) / float(non_asm_funcs)); + lg::info("Found {} functions ({} with no control flow)", total_functions, + total_trivial_cfg_functions); + lg::info("Named {}/{} functions ({:.3f}%)", total_named_functions, total_functions, + 100.f * float(total_named_functions) / float(total_functions)); + lg::info("Excluding {} asm functions", asm_funcs); + lg::info("Found {} basic blocks in {:.3f} ms", total_basic_blocks, timer.getMs()); + lg::info(" {}/{} functions passed cfg analysis stage ({:.3f}%)", resolved_cfg_functions, + non_asm_funcs, 100.f * float(resolved_cfg_functions) / float(non_asm_funcs)); int successful_basic_ops = total_basic_ops - total_failed_basic_ops; - spdlog::info(" {}/{} basic ops converted successfully ({:.3f}%)", successful_basic_ops, - total_basic_ops, 100.f * float(successful_basic_ops) / float(total_basic_ops)); - spdlog::info(" {}/{} basic ops with reginfo ({:.3f}%)", total_reginfo_ops, total_basic_ops, - 100.f * float(total_reginfo_ops) / float(total_basic_ops)); - spdlog::info(" {}/{} cfgs converted to ir ({:.3f}%)", successful_cfg_irs, non_asm_funcs, - 100.f * float(successful_cfg_irs) / float(non_asm_funcs)); - spdlog::info(" {}/{} functions attempted type analysis ({:.2f}%)", attempted_type_analysis, - non_asm_funcs, 100.f * float(attempted_type_analysis) / float(non_asm_funcs)); - spdlog::info(" {}/{} functions that attempted type analysis succeeded ({:.2f}%)", - successful_type_analysis, attempted_type_analysis, - 100.f * float(successful_type_analysis) / float(attempted_type_analysis)); - spdlog::info(" {}/{} functions passed type analysis ({:.2f}%)", successful_type_analysis, - non_asm_funcs, 100.f * float(successful_type_analysis) / float(non_asm_funcs)); - spdlog::info( + lg::info(" {}/{} basic ops converted successfully ({:.3f}%)", successful_basic_ops, + total_basic_ops, 100.f * float(successful_basic_ops) / float(total_basic_ops)); + lg::info(" {}/{} basic ops with reginfo ({:.3f}%)", total_reginfo_ops, total_basic_ops, + 100.f * float(total_reginfo_ops) / float(total_basic_ops)); + lg::info(" {}/{} cfgs converted to ir ({:.3f}%)", successful_cfg_irs, non_asm_funcs, + 100.f * float(successful_cfg_irs) / float(non_asm_funcs)); + lg::info(" {}/{} functions attempted type analysis ({:.2f}%)", attempted_type_analysis, + non_asm_funcs, 100.f * float(attempted_type_analysis) / float(non_asm_funcs)); + lg::info(" {}/{} functions that attempted type analysis succeeded ({:.2f}%)", + successful_type_analysis, attempted_type_analysis, + 100.f * float(successful_type_analysis) / float(attempted_type_analysis)); + lg::info(" {}/{} functions passed type analysis ({:.2f}%)", successful_type_analysis, + non_asm_funcs, 100.f * float(successful_type_analysis) / float(non_asm_funcs)); + lg::info( " {} functions were supposed to do type analysis but either failed or didn't know their " "types.\n", bad_type_analysis); @@ -1097,7 +1096,7 @@ void ObjectFileDB::analyze_functions() { } void ObjectFileDB::analyze_expressions() { - spdlog::info("- Analyzing Expressions..."); + lg::info("- Analyzing Expressions..."); Timer timer; int attempts = 0; int success = 0; @@ -1107,7 +1106,7 @@ void ObjectFileDB::analyze_expressions() { if (/*!had_failure &&*/ func.attempted_type_analysis) { attempts++; - spdlog::info("Analyze {}", func.guessed_name.to_string()); + lg::info("Analyze {}", func.guessed_name.to_string()); if (func.build_expression(data.linked_data)) { success++; } else { @@ -1117,8 +1116,8 @@ void ObjectFileDB::analyze_expressions() { } }); - spdlog::info(" {}/{} functions passed expression building ({:.2f}%)\n", success, attempts, - 100.f * float(success) / float(attempts)); + lg::info(" {}/{} functions passed expression building ({:.2f}%)\n", success, attempts, + 100.f * float(success) / float(attempts)); } void ObjectFileDB::dump_raw_objects(const std::string& output_dir) { diff --git a/decompiler/data/tpage.cpp b/decompiler/data/tpage.cpp index 32ebedd631..c51075e16a 100644 --- a/decompiler/data/tpage.cpp +++ b/decompiler/data/tpage.cpp @@ -18,7 +18,7 @@ #include "tpage.h" #include "common/versions.h" #include "decompiler/ObjectFile/ObjectFileDB.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "third-party/fmt/core.h" namespace { diff --git a/decompiler/main.cpp b/decompiler/main.cpp index df96acb166..8b89d8c10e 100644 --- a/decompiler/main.cpp +++ b/decompiler/main.cpp @@ -2,18 +2,16 @@ #include #include #include "ObjectFile/ObjectFileDB.h" +#include "common/log/log.h" #include "config.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" -#include "third-party/spdlog/include/spdlog/sinks/basic_file_sink.h" #include "common/util/FileUtil.h" int main(int argc, char** argv) { - spdlog::info("Beginning disassembly. This may take a few minutes..."); - - spdlog::set_level(spdlog::level::debug); - // auto lu = spdlog::basic_logger_mt("GOAL Decompiler", "logs/decompiler.log"); - // spdlog::set_default_logger(lu); - spdlog::flush_on(spdlog::level::info); + lg::set_file(file_util::get_file_path({"log/decompiler.txt"})); + lg::set_file_level(lg::level::info); + lg::set_stdout_level(lg::level::info); + lg::set_flush_level(lg::level::info); + lg::initialize(); file_util::init_crc(); init_opcode_info(); @@ -98,6 +96,6 @@ int main(int argc, char** argv) { file_util::write_text_file(file_util::combine_path(out_folder, "all-syms.gc"), db.dts.dump_symbol_types()); - spdlog::info("Disassembly has completed successfully."); + lg::info("Disassembly has completed successfully."); return 0; } diff --git a/decompiler/util/DecompilerTypeSystem.cpp b/decompiler/util/DecompilerTypeSystem.cpp index 90c7dd7e67..175e05880b 100644 --- a/decompiler/util/DecompilerTypeSystem.cpp +++ b/decompiler/util/DecompilerTypeSystem.cpp @@ -2,7 +2,7 @@ #include "common/goos/Reader.h" #include "common/type_system/deftype.h" #include "decompiler/Disasm/Register.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" #include "TP_Type.h" DecompilerTypeSystem::DecompilerTypeSystem() { @@ -105,9 +105,9 @@ void DecompilerTypeSystem::add_type_flags(const std::string& name, u64 flags) { auto kv = type_flags.find(name); if (kv != type_flags.end()) { if (kv->second != flags) { - spdlog::warn("duplicated type flags for {}, was 0x{:x}, now 0x{:x}", name.c_str(), kv->second, - flags); - spdlog::warn("duplicated type flags that are inconsistent!"); + lg::warn("duplicated type flags for {}, was 0x{:x}, now 0x{:x}", name.c_str(), kv->second, + flags); + lg::warn("duplicated type flags that are inconsistent!"); } } type_flags[name] = flags; @@ -117,8 +117,8 @@ void DecompilerTypeSystem::add_type_parent(const std::string& child, const std:: auto kv = type_parents.find(child); if (kv != type_parents.end()) { if (kv->second != parent) { - spdlog::warn("duplicated type parents for {} was {} now {}", child.c_str(), - kv->second.c_str(), parent.c_str()); + lg::warn("duplicated type parents for {} was {} now {}", child.c_str(), kv->second.c_str(), + parent.c_str()); throw std::runtime_error("duplicated type parents that are inconsistent!"); } } @@ -151,8 +151,8 @@ void DecompilerTypeSystem::add_symbol(const std::string& name, const TypeSpec& t } else { if (ts.typecheck(type_spec, skv->second, "", false, false)) { } else { - spdlog::warn("Attempting to redefine type of symbol {} from {} to {}\n", name, - skv->second.print(), type_spec.print()); + lg::warn("Attempting to redefine type of symbol {} from {} to {}\n", name, + skv->second.print(), type_spec.print()); throw std::runtime_error("Type redefinition"); } } diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 09f0d0cb68..43b8af155f 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -69,24 +69,17 @@ set(RUNTIME_SOURCE overlord/ssound.cpp overlord/stream.cpp) -# the runtime should be built without any static/dynamic libraries. -#add_executable(gk ${RUNTIME_SOURCE} main.cpp) - -# we also build a runtime library for testing. This version is likely unable to call GOAL code correctly, but -# can be used to test other things. +# we build the runtime as a static library. add_library(runtime ${RUNTIME_SOURCE}) -add_executable(gk main.cpp) - +target_link_libraries(runtime common fmt) IF (WIN32) - # set stuff for windows - target_link_libraries(runtime mman cross_sockets common_util spdlog cross_os_debug) - target_link_libraries(gk cross_sockets mman common_util runtime spdlog cross_os_debug) + target_link_libraries(runtime mman) ELSE() - # set stuff for other systems - target_link_libraries(runtime pthread cross_sockets common_util spdlog cross_os_debug) - target_link_libraries(gk cross_sockets pthread common_util runtime spdlog cross_os_debug) - + target_link_libraries(runtime pthread) ENDIF() +add_executable(gk main.cpp) +target_link_libraries(gk runtime) + diff --git a/game/kernel/kdgo.cpp b/game/kernel/kdgo.cpp index 9cde408e3b..fee23cf06e 100644 --- a/game/kernel/kdgo.cpp +++ b/game/kernel/kdgo.cpp @@ -17,7 +17,7 @@ #include "game/common/loader_rpc_types.h" #include "game/common/play_rpc_types.h" #include "game/common/str_rpc_types.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" using namespace ee; @@ -192,8 +192,8 @@ void BeginLoadingDGO(const char* name, Ptr buffer1, Ptr buffer2, Ptr // file name strcpy(sMsg[msgID].name, name); - spdlog::debug("[Begin Loading DGO RPC] {}, 0x{:x}, 0x{:x}, 0x{:x}", name, buffer1.offset, - buffer2.offset, currentHeap.offset); + lg::debug("[Begin Loading DGO RPC] {}, 0x{:x}, 0x{:x}, 0x{:x}", name, buffer1.offset, + buffer2.offset, currentHeap.offset); // this RPC will return once we have loaded the first object file. // but we call async, so we don't block here. RpcCall(DGO_RPC_CHANNEL, DGO_RPC_LOAD_FNO, true, mess, sizeof(RPC_Dgo_Cmd), mess, @@ -315,7 +315,7 @@ void load_and_link_dgo(u64 name_gstr, u64 heap_info, u64 flag, u64 buffer_size) * This does not use the mutli-threaded linker and will block until the entire file is done.e */ void load_and_link_dgo_from_c(const char* name, Ptr heap, u32 linkFlag, s32 bufferSize) { - spdlog::debug("[Load and Link DGO From C] {}", name); + lg::debug("[Load and Link DGO From C] {}", name); u32 oldShowStall = sShowStallMsg; // remember where the heap top point is so we can clear temporary allocations @@ -364,7 +364,7 @@ void load_and_link_dgo_from_c(const char* name, Ptr heap, u32 linkFla char objName[64]; strcpy(objName, (dgoObj + 4).cast().c()); // name from dgo object header - spdlog::debug("[link and exec] {} {}", objName, lastObjectLoaded); + lg::debug("[link and exec] {} {}", objName, lastObjectLoaded); link_and_exec(obj, objName, objSize, heap, linkFlag); // link now! // inform IOP we are done diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index c7552cdd35..5482db03f5 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -25,7 +25,7 @@ #include "game/sce/libcdvd_ee.h" #include "game/sce/stubs.h" #include "common/symbols.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" using namespace ee; /*! @@ -148,13 +148,13 @@ void InitParms(int argc, const char* const* argv) { * DONE, EXACT */ void InitCD() { - spdlog::info("Initializing CD drive. This may take a while..."); + lg::info("Initializing CD drive. This may take a while..."); sceCdInit(SCECdINIT); sceCdMmode(SCECdDVD); while (sceCdDiskReady(0) == SCECdNotReady) { - spdlog::debug("Drive not ready... insert a disk!"); + lg::debug("Drive not ready... insert a disk!"); } - spdlog::debug("Disk type {}\n", sceCdGetDiskType()); + lg::debug("Disk type {}\n", sceCdGetDiskType()); } /*! @@ -172,22 +172,22 @@ void InitIOP() { if (!reboot) { // reboot with development IOP kernel - spdlog::debug("Rebooting IOP..."); + lg::debug("Rebooting IOP..."); while (!sceSifRebootIop("host0:/usr/local/sce/iop/modules/ioprp221.img")) { - spdlog::debug("Failed, retrying"); + lg::debug("Failed, retrying"); } while (!sceSifSyncIop()) { - spdlog::debug("Syncing..."); + lg::debug("Syncing..."); } } else { // reboot with IOP kernel off of the disk // reboot with development IOP kernel - spdlog::debug("Rebooting IOP..."); + lg::debug("Rebooting IOP..."); while (!sceSifRebootIop("cdrom0:\\DRIVERS\\IOPRP221.IMG;1")) { - spdlog::debug("Failed, retrying"); + lg::debug("Failed, retrying"); } while (!sceSifSyncIop()) { - spdlog::debug("Syncing..."); + lg::debug("Syncing..."); } } @@ -238,7 +238,7 @@ void InitIOP() { sceSifLoadModule("host0:/usr/home/src/989snd10/iop/989ERR.IRX", 0, nullptr); - spdlog::debug("Initializing CD library..."); + lg::debug("Initializing CD library..."); auto rv = sceSifLoadModule("host0:binee/overlord.irx", cmd + len + 1 - overlord_boot_command, overlord_boot_command); if (rv < 0) { @@ -270,7 +270,7 @@ void InitIOP() { MsgErr("loading 989snd.irx failed\n"); } - spdlog::debug("Initializing CD library in ISO_CD mode..."); + lg::debug("Initializing CD library in ISO_CD mode..."); auto rv = sceSifLoadModule("cdrom0:\\\\DRIVERS\\\\OVERLORD.IRX;1", cmd + len + 1 - overlord_boot_command, overlord_boot_command); if (rv < 0) { @@ -281,7 +281,7 @@ void InitIOP() { if (rv < 0) { MsgErr("MC driver init failed %d\n", rv); } else { - spdlog::info("InitIOP OK"); + lg::info("InitIOP OK"); } } @@ -302,8 +302,8 @@ int InitMachine() { // initialize the global heap u32 global_heap_size = GLOBAL_HEAP_END - HEAP_START; float size_mb = ((float)global_heap_size) / (float)(1 << 20); - spdlog::info("gkernel: global heap 0x{:08x} to 0x{:08x} (size {:.3f} MB)", HEAP_START, - GLOBAL_HEAP_END, size_mb); + lg::info("gkernel: global heap 0x{:08x} to 0x{:08x} (size {:.3f} MB)", HEAP_START, + GLOBAL_HEAP_END, size_mb); kinitheap(kglobalheap, Ptr(HEAP_START), global_heap_size); // initialize the debug heap, if appropriate @@ -312,8 +312,8 @@ int InitMachine() { kinitheap(kdebugheap, Ptr(DEBUG_HEAP_START), debug_heap_size); float debug_size_mb = ((float)debug_heap_size) / (float)(1 << 20); float gap_size_mb = ((float)DEBUG_HEAP_START - GLOBAL_HEAP_END) / (float)(1 << 20); - spdlog::info("gkernel: debug heap 0x{:08x} to 0x{:08x} (size {:.3f} MB, gap {:.3f} MB)", - DEBUG_HEAP_START, debug_heap_end, debug_size_mb, gap_size_mb); + lg::info("gkernel: debug heap 0x{:08x} to 0x{:08x} (size {:.3f} MB, gap {:.3f} MB)", + DEBUG_HEAP_START, debug_heap_end, debug_size_mb, gap_size_mb); } else { // if no debug, we make the kheapinfo structure NULL so GOAL knows not to use it. kdebugheap.offset = 0; @@ -338,9 +338,9 @@ int InitMachine() { InitGoalProto(); } - spdlog::info("InitSound"); + lg::info("InitSound"); InitSound(); // do nothing! - spdlog::info("InitRPC"); + lg::info("InitRPC"); InitRPC(); // connect to IOP reset_output(); // reset output buffers clear_print(); @@ -350,9 +350,9 @@ int InitMachine() { return goal_status; } - spdlog::info("InitListenerConnect"); + lg::info("InitListenerConnect"); InitListenerConnect(); - spdlog::info("InitCheckListener"); + lg::info("InitCheckListener"); InitCheckListener(); Msg(6, "kernel: machine started\n"); return 0; @@ -619,7 +619,7 @@ void InitMachineScheme() { new_pair(s7.offset + FIX_SYM_GLOBAL_HEAP, *((s7 + FIX_SYM_PAIR_TYPE).cast()), make_string_from_c("common"), kernel_packages->value); - spdlog::info("calling fake play~"); + lg::info("calling fake play~"); call_goal_function_by_name("play"); } } diff --git a/game/kernel/kscheme.cpp b/game/kernel/kscheme.cpp index 2287d81878..40aa10ce71 100644 --- a/game/kernel/kscheme.cpp +++ b/game/kernel/kscheme.cpp @@ -20,7 +20,7 @@ #include "common/symbols.h" #include "common/versions.h" #include "common/goal_constants.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" //! Controls link mode when EnableMethodSet = 0, MasterDebug = 1, DiskBoot = 0. Will enable a //! warning message if EnableMethodSet = 1 @@ -1979,10 +1979,8 @@ s32 InitHeapAndSymbol() { (kernel_version >> 3) & 0xffff); return -1; } else { - spdlog::info("Got correct kernel version {}.{}", kernel_version >> 0x13, - (kernel_version >> 3) & 0xffff); - // printf("Got correct kernel version %d.%d\n", kernel_version >> 0x13, - // (kernel_version >> 3) & 0xffff); + lg::info("Got correct kernel version {}.{}", kernel_version >> 0x13, + (kernel_version >> 3) & 0xffff); } } diff --git a/game/main.cpp b/game/main.cpp index 3687634ebe..3d21077851 100644 --- a/game/main.cpp +++ b/game/main.cpp @@ -6,23 +6,21 @@ #include #include "runtime.h" #include "common/versions.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" -#include "third-party/spdlog/include/spdlog/sinks/basic_file_sink.h" -#include "third-party/spdlog/include/spdlog/sinks/stdout_color_sinks.h" +#include "common/log/log.h" +#include "common/util/FileUtil.h" void setup_logging(bool verbose) { - spdlog::set_level(spdlog::level::debug); + lg::set_file(file_util::get_file_path({"log/game.txt"})); if (verbose) { - auto game_logger = spdlog::stdout_color_mt("GOAL Runtime"); - spdlog::set_default_logger(game_logger); - spdlog::flush_on(spdlog::level::info); - spdlog::info("Verbose logging enabled"); + lg::set_file_level(lg::level::info); + lg::set_stdout_level(lg::level::info); + lg::set_flush_level(lg::level::info); } else { - auto game_logger = spdlog::basic_logger_mt("GOAL Runtime", "logs/runtime.log"); - spdlog::set_default_logger(game_logger); - spdlog::flush_on(spdlog::level::debug); - printf("OpenGOAL Runtime %d.%d\n", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR); + lg::set_file_level(lg::level::warn); + lg::set_stdout_level(lg::level::warn); + lg::set_flush_level(lg::level::warn); } + lg::initialize(); } int main(int argc, char** argv) { @@ -38,8 +36,7 @@ int main(int argc, char** argv) { while (true) { // run the runtime in a loop so we can reset the game and have it restart cleanly - spdlog::info("OpenGOAL Runtime {}.{}", versions::GOAL_VERSION_MAJOR, - versions::GOAL_VERSION_MINOR); + lg::info("OpenGOAL Runtime {}.{}", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR); if (exec_runtime(argc, argv) == 2) { return 0; diff --git a/game/overlord/fake_iso.cpp b/game/overlord/fake_iso.cpp index fbf1831f7b..1d4788d0eb 100644 --- a/game/overlord/fake_iso.cpp +++ b/game/overlord/fake_iso.cpp @@ -16,7 +16,7 @@ #include "isocommon.h" #include "overlord.h" #include "common/util/FileUtil.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" using namespace iop; @@ -199,7 +199,7 @@ uint32_t FS_GetLength(FileRecord* fr) { * This is an ISO FS API Function */ LoadStackEntry* FS_Open(FileRecord* fr, int32_t offset) { - spdlog::debug("[OVERLORD] FS Open {}", fr->name); + lg::debug("[OVERLORD] FS Open {}", fr->name); LoadStackEntry* selected = nullptr; // find first unused spot on load stack. for (uint32_t i = 0; i < MAX_OPEN_FILES; i++) { @@ -213,7 +213,7 @@ LoadStackEntry* FS_Open(FileRecord* fr, int32_t offset) { return selected; } } - spdlog::warn("[OVERLORD] Failed to FS Open {}", fr->name); + lg::warn("[OVERLORD] Failed to FS Open {}", fr->name); ExitIOP(); return nullptr; } @@ -224,7 +224,7 @@ LoadStackEntry* FS_Open(FileRecord* fr, int32_t offset) { * This is an ISO FS API Function */ LoadStackEntry* FS_OpenWad(FileRecord* fr, int32_t offset) { - spdlog::debug("[OVERLORD] FS_OpenWad {}", fr->name); + lg::debug("[OVERLORD] FS_OpenWad {}", fr->name); LoadStackEntry* selected = nullptr; for (uint32_t i = 0; i < MAX_OPEN_FILES; i++) { if (!sLoadStack[i].fr) { @@ -234,7 +234,7 @@ LoadStackEntry* FS_OpenWad(FileRecord* fr, int32_t offset) { return selected; } } - spdlog::warn("[OVERLORD] Failed to FS_OpenWad {}", fr->name); + lg::warn("[OVERLORD] Failed to FS_OpenWad {}", fr->name); ExitIOP(); return nullptr; } @@ -244,7 +244,7 @@ LoadStackEntry* FS_OpenWad(FileRecord* fr, int32_t offset) { * This is an ISO FS API Function */ void FS_Close(LoadStackEntry* fd) { - spdlog::debug("[OVERLORD] FS_Close {}", fd->fr->name); + lg::debug("[OVERLORD] FS_Close {}", fd->fr->name); // close the FD fd->fr = nullptr; @@ -263,7 +263,7 @@ uint32_t FS_BeginRead(LoadStackEntry* fd, void* buffer, int32_t len) { int32_t real_size = len; if (len < 0) { // not sure what this is about... - spdlog::warn("[OVERLORD ISO CD] Negative length warning!"); + lg::warn("[OVERLORD ISO CD] Negative length warning!"); real_size = len + 0x7ff; } @@ -274,7 +274,7 @@ uint32_t FS_BeginRead(LoadStackEntry* fd, void* buffer, int32_t len) { const char* path = get_file_path(fd->fr); FILE* fp = fopen(path, "rb"); if (!fp) { - spdlog::error("[OVERLORD] fake iso could not open the file \"{}\"", path); + lg::error("[OVERLORD] fake iso could not open the file \"{}\"", path); } assert(fp); fseek(fp, 0, SEEK_END); diff --git a/game/overlord/iso.cpp b/game/overlord/iso.cpp index 3f2be4ef52..b8451fb1da 100644 --- a/game/overlord/iso.cpp +++ b/game/overlord/iso.cpp @@ -4,7 +4,7 @@ * This is a huge mess */ -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" #include #include #include @@ -496,8 +496,8 @@ u32 RunDGOStateMachine(IsoMessage* _cmd, IsoBufferHeader* buffer) { // printf("[Overlord DGO] Got DGO file header for %s with %d objects\n", // cmd->dgo_header.name, // cmd->dgo_header.object_count); // added - spdlog::info("[Overlord DGO] Got DGO file header for {} with {} objects", - cmd->dgo_header.name, cmd->dgo_header.object_count); + lg::info("[Overlord DGO] Got DGO file header for {} with {} objects", + cmd->dgo_header.name, cmd->dgo_header.object_count); cmd->bytes_processed = 0; cmd->objects_loaded = 0; if (cmd->dgo_header.object_count == 1) { diff --git a/game/overlord/iso_api.cpp b/game/overlord/iso_api.cpp index fa4395dc8a..de050d0249 100644 --- a/game/overlord/iso_api.cpp +++ b/game/overlord/iso_api.cpp @@ -1,6 +1,6 @@ #include "iso_api.h" #include "game/sce/iop.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" using namespace iop; @@ -8,8 +8,7 @@ using namespace iop; * Load a File to IOP memory (blocking) */ s32 LoadISOFileToIOP(FileRecord* file, void* addr, uint32_t length) { - // printf("[OVERLORD] LoadISOFileToIOP %s, %d/%d bytes\n", file->name, length, file->size); - spdlog::debug("[OVERLORD] LoadISOFileToIOP {}, {}/{} bytes", file->name, length, file->size); + lg::debug("[OVERLORD] LoadISOFileToIOP {}, {}/{} bytes", file->name, length, file->size); IsoCommandLoadSingle cmd; cmd.cmd_id = LOAD_TO_IOP_CMD_ID; cmd.messagebox_to_reply = 0; @@ -31,8 +30,7 @@ s32 LoadISOFileToIOP(FileRecord* file, void* addr, uint32_t length) { * Load a File to IOP memory (blocking) */ s32 LoadISOFileToEE(FileRecord* file, uint32_t addr, uint32_t length) { - // printf("[OVERLORD] LoadISOFileToEE %s, %d/%d bytes\n", file->name, length, file->size); - spdlog::debug("[OVERLORD] LoadISOFileToEE {}, {}/{} bytes", file->name, length, file->size); + lg::debug("[OVERLORD] LoadISOFileToEE {}, {}/{} bytes", file->name, length, file->size); IsoCommandLoadSingle cmd; cmd.cmd_id = LOAD_TO_EE_CMD_ID; cmd.messagebox_to_reply = 0; @@ -51,7 +49,7 @@ s32 LoadISOFileToEE(FileRecord* file, uint32_t addr, uint32_t length) { } s32 LoadISOFileChunkToEE(FileRecord* file, uint32_t dest_addr, uint32_t length, uint32_t offset) { - spdlog::debug("[OVERLORD] LoadISOFileChunkToEE {} : {} offset {}\n", file->name, length, offset); + lg::debug("[OVERLORD] LoadISOFileChunkToEE {} : {} offset {}\n", file->name, length, offset); IsoCommandLoadSingle cmd; cmd.cmd_id = LOAD_TO_EE_OFFSET_CMD_ID; cmd.messagebox_to_reply = 0; diff --git a/game/overlord/iso_cd.cpp b/game/overlord/iso_cd.cpp index 2e45f64a5b..3f4399ff32 100644 --- a/game/overlord/iso_cd.cpp +++ b/game/overlord/iso_cd.cpp @@ -11,6 +11,7 @@ #include "overlord.h" #include "soundcommon.h" #include "srpc.h" +#include "common/log/log.h" // iso_cd is an implementation of the IsoFs API for loading files from a CD/DVD with an ISO and/or // DUP filesystem. @@ -231,7 +232,7 @@ u32 ReadDirectory(uint32_t sector, uint32_t size, uint32_t secBufID) { while (lsize > 0) { // ISO low-level read if (!ReadSectorsNow(lsector, 1, buffer)) { - spdlog::info("[OVERLORD ISO CD] Failed to read sector in ReadDirectory!"); + lg::info("[OVERLORD ISO CD] Failed to read sector in ReadDirectory!"); return 0; } u8* lbuffer = buffer; @@ -264,7 +265,7 @@ u32 ReadDirectory(uint32_t sector, uint32_t size, uint32_t secBufID) { } } else { if (sNumFiles == MAX_ISO_FILES) { - spdlog::info("[OVERLORD ISO CD] There are too many files on the disc!"); + lg::info("[OVERLORD ISO CD] There are too many files on the disc!"); return 0; } @@ -283,7 +284,7 @@ u32 ReadDirectory(uint32_t sector, uint32_t size, uint32_t secBufID) { lsize -= 0x800; } } else { - spdlog::info("[OVERLORD ISO CD] ReadDirectory ran out of sector buffers!"); + lg::info("[OVERLORD ISO CD] ReadDirectory ran out of sector buffers!"); } return 1; } @@ -354,7 +355,7 @@ void LoadMusicTweaks(u8* buffer) { FileRecord* fr = FS_FindIN(iso_name); if (!fr || !ReadSectorsNow(fr->location, 1, buffer)) { *(s32*)gMusicTweakInfo = 0; - spdlog::warn("[OVERLORD ISO CD] Failed to load music tweaks!"); + lg::warn("[OVERLORD ISO CD] Failed to load music tweaks!"); } else { memcpy(gMusicTweakInfo, buffer, MUSIC_TWEAK_SIZE); } @@ -373,7 +374,7 @@ void LoadDiscID() { MakeISOName(iso_name, "DISK_ID.DIZ"); FileRecord* fr = FS_FindIN(iso_name); if (!fr) { - spdlog::warn( + lg::warn( "[OVERLORD ISO CD] LoadDiscID failed to find DISK_ID.DIZ, using sector 0x400 instead!"); CD_ID_SectorNum = 0x400; } else { @@ -385,7 +386,7 @@ void LoadDiscID() { for (uint32_t i = 0; i < SECTOR_SIZE / 4; i++) { CD_ID_SectorSum += CD_ID_Sector[i]; } - spdlog::info("[OVERLORD] DISK_ID.DIZ OK 0x{:x}\n", CD_ID_SectorSum); + lg::info("[OVERLORD] DISK_ID.DIZ OK 0x{:x}\n", CD_ID_SectorSum); } /*! @@ -416,13 +417,13 @@ void SetRealSector() { } else { // it's a duplicated file, and duplicate read is enabled, so get the area 2 sector. _real_sector = _sector + sAreaDiff; - spdlog::warn("[OVERLORD] Warning, adjusting real sector in SetRealSector"); + lg::warn("[OVERLORD] Warning, adjusting real sector in SetRealSector"); } // we suspect the game is pirated, load the wrong sector. if (pirated) { _real_sector += 3; - spdlog::warn("Pirated!"); + lg::warn("Pirated!"); } } @@ -466,13 +467,13 @@ int FS_Init(u8* buffer) { // read primary volume descriptor into buffer if (!ReadSectorsNow(0x10, 1, sSecBuffer[0])) { - spdlog::warn("[OVERLORD ISO CD] Failed to read primary volume descriptor"); + lg::warn("[OVERLORD ISO CD] Failed to read primary volume descriptor"); return 1; } // check volume descriptor identifier if (memcmp(sSecBuffer[0] + 1, "CD001", 5)) { - spdlog::warn("[OVERLORD ISO CD] Got the wrong volume descriptor identifier"); + lg::warn("[OVERLORD ISO CD] Got the wrong volume descriptor identifier"); char* cptr = (char*)sSecBuffer[0] + 1; printf("%c%c%c%c%c\n", cptr[0], cptr[1], cptr[2], cptr[3], cptr[4]); return 1; @@ -482,7 +483,7 @@ int FS_Init(u8* buffer) { uint32_t path_table_sector = ReadU32(sSecBuffer[0] + 0x8c); if (!ReadSectorsNow(path_table_sector, 1, sSecBuffer[0])) { - spdlog::warn("[OVERLORD ISO CD] Failed to read path"); + lg::warn("[OVERLORD ISO CD] Failed to read path"); return 1; } @@ -490,14 +491,14 @@ int FS_Init(u8* buffer) { uint32_t path_table_extent = ReadU32(sSecBuffer[0] + 2); if (!ReadSectorsNow(path_table_extent, 1, sSecBuffer[0])) { - spdlog::warn("[OVERLORD ISO CD] Failed to read path table extent"); + lg::warn("[OVERLORD ISO CD] Failed to read path table extent"); } // read root directory add_files = true; uint32_t dir_size = ReadU32(sSecBuffer[0] + 10); if (!ReadDirectory(path_table_extent, dir_size, 0)) { - spdlog::warn("[OVERLORD ISO CD] Failed to ReadDirectory"); + lg::warn("[OVERLORD ISO CD] Failed to ReadDirectory"); return 1; } @@ -520,7 +521,7 @@ int FS_Init(u8* buffer) { } return 0; } else { - spdlog::warn("[OVERLORD ISO CD] Bad Media Type!"); + lg::warn("[OVERLORD ISO CD] Bad Media Type!"); return 1; } } @@ -567,7 +568,7 @@ FileRecord* FS_FindIN(const char* iso_name) { } // we didn't get 1 GB of files, you're a pirate. - spdlog::warn("Pirated!"); + lg::warn("Pirated!"); } } @@ -585,7 +586,7 @@ uint32_t FS_GetLength(FileRecord* fr) { * This is an ISO FS API Function */ LoadStackEntry* FS_Open(FileRecord* fr, int32_t offset) { - spdlog::info("[OVERLORD] FS Open {}", fr->name); + lg::info("[OVERLORD] FS Open {}", fr->name); LoadStackEntry* selected = nullptr; // find first unused spot on load stack. for (uint32_t i = 0; i < MAX_OPEN_FILES; i++) { @@ -599,7 +600,7 @@ LoadStackEntry* FS_Open(FileRecord* fr, int32_t offset) { return selected; } } - spdlog::warn("[OVERLORD ISO CD] Failed to FS_Open {}", fr->name); + lg::warn("[OVERLORD ISO CD] Failed to FS_Open {}", fr->name); ExitIOP(); return nullptr; } @@ -620,7 +621,7 @@ LoadStackEntry* FS_OpenWad(FileRecord* fr, int32_t offset) { return selected; } } - spdlog::warn("[OVERLORD ISO CD] Failed to use FS_OpenWad {}", fr->name); + lg::warn("[OVERLORD ISO CD] Failed to use FS_OpenWad {}", fr->name); ExitIOP(); return nullptr; } @@ -630,7 +631,7 @@ LoadStackEntry* FS_OpenWad(FileRecord* fr, int32_t offset) { * This is an ISO FS API Function */ void FS_Close(LoadStackEntry* fd) { - spdlog::info("[OVERLORD] FS Close {}", fd->fr->name); + lg::info("[OVERLORD] FS Close {}", fd->fr->name); if (fd == sReadInfo) { // the file is currently being read, so lets try to finish out the read, if possible. int count = 0; @@ -663,7 +664,7 @@ uint32_t FS_BeginRead(LoadStackEntry* fd, void* buffer, int32_t len) { int32_t real_size = len; if (len < 0) { // not sure what this is about... - spdlog::warn("[OVERLORD ISO CD] Negative length warning!"); + lg::warn("[OVERLORD ISO CD] Negative length warning!"); real_size = len + 0x7ff; } _sectors = real_size >> 11; diff --git a/game/overlord/iso_queue.cpp b/game/overlord/iso_queue.cpp index 63b4b62e8a..e0612f8af9 100644 --- a/game/overlord/iso_queue.cpp +++ b/game/overlord/iso_queue.cpp @@ -1,6 +1,7 @@ #include #include #include +#include "common/log/log.h" #include "game/sce/iop.h" #include "iso_queue.h" #include "isocommon.h" @@ -179,11 +180,11 @@ u32 QueueMessage(IsoMessage* cmd, int32_t priority, const char* name) { gPriStack[priority].cmds[gPriStack[priority].n] = cmd; gPriStack[priority].names[gPriStack[priority].n] = name; gPriStack[priority].n++; - spdlog::debug("[OVERLORD] Queue {} ({}/{}), {}", priority, gPriStack[priority].n, - PRI_STACK_LENGTH, gPriStack[priority].names[gPriStack[priority].n - 1].c_str()); + lg::debug("[OVERLORD] Queue {} ({}/{}), {}", priority, gPriStack[priority].n, PRI_STACK_LENGTH, + gPriStack[priority].names[gPriStack[priority].n - 1].c_str()); DisplayQueue(); } else { - spdlog::warn("[OVERLORD ISO QUEUE] Failed to queue!"); + lg::warn("[OVERLORD ISO QUEUE] Failed to queue!"); cmd->status = CMD_STATUS_FAILED_TO_QUEUE; ReturnMessage(cmd); } @@ -209,7 +210,7 @@ void UnqueueMessage(IsoMessage* cmd) { } } } - spdlog::warn("[OVERLORD ISO QUEUE] Failed to unqueue!"); + lg::warn("[OVERLORD ISO QUEUE] Failed to unqueue!"); found: assert(gPriStack[pri].cmds[idx] == cmd); diff --git a/game/overlord/stream.cpp b/game/overlord/stream.cpp index 0fdc5acc4b..3a677da24e 100644 --- a/game/overlord/stream.cpp +++ b/game/overlord/stream.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "stream.h" #include "game/sce/iop.h" #include "game/common/str_rpc_types.h" diff --git a/game/runtime.cpp b/game/runtime.cpp index 002ede5b44..0520b2cbf3 100644 --- a/game/runtime.cpp +++ b/game/runtime.cpp @@ -16,6 +16,7 @@ #include #include +#include "common/log/log.h" #include "runtime.h" #include "system/SystemThread.h" #include "sce/libcdvd_ee.h" @@ -72,21 +73,21 @@ void deci2_runner(SystemThreadInterface& iface) { iface.initialization_complete(); // in our own thread, wait for the EE to register the first protocol driver - spdlog::debug("[DECI2] Waiting for EE to register protos"); + lg::debug("[DECI2] Waiting for EE to register protos"); server.wait_for_protos_ready(); // then allow the server to accept connections if (!server.init()) { assert(false); } - spdlog::debug("[DECI2] Waiting for listener..."); - // spdlog::debug("[DECI2] Waiting for listener..."); --> disabled temporarily, some weird race + lg::debug("[DECI2] Waiting for listener..."); + // lg::debug("[DECI2] Waiting for listener..."); --> disabled temporarily, some weird race // condition? bool saw_listener = false; while (!iface.get_want_exit()) { if (server.check_for_listener()) { if (!saw_listener) { - spdlog::debug("[DECI2] Connected!"); + lg::debug("[DECI2] Connected!"); } saw_listener = true; // we have a listener, run! @@ -116,19 +117,19 @@ void ee_runner(SystemThreadInterface& iface) { } if (g_ee_main_mem == (u8*)(-1)) { - spdlog::debug("Failed to initialize main memory! {}", strerror(errno)); + lg::debug("Failed to initialize main memory! {}", strerror(errno)); iface.initialization_complete(); return; } - spdlog::debug("Main memory mapped at 0x{:016x}", (u64)(g_ee_main_mem)); - spdlog::debug("Main memory size 0x{:x} bytes ({:.3f} MB)", EE_MAIN_MEM_SIZE, - (double)EE_MAIN_MEM_SIZE / (1 << 20)); + lg::debug("Main memory mapped at 0x{:016x}", (u64)(g_ee_main_mem)); + lg::debug("Main memory size 0x{:x} bytes ({:.3f} MB)", EE_MAIN_MEM_SIZE, + (double)EE_MAIN_MEM_SIZE / (1 << 20)); - spdlog::debug("[EE] Initialization complete!"); + lg::debug("[EE] Initialization complete!"); iface.initialization_complete(); - spdlog::debug("[EE] Run!"); + lg::debug("[EE] Run!"); memset((void*)g_ee_main_mem, 0, EE_MAIN_MEM_SIZE); // prevent access to the first 1 MB of memory. @@ -153,7 +154,7 @@ void ee_runner(SystemThreadInterface& iface) { xdbg::allow_debugging(); goal_main(g_argc, g_argv); - spdlog::debug("[EE] Done!"); + lg::debug("[EE] Done!"); // // kill the IOP todo iop::LIBRARY_kill(); @@ -169,7 +170,7 @@ void ee_runner(SystemThreadInterface& iface) { */ void iop_runner(SystemThreadInterface& iface) { IOP iop; - spdlog::debug("[IOP] Restart!"); + lg::debug("[IOP] Restart!"); iop.reset_allocator(); ee::LIBRARY_sceSif_register(&iop); iop::LIBRARY_register(&iop); @@ -192,12 +193,12 @@ void iop_runner(SystemThreadInterface& iface) { iface.initialization_complete(); - spdlog::debug("[IOP] Wait for OVERLORD to start..."); + lg::debug("[IOP] Wait for OVERLORD to start..."); iop.wait_for_overlord_start_cmd(); if (iop.status == IOP_OVERLORD_INIT) { - spdlog::debug("[IOP] Run!"); + lg::debug("[IOP] Run!"); } else { - spdlog::debug("[IOP] Shutdown!"); + lg::debug("[IOP] Shutdown!"); return; } @@ -259,6 +260,6 @@ u32 exec_runtime(int argc, char** argv) { // join and exit tm.join(); - spdlog::info("GOAL Runtime Shutdown (code {})", MasterExit); + lg::info("GOAL Runtime Shutdown (code {})", MasterExit); return MasterExit; } diff --git a/game/sce/deci2.cpp b/game/sce/deci2.cpp index 1eafb96530..97f37aa717 100644 --- a/game/sce/deci2.cpp +++ b/game/sce/deci2.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "common/log/log.h" #include "deci2.h" #include "game/system/Deci2Server.h" @@ -69,8 +70,7 @@ s32 sceDeci2Open(u16 protocol, void* opt, void (*handler)(s32 event, s32 param, drv.id = protocol_count + 1; drv.active = true; protocols[protocol_count++] = drv; - // printf("[DECI2] Add new protocol driver %d for 0x%x\n", drv.id, drv.protocol); - spdlog::info("[DECI2] Add new protocol driver {} for 0x{:x}", drv.id, drv.protocol); + lg::info("[DECI2] Add new protocol driver {} for 0x{:x}", drv.id, drv.protocol); server->unlock(); if (protocol_count == 1) { diff --git a/game/sce/iop.h b/game/sce/iop.h index 4638b799f3..f0ced35b3d 100644 --- a/game/sce/iop.h +++ b/game/sce/iop.h @@ -4,7 +4,6 @@ #define JAK1_IOP_H #include "common/common_types.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" #define SMEM_Low (0) #define SMEM_High (1) diff --git a/game/system/Deci2Server.h b/game/system/Deci2Server.h index 7c888a188b..1bd164ffe6 100644 --- a/game/system/Deci2Server.h +++ b/game/system/Deci2Server.h @@ -19,7 +19,6 @@ #include #include #include "game/system/deci_common.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" class Deci2Server { public: diff --git a/game/system/SystemThread.cpp b/game/system/SystemThread.cpp index f7089f2c19..d9cf546cec 100644 --- a/game/system/SystemThread.cpp +++ b/game/system/SystemThread.cpp @@ -3,7 +3,7 @@ #endif #include "SystemThread.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" +#include "common/log/log.h" ////////////////////// // Thread Manager // @@ -14,7 +14,7 @@ */ SystemThread& SystemThreadManager::create_thread(const std::string& name) { if (thread_count >= MAX_SYSTEM_THREADS) { - spdlog::critical("Out of System Threads! MAX_SYSTEM_THREADS is ", MAX_SYSTEM_THREADS); + lg::die("Out of System Threads! MAX_SYSTEM_THREADS is ", MAX_SYSTEM_THREADS); assert(false); } auto& thread = threads[thread_count]; @@ -51,7 +51,7 @@ void SystemThreadManager::print_stats() { */ void SystemThreadManager::shutdown() { for (int i = 0; i < thread_count; i++) { - spdlog::debug("# Stop {}", threads[i].name.c_str()); + lg::debug("# Stop {}", threads[i].name.c_str()); threads[i].stop(); } } @@ -61,7 +61,7 @@ void SystemThreadManager::shutdown() { */ void SystemThreadManager::join() { for (int i = 0; i < thread_count; i++) { - spdlog::debug(" # Join {}", threads[i].name.c_str()); + lg::debug(" # Join {}", threads[i].name.c_str()); if (threads[i].running) { threads[i].join(); } @@ -75,7 +75,7 @@ void* bootstrap_thread_func(void* x) { SystemThread* thd = (SystemThread*)x; SystemThreadInterface iface(thd); thd->function(iface); - spdlog::debug("[SYSTEM] Thread {} is returning", thd->name.c_str()); + lg::debug("[SYSTEM] Thread {} is returning", thd->name.c_str()); return nullptr; } @@ -83,7 +83,7 @@ void* bootstrap_thread_func(void* x) { * Start a thread and wait for its initialization */ void SystemThread::start(std::function f) { - spdlog::debug("# Initialize {}...", name.c_str()); + lg::debug("# Initialize {}...", name.c_str()); function = f; thread = std::thread(bootstrap_thread_func, this); @@ -121,7 +121,7 @@ void SystemThreadInterface::initialization_complete() { std::unique_lock mlk(thread.initialization_mutex); thread.initialization_complete = true; thread.initialization_cv.notify_all(); - spdlog::debug("# {} initialized", thread.name.c_str()); + lg::debug("# {} initialized", thread.name.c_str()); } /*! diff --git a/goalc/CMakeLists.txt b/goalc/CMakeLists.txt index 5ae0681279..88c22b31a7 100644 --- a/goalc/CMakeLists.txt +++ b/goalc/CMakeLists.txt @@ -38,12 +38,13 @@ add_library(compiler compiler/Compiler.cpp compiler/compilation/Asm.cpp) -add_executable(goalc main.cpp) +target_link_libraries(compiler common Zydis) IF (WIN32) - target_link_libraries(compiler goos type_system mman common_util spdlog cross_os_debug cross_sockets Zydis) -ELSE () - target_link_libraries(compiler goos type_system common_util spdlog cross_os_debug cross_sockets Zydis) + target_link_libraries(compiler mman) ENDIF () -target_link_libraries(goalc goos compiler type_system) \ No newline at end of file +add_executable(goalc main.cpp) +target_link_libraries(goalc common Zydis compiler) + + diff --git a/goalc/compiler/compilation/CompilerControl.cpp b/goalc/compiler/compilation/CompilerControl.cpp index 0911e7924c..d136ef9925 100644 --- a/goalc/compiler/compilation/CompilerControl.cpp +++ b/goalc/compiler/compilation/CompilerControl.cpp @@ -151,7 +151,7 @@ Val* Compiler::compile_asm_file(const goos::Object& form, const goos::Object& re if (m_listener.is_connected()) { m_listener.send_code(data); } else { - printf("WARNING - couldn't load because listener isn't connected\n"); // todo spdlog warn + printf("WARNING - couldn't load because listener isn't connected\n"); // todo log warn } } diff --git a/goalc/main.cpp b/goalc/main.cpp index afda7a3afe..0e64ef135a 100644 --- a/goalc/main.cpp +++ b/goalc/main.cpp @@ -1,24 +1,21 @@ #include #include "goalc/compiler/Compiler.h" #include "common/versions.h" -#include "third-party/spdlog/include/spdlog/spdlog.h" -#include "third-party/spdlog/include/spdlog/sinks/basic_file_sink.h" -#include "third-party/spdlog/include/spdlog/sinks/stdout_color_sinks.h" +#include "common/util/FileUtil.h" +#include "common/log/log.h" void setup_logging(bool verbose) { - spdlog::set_level(spdlog::level::debug); + lg::set_file(file_util::get_file_path({"log/compiler.txt"})); if (verbose) { - auto game_logger = spdlog::stdout_color_mt("GOAL Compiler"); - spdlog::set_default_logger(game_logger); - spdlog::flush_on(spdlog::level::info); - spdlog::set_pattern("%v"); - spdlog::info("Verbose logging enabled"); + lg::set_file_level(lg::level::info); + lg::set_stdout_level(lg::level::info); + lg::set_flush_level(lg::level::info); } else { - auto game_logger = spdlog::basic_logger_mt("GOAL Compiler", "logs/compiler.log"); - spdlog::set_default_logger(game_logger); - spdlog::flush_on(spdlog::level::debug); - printf("OpenGOAL Compiler %d.%d\n", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR); + lg::set_file_level(lg::level::warn); + lg::set_stdout_level(lg::level::warn); + lg::set_flush_level(lg::level::warn); } + lg::initialize(); } int main(int argc, char** argv) { @@ -39,8 +36,7 @@ int main(int argc, char** argv) { } setup_logging(verbose); - spdlog::info("OpenGOAL Compiler {}.{}", versions::GOAL_VERSION_MAJOR, - versions::GOAL_VERSION_MINOR); + lg::info("OpenGOAL Compiler {}.{}", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR); Compiler compiler; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index e28c251adc..dbfb05031e 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,13 +23,11 @@ add_executable(goalc-test enable_testing() +target_link_libraries(goalc-test common runtime compiler gtest Zydis) + IF (WIN32) set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - - # TODO - split out these declarations for platform specific includes - target_link_libraries(goalc-test cross_sockets goos common_util runtime compiler type_system gtest mman Zydis) -ELSE() - target_link_libraries(goalc-test cross_sockets goos common_util runtime compiler type_system gtest Zydis) + target_link_libraries(goalc-test mman) ENDIF() if(UNIX AND CMAKE_COMPILER_IS_GNUCXX AND CODE_COVERAGE) diff --git a/third-party/fmt/CMakeLists.txt b/third-party/fmt/CMakeLists.txt index 7c1a01067d..61e661d329 100644 --- a/third-party/fmt/CMakeLists.txt +++ b/third-party/fmt/CMakeLists.txt @@ -5,4 +5,5 @@ else () endif (UNIX) include_directories(../) -add_library(fmt SHARED format.cc) \ No newline at end of file +add_library(fmt SHARED format.cc) +target_compile_definitions(fmt PRIVATE FMT_EXPORT INTERFACE FMT_SHARED) \ No newline at end of file diff --git a/third-party/spdlog b/third-party/spdlog deleted file mode 160000 index cbe9448650..0000000000 --- a/third-party/spdlog +++ /dev/null @@ -1 +0,0 @@ -Subproject commit cbe9448650176797739dbab13961ef4c07f4290f