mirror of
https://github.com/ran-j/PS2Recomp.git
synced 2026-10-01 18:31:21 -04:00
feat: now we generate header file for stub functions
This commit is contained in:
@@ -479,7 +479,8 @@ namespace ps2recomp
|
||||
{
|
||||
ss << "#include \"ps2_runtime_macros.h\"\n";
|
||||
ss << "#include \"ps2_runtime.h\"\n";
|
||||
ss << "#include \"ps2_recompiled_functions.h\"\n\n";
|
||||
ss << "#include \"ps2_recompiled_functions.h\"\n";
|
||||
ss << "#include \"ps2_recompiled_stubs.h\"\n\n";
|
||||
}
|
||||
|
||||
ss << "// Function: " << function.name << "\n";
|
||||
|
||||
@@ -20,11 +20,13 @@ namespace ps2recomp
|
||||
|
||||
try
|
||||
{
|
||||
std::cout << "Parsing toml file: " << m_configPath << std::endl;
|
||||
auto data = toml::parse(m_configPath);
|
||||
|
||||
config.inputPath = toml::find<std::string>(data, "general", "input");
|
||||
config.outputPath = toml::find<std::string>(data, "general", "output");
|
||||
config.singleFileOutput = toml::find<bool>(data, "general", "single_file_output");
|
||||
config.stubImplementations = toml::find<std::vector<std::string>>(data, "general", "stubs");
|
||||
|
||||
config.skipFunctions = toml::find<std::vector<std::string>>(data, "general", "skip");
|
||||
|
||||
@@ -46,17 +48,6 @@ namespace ps2recomp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (data.contains("stubs") && data.at("stubs").is_table())
|
||||
{
|
||||
const auto &stubImpls = toml::find(data, "stubs");
|
||||
for (const auto &item : stubImpls.as_table())
|
||||
{
|
||||
const std::string &funcName = item.first;
|
||||
const std::string &implementation = toml::find<std::string>(stubImpls, funcName);
|
||||
config.stubImplementations[funcName] = implementation;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
@@ -98,12 +89,7 @@ namespace ps2recomp
|
||||
|
||||
if (!config.stubImplementations.empty())
|
||||
{
|
||||
toml::table stubImpls;
|
||||
for (const auto &impl : config.stubImplementations)
|
||||
{
|
||||
stubImpls[impl.first] = impl.second;
|
||||
}
|
||||
data["stubs"] = stubImpls;
|
||||
data["stubs"] = config.stubImplementations;
|
||||
}
|
||||
|
||||
std::ofstream file(m_configPath);
|
||||
|
||||
@@ -119,6 +119,7 @@ namespace ps2recomp
|
||||
combinedOutput << "#include \"ps2_recompiled_functions.h\"\n\n";
|
||||
combinedOutput << "#include \"ps2_runtime_macros.h\"\n";
|
||||
combinedOutput << "#include \"ps2_runtime.h\"\n";
|
||||
combinedOutput << "#include \"ps2_recompiled_stubs.h\"\n";
|
||||
|
||||
for (const auto &function : m_functions)
|
||||
{
|
||||
@@ -199,6 +200,8 @@ namespace ps2recomp
|
||||
fs::path registerPath = fs::path(m_config.outputPath) / "register_functions.cpp";
|
||||
writeToFile(registerPath.string(), registerFunctions);
|
||||
std::cout << "Generated function registration file: " << registerPath << std::endl;
|
||||
|
||||
generateStubHeader();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
@@ -206,6 +209,40 @@ namespace ps2recomp
|
||||
}
|
||||
}
|
||||
|
||||
bool PS2Recompiler::generateStubHeader()
|
||||
{
|
||||
try
|
||||
{
|
||||
std::stringstream ss;
|
||||
|
||||
ss << "#pragma once\n\n";
|
||||
ss << "#include <cstdint>\n";
|
||||
ss << "#include \"ps2_runtime.h\"\n";
|
||||
ss << "#include \"ps2_syscalls.h\"\n\n";
|
||||
ss << "namespace ps2recomp {\n";
|
||||
ss << "namespace stubs {\n\n";
|
||||
|
||||
for (const auto &funcName : m_config.stubImplementations)
|
||||
{
|
||||
ss << "void " << funcName << "(uint8_t* rdram, R5900Context* ctx, PS2Runtime* runtime) { ps2_syscalls::TODO(rdram, ctx, runtime); }\n";
|
||||
}
|
||||
|
||||
ss << "\n} // namespace stubs\n";
|
||||
ss << "} // namespace ps2recomp\n";
|
||||
|
||||
fs::path headerPath = fs::path(m_config.outputPath) / "ps2_recompiled_stubs.h";
|
||||
writeToFile(headerPath.string(), ss.str());
|
||||
|
||||
std::cout << "Generated generating header file: " << headerPath << std::endl;
|
||||
return true;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
std::cerr << "Error generating stub header: " << e.what() << std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool PS2Recompiler::generateFunctionHeader()
|
||||
{
|
||||
try
|
||||
|
||||
Reference in New Issue
Block a user