diff --git a/src/.main.cpp.swp b/src/.main.cpp.swp new file mode 100644 index 0000000..20090af Binary files /dev/null and b/src/.main.cpp.swp differ diff --git a/src/main.cpp b/src/main.cpp index f79580f..242bcbf 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> 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::ranges::sort(sorted_relocs, {}, &N64Recomp::Reloc::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::ranges::sort(sorted_funcs, {}, [](const N64Recomp::Function& func) { return std::tie(func.vram, func.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 +234,16 @@ 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::ranges::sort(sorted_symbols, {}, [](const N64Recomp::DataSymbol& sym) { return std::tie(sym.vram, sym.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 +252,17 @@ 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::ranges::sort(sorted_symbols, {}, [](const N64Recomp::DataSymbol& sym) { return std::tie(sym.vram, sym.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"); } }