Move file header writing outside of function recompilation

This commit is contained in:
Mr-Wiseguy 2024-08-22 23:24:54 -04:00
parent ad0e38dde7
commit 008b1177fa
4 changed files with 12 additions and 14 deletions

View file

@ -156,7 +156,7 @@ int main(int argc, const char** argv) {
output_file << "RECOMP_EXPORT int32_t* section_addresses = NULL;\n";
for (const auto& func : mod_context.functions) {
N64Recomp::recompile_function(mod_context, func, "", output_file, static_funcs_by_section, false);
N64Recomp::recompile_function(mod_context, func, output_file, static_funcs_by_section);
}
return EXIT_SUCCESS;

View file

@ -469,7 +469,7 @@ namespace N64Recomp {
}
};
bool recompile_function(const Context& context, const Function& func, const std::string& recomp_include, std::ofstream& output_file, std::span<std::vector<uint32_t>> static_funcs, bool write_header);
bool recompile_function(const Context& context, const Function& func, std::ofstream& output_file, std::span<std::vector<uint32_t>> static_funcs);
enum class ModSymbolsError {
Good,

View file

@ -121,7 +121,13 @@ bool recompile_single_function(const N64Recomp::Context& context, const N64Recom
return false;
}
if (!N64Recomp::recompile_function(context, func, recomp_include, output_file, static_funcs_out, true)) {
// Write the file header
fmt::print(output_file,
"{}\n"
"\n",
recomp_include);
if (!N64Recomp::recompile_function(context, func, output_file, static_funcs_out)) {
return false;
}
@ -611,7 +617,7 @@ int main(int argc, char** argv) {
// Recompile the function.
if (config.single_file_output || config.functions_per_output_file > 1) {
result = N64Recomp::recompile_function(context, func, config.recomp_include, current_output_file, static_funcs_by_section, false);
result = N64Recomp::recompile_function(context, func, current_output_file, static_funcs_by_section);
if (!config.single_file_output) {
cur_file_function_count++;
if (cur_file_function_count >= config.functions_per_output_file) {
@ -698,7 +704,7 @@ int main(int argc, char** argv) {
bool result;
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 = N64Recomp::recompile_function(context, func, config.recomp_include, current_output_file, static_funcs_by_section, false);
result = N64Recomp::recompile_function(context, func, current_output_file, static_funcs_by_section);
if (!config.single_file_output) {
cur_file_function_count++;
if (cur_file_function_count >= config.functions_per_output_file) {

View file

@ -730,18 +730,10 @@ bool process_instruction(const N64Recomp::Context& context, const N64Recomp::Fun
return true;
}
bool N64Recomp::recompile_function(const N64Recomp::Context& context, const N64Recomp::Function& func, const std::string& recomp_include, std::ofstream& output_file, std::span<std::vector<uint32_t>> static_funcs_out, bool write_header) {
bool N64Recomp::recompile_function(const N64Recomp::Context& context, const N64Recomp::Function& func, std::ofstream& output_file, std::span<std::vector<uint32_t>> static_funcs_out) {
//fmt::print("Recompiling {}\n", func.name);
std::vector<rabbitizer::InstructionCpu> instructions;
if (write_header) {
// Write the file header
fmt::print(output_file,
"{}\n"
"\n",
recomp_include);
}
fmt::print(output_file,
"RECOMP_FUNC void {}(uint8_t* rdram, recomp_context* ctx) {{\n"
// these variables shouldn't need to be preserved across function boundaries, so make them local for more efficient output