Made recompilation header include configurable

This commit is contained in:
Mr-Wiseguy 2024-08-13 02:14:34 -04:00 committed by Wiseguy
parent dfd90057c9
commit 4161ef68cc
4 changed files with 25 additions and 11 deletions

View file

@ -85,6 +85,7 @@ namespace RecompPort {
std::vector<FunctionSize> manual_func_sizes;
std::vector<ManualFunction> manual_functions;
std::string bss_section_suffix;
std::string recomp_include;
Config(const char* path);
bool good() { return !bad; }

View file

@ -408,6 +408,14 @@ RecompPort::Config::Config(const char* path) {
unpaired_lo16_warnings = true;
}
std::optional<std::string> recomp_include_opt = input_data["recomp_include"].value<std::string>();
if (recomp_include_opt.has_value()) {
recomp_include = recomp_include_opt.value();
}
else {
recomp_include = "#include \"librecomp/recomp.h\"";
}
// Patches section (optional)
toml::node_view patches_data = config_data["patches"];
if (patches_data.is_table()) {

View file

@ -1683,12 +1683,13 @@ int main(int argc, char** argv) {
std::ofstream func_header_file{ config.output_func_path / "funcs.h" };
fmt::print(func_header_file,
"#include \"librecomp/recomp.h\"\n"
"{}\n"
"\n"
"#ifdef __cplusplus\n"
"extern \"C\" {{\n"
"#endif\n"
"\n"
"\n",
config.recomp_include
);
std::vector<std::vector<uint32_t>> static_funcs_by_section{ context.sections.size() };
@ -1785,9 +1786,10 @@ int main(int argc, char** argv) {
single_output_file.open(config.output_func_path / config.elf_path.stem().replace_extension(".c"));
// Write the file header
fmt::print(single_output_file,
"#include \"librecomp/recomp.h\"\n"
"{}\n"
"#include \"funcs.h\"\n"
"\n");
"\n",
config.recomp_include);
}
//#pragma omp parallel for
@ -1902,8 +1904,9 @@ int main(int argc, char** argv) {
std::ofstream lookup_file{ config.output_func_path / "lookup.cpp" };
fmt::print(lookup_file,
"#include \"librecomp/recomp.h\"\n"
"\n"
"{}\n"
"\n",
config.recomp_include
);
fmt::print(lookup_file,
@ -1928,10 +1931,11 @@ int main(int argc, char** argv) {
std::string section_load_table = "static SectionTableEntry section_table[] = {\n";
fmt::print(overlay_file,
"#include \"librecomp/recomp.h\"\n"
"{}\n"
"#include \"funcs.h\"\n"
"#include \"librecomp/sections.h\"\n"
"\n"
"\n",
config.recomp_include
);
std::unordered_map<std::string, size_t> relocatable_section_indices{};

View file

@ -58,7 +58,7 @@ JalResolutionResult resolve_jal(const RecompPort::Context& context, size_t cur_s
break;
}
// If the function's section isn't non-relocatable, add it as a candidate.
// If the function's section isn't relocatable, add the function as a candidate.
const auto& target_func_section = context.sections[target_func.section_index];
if (!target_func_section.relocatable) {
matched_funcs.push_back(target_func_index);
@ -1204,8 +1204,9 @@ bool RecompPort::recompile_function(const RecompPort::Context& context, const Re
if (write_header) {
// Write the file header
fmt::print(output_file,
"#include \"librecomp/recomp.h\"\n"
"\n");
"{}\n"
"\n",
config.recomp_include);
}
fmt::print(output_file,