From a923cadf9bf7e95ab051e0f2653adc70cbbf594d Mon Sep 17 00:00:00 2001 From: Garrett Smith Date: Fri, 1 May 2026 12:57:49 -0700 Subject: [PATCH] add sorting --- src/main.cpp | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index f79580f..252544d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -194,30 +195,37 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map> relocs_out; 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); + relocs_out.push_back(reloc); } } } + std::ranges::sort(relocs_out, {}, &N64Recomp::Reloc::address); + fmt::print(func_context_file, "relocs = [\n"); + for (const N64Recomp::Reloc& reloc : relocs_out) { + 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> functions_out; for (const size_t& function_index : section_funcs) { - const N64Recomp::Function& func = context.functions[function_index]; + functions_out.push_back(context.functions[function_index]); + } + std::ranges::sort(functions_out, {}, [](const N64Recomp::Function& func) { return std::tie(func.vram, func.name); }); + + fmt::print(func_context_file, "functions = [\n"); + for (const N64Recomp::Function& func : functions_out) { 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 +234,16 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map> symbols_out; for (const N64Recomp::DataSymbol& cur_sym : find_syms_it->second) { + symbols_out.push_back(cur_sym); + } + std::ranges::sort(symbols_out, {}, [](const N64Recomp::DataSymbol& sym) { return std::tie(sym.vram, sym.name); }); + + fmt::print(data_context_file, "symbols = [\n"); + for (const N64Recomp::DataSymbol& cur_sym : symbols_out) { fmt::print(data_context_file, " {{ name = \"{}\", vram = 0x{:08X} }},\n", cur_sym.name, cur_sym.vram); } - fmt::print(data_context_file, "]\n\n"); } }