also sort absolute symbols

This commit is contained in:
Garrett Smith 2026-05-01 14:09:22 -07:00
parent a923cadf9b
commit 387692e3ff
2 changed files with 19 additions and 14 deletions

BIN
src/.main.cpp.swp Normal file

Binary file not shown.

View File

@ -195,19 +195,19 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map<ui
// Dump relocs into the function context file.
if (!section.relocs.empty()) {
std::vector<std::reference_wrapper<const N64Recomp::Reloc>> relocs_out;
std::vector<std::reference_wrapper<const N64Recomp::Reloc>> 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) {
relocs_out.push_back(reloc);
sorted_relocs.push_back(reloc);
}
}
}
std::ranges::sort(relocs_out, {}, &N64Recomp::Reloc::address);
std::ranges::sort(sorted_relocs, {}, &N64Recomp::Reloc::address);
fmt::print(func_context_file, "relocs = [\n");
for (const N64Recomp::Reloc& reloc : relocs_out) {
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<int>(reloc.type)], reloc.address, reloc.target_section_offset + section.ram_addr);
}
@ -215,14 +215,14 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map<ui
}
// Dump functions into the function context file.
std::vector<std::reference_wrapper<const N64Recomp::Function>> functions_out;
std::vector<std::reference_wrapper<const N64Recomp::Function>> sorted_funcs;
for (const size_t& function_index : section_funcs) {
functions_out.push_back(context.functions[function_index]);
sorted_funcs.push_back(context.functions[function_index]);
}
std::ranges::sort(functions_out, {}, [](const N64Recomp::Function& func) { return std::tie(func.vram, func.name); });
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 : functions_out) {
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]));
}
@ -234,14 +234,14 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map<ui
print_section(data_context_file, section.name, section.rom_addr, section.ram_addr, section.size);
// Dump other symbols into the data context file.
std::vector<std::reference_wrapper<const N64Recomp::DataSymbol>> symbols_out;
std::vector<std::reference_wrapper<const N64Recomp::DataSymbol>> sorted_symbols;
for (const N64Recomp::DataSymbol& cur_sym : find_syms_it->second) {
symbols_out.push_back(cur_sym);
sorted_symbols.push_back(cur_sym);
}
std::ranges::sort(symbols_out, {}, [](const N64Recomp::DataSymbol& sym) { return std::tie(sym.vram, sym.name); });
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 : symbols_out) {
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");
@ -252,12 +252,17 @@ void dump_context(const N64Recomp::Context& context, const std::unordered_map<ui
if (find_abs_syms_it != data_syms.end() && !find_abs_syms_it->second.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<std::reference_wrapper<const N64Recomp::DataSymbol>> 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");
}
}