From bb2fc8c67b77b94fd71ef9adbbee4ccc924a6e68 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Mon, 8 Jul 2024 16:37:41 -0400 Subject: [PATCH] Removed unnecessary config input to recompilation functions --- include/recomp_port.h | 3 +-- src/main.cpp | 12 ++++++------ src/recompilation.cpp | 14 +++++++------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/recomp_port.h b/include/recomp_port.h index 361cb39..ee0e4a7 100644 --- a/include/recomp_port.h +++ b/include/recomp_port.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include "rabbitizer.hpp" @@ -219,7 +218,7 @@ namespace RecompPort { }; bool analyze_function(const Context& context, const Function& function, const std::vector& instructions, FunctionStats& stats); - bool recompile_function(const Context& context, const Config& config, const Function& func, std::ofstream& output_file, std::span> static_funcs, bool write_header); + bool recompile_function(const Context& context, const Function& func, const std::string& recomp_include, std::ofstream& output_file, std::span> static_funcs, bool write_header); } #endif diff --git a/src/main.cpp b/src/main.cpp index 1026175..4f66711 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1330,7 +1330,7 @@ bool compare_files(const std::filesystem::path& file1_path, const std::filesyste return std::equal(begin1, std::istreambuf_iterator(), begin2); //Second argument is end-of-range iterator } -bool recompile_single_function(const RecompPort::Context& context, const RecompPort::Config& config, const RecompPort::Function& func, const std::filesystem::path& output_path, std::span> static_funcs_out) { +bool recompile_single_function(const RecompPort::Context& context, const RecompPort::Function& func, const std::string& recomp_include, const std::filesystem::path& output_path, std::span> static_funcs_out) { // Open the temporary output file std::filesystem::path temp_path = output_path; temp_path.replace_extension(".tmp"); @@ -1340,7 +1340,7 @@ bool recompile_single_function(const RecompPort::Context& context, const RecompP return false; } - if (!RecompPort::recompile_function(context, config, func, output_file, static_funcs_out, true)) { + if (!RecompPort::recompile_function(context, func, recomp_include, output_file, static_funcs_out, true)) { return false; } @@ -1828,7 +1828,7 @@ int main(int argc, char** argv) { "void {}(uint8_t* rdram, recomp_context* ctx);\n", func.name); bool result; if (config.single_file_output || config.functions_per_output_file > 1) { - result = RecompPort::recompile_function(context, config, func, current_output_file, static_funcs_by_section, false); + result = RecompPort::recompile_function(context, func, config.recomp_include, current_output_file, static_funcs_by_section, false); if (!config.single_file_output) { cur_file_function_count++; if (cur_file_function_count >= config.functions_per_output_file) { @@ -1837,7 +1837,7 @@ int main(int argc, char** argv) { } } else { - result = recompile_single_function(context, config, func, config.output_func_path / (func.name + ".c"), static_funcs_by_section); + result = recompile_single_function(context, func, config.recomp_include, config.output_func_path / (func.name + ".c"), static_funcs_by_section); } if (result == false) { fmt::print(stderr, "Error recompiling {}\n", func.name); @@ -1907,7 +1907,7 @@ int main(int argc, char** argv) { size_t prev_num_statics = static_funcs_by_section[func.section_index].size(); if (config.single_file_output || config.functions_per_output_file > 1) { - result = RecompPort::recompile_function(context, config, func, current_output_file, static_funcs_by_section, false); + result = RecompPort::recompile_function(context, func, config.recomp_include, current_output_file, static_funcs_by_section, false); if (!config.single_file_output) { cur_file_function_count++; if (cur_file_function_count >= config.functions_per_output_file) { @@ -1916,7 +1916,7 @@ int main(int argc, char** argv) { } } else { - result = recompile_single_function(context, config, func, config.output_func_path / (func.name + ".c"), static_funcs_by_section); + result = recompile_single_function(context, func, config.recomp_include, config.output_func_path / (func.name + ".c"), static_funcs_by_section); } // Add any new static functions that were found while recompiling this one. diff --git a/src/recompilation.cpp b/src/recompilation.cpp index 5a645aa..2b3691c 100644 --- a/src/recompilation.cpp +++ b/src/recompilation.cpp @@ -109,7 +109,7 @@ std::string_view ctx_gpr_prefix(int reg) { } // Major TODO, this function grew very organically and needs to be cleaned up. Ideally, it'll get split up into some sort of lookup table grouped by similar instruction types. -bool process_instruction(const RecompPort::Context& context, const RecompPort::Config& config, const RecompPort::Function& func, const RecompPort::FunctionStats& stats, const std::unordered_set& skipped_insns, size_t instr_index, const std::vector& instructions, std::ofstream& output_file, bool indent, bool emit_link_branch, int link_branch_index, size_t reloc_index, bool& needs_link_branch, bool& is_branch_likely, std::span> static_funcs_out) { +bool process_instruction(const RecompPort::Context& context, const RecompPort::Function& func, const RecompPort::FunctionStats& stats, const std::unordered_set& skipped_insns, size_t instr_index, const std::vector& instructions, std::ofstream& output_file, bool indent, bool emit_link_branch, int link_branch_index, size_t reloc_index, bool& needs_link_branch, bool& is_branch_likely, std::span> static_funcs_out) { using namespace RecompPort; const auto& section = context.sections[func.section_index]; @@ -225,7 +225,7 @@ bool process_instruction(const RecompPort::Context& context, const RecompPort::C if (reloc_index + 1 < section.relocs.size() && next_vram > section.relocs[reloc_index].address) { next_reloc_index++; } - if (!process_instruction(context, config, func, stats, skipped_insns, instr_index + 1, instructions, output_file, false, false, link_branch_index, next_reloc_index, dummy_needs_link_branch, dummy_is_branch_likely, static_funcs_out)) { + if (!process_instruction(context, func, stats, skipped_insns, instr_index + 1, instructions, output_file, false, false, link_branch_index, next_reloc_index, dummy_needs_link_branch, dummy_is_branch_likely, static_funcs_out)) { return false; } } @@ -320,7 +320,7 @@ bool process_instruction(const RecompPort::Context& context, const RecompPort::C if (reloc_index + 1 < section.relocs.size() && next_vram > section.relocs[reloc_index].address) { next_reloc_index++; } - if (!process_instruction(context, config, func, stats, skipped_insns, instr_index + 1, instructions, output_file, true, false, link_branch_index, next_reloc_index, dummy_needs_link_branch, dummy_is_branch_likely, static_funcs_out)) { + if (!process_instruction(context, func, stats, skipped_insns, instr_index + 1, instructions, output_file, true, false, link_branch_index, next_reloc_index, dummy_needs_link_branch, dummy_is_branch_likely, static_funcs_out)) { return false; } } @@ -490,7 +490,7 @@ bool process_instruction(const RecompPort::Context& context, const RecompPort::C if (reloc_index + 1 < section.relocs.size() && next_vram > section.relocs[reloc_index].address) { next_reloc_index++; } - if (!process_instruction(context, config, func, stats, skipped_insns, instr_index + 1, instructions, output_file, false, false, link_branch_index, next_reloc_index, dummy_needs_link_branch, dummy_is_branch_likely, static_funcs_out)) { + if (!process_instruction(context, func, stats, skipped_insns, instr_index + 1, instructions, output_file, false, false, link_branch_index, next_reloc_index, dummy_needs_link_branch, dummy_is_branch_likely, static_funcs_out)) { return false; } print_indent(); @@ -717,7 +717,7 @@ bool process_instruction(const RecompPort::Context& context, const RecompPort::C return true; } -bool RecompPort::recompile_function(const RecompPort::Context& context, const RecompPort::Config& config, const RecompPort::Function& func, std::ofstream& output_file, std::span> static_funcs_out, bool write_header) { +bool RecompPort::recompile_function(const RecompPort::Context& context, const RecompPort::Function& func, const std::string& recomp_include, std::ofstream& output_file, std::span> static_funcs_out, bool write_header) { //fmt::print("Recompiling {}\n", func.name); std::vector instructions; @@ -726,7 +726,7 @@ bool RecompPort::recompile_function(const RecompPort::Context& context, const Re fmt::print(output_file, "{}\n" "\n", - config.recomp_include); + recomp_include); } fmt::print(output_file, @@ -808,7 +808,7 @@ bool RecompPort::recompile_function(const RecompPort::Context& context, const Re } // Process the current instruction and check for errors - if (process_instruction(context, config, func, stats, skipped_insns, instr_index, instructions, output_file, false, needs_link_branch, num_link_branches, reloc_index, needs_link_branch, is_branch_likely, static_funcs_out) == false) { + if (process_instruction(context, func, stats, skipped_insns, instr_index, instructions, output_file, false, needs_link_branch, num_link_branches, reloc_index, needs_link_branch, is_branch_likely, static_funcs_out) == false) { fmt::print(stderr, "Error in recompiling {}, clearing output file\n", func.name); output_file.clear(); return false;