From e5cef40032a07a447f49bcb38e6cb84223cb94a6 Mon Sep 17 00:00:00 2001 From: Ran-j Date: Mon, 14 Apr 2025 02:02:56 -0300 Subject: [PATCH] fix: fix recompile from single file to multi file --- ps2xRecomp/include/ps2recomp/code_generator.h | 6 +++--- ps2xRecomp/src/code_generator.cpp | 11 +++++++---- ps2xRecomp/src/ps2_recompiler.cpp | 10 ++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ps2xRecomp/include/ps2recomp/code_generator.h b/ps2xRecomp/include/ps2recomp/code_generator.h index e1f7dde..140a2b4 100644 --- a/ps2xRecomp/include/ps2recomp/code_generator.h +++ b/ps2xRecomp/include/ps2recomp/code_generator.h @@ -14,7 +14,7 @@ namespace ps2recomp CodeGenerator(const std::vector &symbols); ~CodeGenerator(); - std::string generateFunction(const Function &function, const std::vector &instructions); + std::string generateFunction(const Function &function, const std::vector &instructions, const bool &useHeaders); std::string generateMacroHeader(); std::string handleBranchDelaySlots(const Instruction &branchInst, const Instruction &delaySlot); @@ -24,8 +24,8 @@ namespace ps2recomp std::string translateInstruction(const Instruction &inst); std::string translateMMIInstruction(const Instruction &inst); std::string translateVUInstruction(const Instruction &inst); - std::string translateFPUInstruction(const Instruction& inst); - std::string translateCOP0Instruction(const Instruction& inst); + std::string translateFPUInstruction(const Instruction &inst); + std::string translateCOP0Instruction(const Instruction &inst); std::string generateJumpTableSwitch(const Instruction &inst, uint32_t tableAddress, const std::vector &entries); diff --git a/ps2xRecomp/src/code_generator.cpp b/ps2xRecomp/src/code_generator.cpp index 3b623d8..70053d7 100644 --- a/ps2xRecomp/src/code_generator.cpp +++ b/ps2xRecomp/src/code_generator.cpp @@ -391,13 +391,16 @@ namespace ps2recomp return ss.str(); } - std::string CodeGenerator::generateFunction(const Function &function, const std::vector &instructions) + std::string CodeGenerator::generateFunction(const Function &function, const std::vector &instructions, const bool &useHeaders) { std::stringstream ss; - ss << "#include \"ps2_runtime_macros.h\"\n"; - ss << "#include \"ps2_runtime.h\"\n"; - ss << "#include \"ps2_recompiled_functions.h\"\n\n"; + if (useHeaders) + { + ss << "#include \"ps2_runtime_macros.h\"\n"; + ss << "#include \"ps2_runtime.h\"\n"; + ss << "#include \"ps2_recompiled_functions.h\"\n\n"; + } ss << "// Function: " << function.name << "\n"; ss << "// Address: 0x" << std::hex << function.start << " - 0x" << function.end << std::dec << "\n"; diff --git a/ps2xRecomp/src/ps2_recompiler.cpp b/ps2xRecomp/src/ps2_recompiler.cpp index 93ed5a2..277a6f8 100644 --- a/ps2xRecomp/src/ps2_recompiler.cpp +++ b/ps2xRecomp/src/ps2_recompiler.cpp @@ -123,15 +123,12 @@ namespace ps2recomp { try { - generateFunctionHeader(); - if (m_config.singleFileOutput) { std::stringstream combinedOutput; combinedOutput << "#include \"ps2_runtime_macros.h\"\n"; - combinedOutput << "#include \"ps2_runtime.h\"\n"; - combinedOutput << "#include \"ps2_recompiled_functions.h\"\n\n"; + combinedOutput << "#include \"ps2_runtime.h\"\n\n"; for (const auto &function : m_functions) { @@ -147,7 +144,7 @@ namespace ps2recomp else { const auto &instructions = m_decodedFunctions[function.start]; - std::string code = m_codeGenerator->generateFunction(function, instructions); + std::string code = m_codeGenerator->generateFunction(function, instructions, false); combinedOutput << code << "\n\n"; } } @@ -158,6 +155,7 @@ namespace ps2recomp } else { + generateFunctionHeader(); for (const auto &function : m_functions) { if (!function.isRecompiled || function.isStub) @@ -173,7 +171,7 @@ namespace ps2recomp else { const auto &instructions = m_decodedFunctions[function.start]; - code = m_codeGenerator->generateFunction(function, instructions); + code = m_codeGenerator->generateFunction(function, instructions, true); } fs::path outputPath = getOutputPath(function);