feat: added header for link functions

This commit is contained in:
Ran-j
2025-04-14 01:41:22 -03:00
parent a877f2a33e
commit 8c0af4e224
3 changed files with 44 additions and 10 deletions
@@ -46,6 +46,7 @@ namespace ps2recomp
bool shouldSkipFunction(const std::string &name) const;
std::string generateRuntimeHeader();
std::string generateStubFunction(const Function& function);
bool generateFunctionHeader();
bool writeToFile(const std::string &path, const std::string &content);
std::filesystem::path getOutputPath(const Function &function) const;
};
+2 -1
View File
@@ -396,7 +396,8 @@ namespace ps2recomp
std::stringstream ss;
ss << "#include \"ps2_runtime_macros.h\"\n";
ss << "#include \"ps2_runtime.h\"\n\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";
+41 -9
View File
@@ -72,20 +72,14 @@ namespace ps2recomp
size_t processedCount = 0;
for (auto &function : m_functions)
{
std::cout << "processing function: " << function.name << std::endl;
if (shouldSkipFunction(function.name))
{
std::cout << "Skipping function: " << function.name << std::endl;
continue;
}
if (shouldStubFunction(function.name))
{
std::cout << "Stubbing function: " << function.name << std::endl;
function.isStub = true;
// TODO: Generate stub implementation
continue;
}
if (shouldStubFunction(function.name))
{
std::cout << "Stubbing function: " << function.name << std::endl;
@@ -129,12 +123,15 @@ namespace ps2recomp
{
try
{
generateFunctionHeader();
if (m_config.singleFileOutput)
{
std::stringstream combinedOutput;
combinedOutput << "#include \"ps2_runtime_macros.h\"\n";
combinedOutput << "#include \"ps2_runtime.h\"\n\n";
combinedOutput << "#include \"ps2_runtime.h\"\n";
combinedOutput << "#include \"ps2_recompiled_functions.h\"\n\n";
for (const auto &function : m_functions)
{
@@ -193,6 +190,41 @@ namespace ps2recomp
}
}
bool PS2Recompiler::generateFunctionHeader()
{
try
{
std::stringstream ss;
ss << "#ifndef PS2_RECOMPILED_FUNCTIONS_H\n";
ss << "#define PS2_RECOMPILED_FUNCTIONS_H\n\n";
ss << "#include <cstdint>\n\n";
ss << "struct R5900Context;\n\n";
for (const auto &function : m_functions)
{
if (function.isRecompiled)
{
ss << "void " << function.name << "(uint8_t* rdram, R5900Context* ctx);\n";
}
}
ss << "\n#endif // PS2_RECOMPILED_FUNCTIONS_H\n";
fs::path headerPath = fs::path(m_config.outputPath) / "ps2_recompiled_functions.h";
writeToFile(headerPath.string(), ss.str());
std::cout << "Generated function header file: " << headerPath << std::endl;
return true;
}
catch (const std::exception &e)
{
std::cerr << "Error generating function header: " << e.what() << std::endl;
return false;
}
}
bool PS2Recompiler::decodeFunction(Function &function)
{
std::vector<Instruction> instructions;