Saving to separate files.

This commit is contained in:
Skyth 2024-09-18 13:31:37 +03:00
parent 618cc75198
commit 5a16d14d30
2 changed files with 54 additions and 9 deletions

View File

@ -136,18 +136,61 @@ int main()
out += '\n';
};
println("#include <ppc_context.h>\n");
std::filesystem::create_directory("out");
for (auto& symbol : image.symbols)
println("PPC_FUNC void {}(PPCContext& __restrict ctx, uint8_t* base);", symbol.name);
size_t cppFileIndex = 0;
println("");
auto saveFile = [&](std::string name = "")
{
if (!out.empty())
{
if (name.empty())
{
name = std::format("out/ppc_recomp.{}.cpp", cppFileIndex);
++cppFileIndex;
}
FILE* f = fopen(name.c_str(), "wb");
fwrite(out.data(), 1, out.size(), f);
fclose(f);
out.clear();
}
};
{
println("#pragma once\n");
println("#include <ppc_context.h>\n");
for (auto& symbol : image.symbols)
println("PPC_FUNC void {}(PPCContext& __restrict ctx, uint8_t* base);", symbol.name);
saveFile("out/ppc_recomp_shared.h");
}
{
println("#include \"ppc_recomp_shared.h\"\n");
println("extern \"C\" __declspec(dllexport) PPCFuncMapping PPCFuncMapping[] = {{");
for (auto& symbol : image.symbols)
println("\t{{ 0x{:X}, {} }},", symbol.address, symbol.name);
println("\t{{ 0, nullptr }}");
println("}};");
saveFile("out/ppc_func_mapping.cpp");
}
for (size_t funcIdx = 0; funcIdx < functions.size(); funcIdx++)
{
if ((funcIdx % 1000) == 0)
{
std::println("Recompiling functions... {}%", static_cast<float>(funcIdx) / functions.size() * 100.0f);
saveFile();
println("#include \"ppc_recomp_shared.h\"\n");
}
auto& fn = functions[funcIdx];
auto base = fn.base;
auto end = base + fn.size;
@ -1687,11 +1730,7 @@ int main()
println("}}\n");
}
std::filesystem::create_directory("out");
FILE* f = fopen("out/" TEST_FILE ".cpp", "w");
fwrite(out.data(), 1, out.size(), f);
fclose(f);
saveFile();
return 0;
}

View File

@ -32,6 +32,12 @@
typedef void PPCFunc(struct PPCContext& __restrict ctx, uint8_t* base);
struct PPCFuncMapping
{
size_t guest;
PPCFunc* host;
};
struct PPCRegister
{
union