diff --git a/src/main.cpp b/src/main.cpp index f79580f..669c4a1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -194,30 +195,41 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map> sorted_relocs; for (const N64Recomp::Reloc& reloc : section.relocs) { if (reloc.target_section == section_index || reloc.target_section == section.bss_section_index) { // TODO allow emitting MIPS32 relocs for specific sections via a toml option for TLB mapping support. if (reloc.type == N64Recomp::RelocType::R_MIPS_HI16 || reloc.type == N64Recomp::RelocType::R_MIPS_LO16 || reloc.type == N64Recomp::RelocType::R_MIPS_26) { - fmt::print(func_context_file, " {{ type = \"{}\", vram = 0x{:08X}, target_vram = 0x{:08X} }},\n", - reloc_names[static_cast(reloc.type)], reloc.address, reloc.target_section_offset + section.ram_addr); + sorted_relocs.push_back(reloc); } } } + std::sort(sorted_relocs.begin(), sorted_relocs.end(), [](auto& a, auto& b) { + return a.get().address < b.get().address; + }); + fmt::print(func_context_file, "relocs = [\n"); + for (const N64Recomp::Reloc& reloc : sorted_relocs) { + fmt::print(func_context_file, " {{ type = \"{}\", vram = 0x{:08X}, target_vram = 0x{:08X} }},\n", + reloc_names[static_cast(reloc.type)], reloc.address, reloc.target_section_offset + section.ram_addr); + } fmt::print(func_context_file, "]\n\n"); } // Dump functions into the function context file. - fmt::print(func_context_file, "functions = [\n"); - + std::vector> sorted_funcs; for (const size_t& function_index : section_funcs) { - const N64Recomp::Function& func = context.functions[function_index]; + sorted_funcs.push_back(context.functions[function_index]); + } + std::sort(sorted_funcs.begin(), sorted_funcs.end(), [](auto& a, auto& b) { + return std::tie(a.get().vram, a.get().name) < std::tie(b.get().vram, b.get().name); + }); + + fmt::print(func_context_file, "functions = [\n"); + for (const N64Recomp::Function& func : sorted_funcs) { fmt::print(func_context_file, " {{ name = \"{}\", vram = 0x{:08X}, size = 0x{:X} }},\n", func.name, func.vram, func.words.size() * sizeof(func.words[0])); } - fmt::print(func_context_file, "]\n\n"); } @@ -226,12 +238,18 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map> sorted_symbols; for (const N64Recomp::DataSymbol& cur_sym : find_syms_it->second) { + sorted_symbols.push_back(cur_sym); + } + std::sort(sorted_symbols.begin(), sorted_symbols.end(), [](auto& a, auto& b) { + return std::tie(a.get().vram, a.get().name) < std::tie(b.get().vram, b.get().name); + }); + + fmt::print(data_context_file, "symbols = [\n"); + for (const N64Recomp::DataSymbol& cur_sym : sorted_symbols) { fmt::print(data_context_file, " {{ name = \"{}\", vram = 0x{:08X} }},\n", cur_sym.name, cur_sym.vram); } - fmt::print(data_context_file, "]\n\n"); } } @@ -240,12 +258,19 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_mapsecond.empty()) { // Dump absolute symbols into the data context file. print_section(data_context_file, "ABSOLUTE_SYMS", (uint32_t)-1, 0, 0); - fmt::print(data_context_file, "symbols = [\n"); + std::vector> sorted_symbols; for (const N64Recomp::DataSymbol& cur_sym : find_abs_syms_it->second) { + sorted_symbols.push_back(cur_sym); + } + std::sort(sorted_symbols.begin(), sorted_symbols.end(), [](auto& a, auto& b) { + return std::tie(a.get().vram, a.get().name) < std::tie(b.get().vram, b.get().name); + }); + + fmt::print(data_context_file, "symbols = [\n"); + for (const N64Recomp::DataSymbol& cur_sym : sorted_symbols) { fmt::print(data_context_file, " {{ name = \"{}\", vram = 0x{:08X} }},\n", cur_sym.name, cur_sym.vram); } - fmt::print(data_context_file, "]\n\n"); } }