diff --git a/PowerRecomp/recompiler.cpp b/PowerRecomp/recompiler.cpp index 8d0abfc..0269dbf 100644 --- a/PowerRecomp/recompiler.cpp +++ b/PowerRecomp/recompiler.cpp @@ -1920,6 +1920,29 @@ bool Recompiler::Recompile(const Function& fn) auto end = base + fn.size; auto* data = (uint32_t*)image.Find(base); + static std::unordered_set labels; + labels.clear(); + + for (size_t addr = base; addr < end; addr += 4) + { + const uint32_t instruction = std::byteswap(*(uint32_t*)((char*)data + addr - base)); + if (!PPC_BL(instruction)) + { + const size_t op = PPC_OP(instruction); + if (op == PPC_OP_B) + labels.emplace(addr + PPC_BI(instruction)); + else if (op == PPC_OP_BC) + labels.emplace(addr + PPC_BD(instruction)); + } + + auto switchTable = switchTables.find(addr); + if (switchTable != switchTables.end()) + { + for (auto label : switchTable->second.labels) + labels.emplace(label); + } + } + auto symbol = image.symbols.find(fn.base); if (symbol != image.symbols.end()) { @@ -1937,13 +1960,15 @@ bool Recompiler::Recompile(const Function& fn) // TODO: the printing scheme here is scuffed RecompilerLocalVariables localVariables; + static std::string tempString; tempString.clear(); std::swap(out, tempString); ppc_insn insn; while (base < end) { - println("loc_{:X}:", base); + if (labels.contains(base)) + println("loc_{:X}:", base); if (switchTable == switchTables.end()) switchTable = switchTables.find(base); @@ -2122,6 +2147,8 @@ void Recompiler::SaveCurrentOutData(const char* directoryPath, const std::string FILE* f = fopen(filePath.c_str(), "rb"); if (f) { + static std::vector temp; + fseek(f, 0, SEEK_END); long fileSize = ftell(f); if (fileSize == out.size()) diff --git a/PowerRecomp/recompiler.h b/PowerRecomp/recompiler.h index 6d61cb6..f4e6fa4 100644 --- a/PowerRecomp/recompiler.h +++ b/PowerRecomp/recompiler.h @@ -41,8 +41,6 @@ struct Recompiler std::unordered_map switchTables; std::string out; size_t cppFileIndex = 0; - std::vector temp; - std::string tempString; uint32_t setJmpAddress = 0; uint32_t longJmpAddress = 0; RecompilerConfig config; diff --git a/PowerSample/CMakeLists.txt b/PowerSample/CMakeLists.txt index a25b2b4..7f99324 100644 --- a/PowerSample/CMakeLists.txt +++ b/PowerSample/CMakeLists.txt @@ -3,9 +3,7 @@ project("PowerSample") add_compile_options( "/fp:strict" "-march=x86-64-v3" - "-fno-strict-aliasing" - "-Wno-unused-label" - "-Wno-unused-variable") + "-fno-strict-aliasing") file(GLOB RecompiledFiles *.cpp) add_library(PowerSample ${RecompiledFiles}) diff --git a/PowerTests/.gitignore b/PowerTests/.gitignore new file mode 100644 index 0000000..cd92b3c --- /dev/null +++ b/PowerTests/.gitignore @@ -0,0 +1 @@ +*.cpp \ No newline at end of file