MCPcopy Create free account
hub / github.com/N64Recomp/N64Recomp / main

Function main

OfflineModRecomp/main.cpp:27–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27int main(int argc, const char** argv) {
28 if (argc != 5) {
29 printf("Usage: %s [mod symbol file] [mod binary file] [recomp symbols file] [output C file]\n", argv[0]);
30 return EXIT_SUCCESS;
31 }
32 bool found;
33 std::vector<uint8_t> symbol_data = read_file(argv[1], found);
34 if (!found) {
35 fprintf(stderr, "Failed to open symbol file\n");
36 return EXIT_FAILURE;
37 }
38
39 std::vector<uint8_t> rom_data = read_file(argv[2], found);
40 if (!found) {
41 fprintf(stderr, "Failed to open ROM\n");
42 return EXIT_FAILURE;
43 }
44
45 std::span<const char> symbol_data_span { reinterpret_cast<const char*>(symbol_data.data()), symbol_data.size() };
46
47 std::vector<uint8_t> dummy_rom{};
48 N64Recomp::Context reference_context{};
49 if (!N64Recomp::Context::from_symbol_file(argv[3], std::move(dummy_rom), reference_context, false)) {
50 printf("Failed to load provided function reference symbol file\n");
51 return EXIT_FAILURE;
52 }
53
54 //for (const std::filesystem::path& cur_data_sym_path : data_reference_syms_file_paths) {
55 // if (!reference_context.read_data_reference_syms(cur_data_sym_path)) {
56 // printf("Failed to load provided data reference symbol file\n");
57 // return EXIT_FAILURE;
58 // }
59 //}
60
61 std::unordered_map<uint32_t, uint16_t> sections_by_vrom{};
62 for (uint16_t section_index = 0; section_index < reference_context.sections.size(); section_index++) {
63 sections_by_vrom[reference_context.sections[section_index].rom_addr] = section_index;
64 }
65
66 N64Recomp::Context mod_context;
67
68 N64Recomp::ModSymbolsError error = N64Recomp::parse_mod_symbols(symbol_data_span, rom_data, sections_by_vrom, mod_context);
69 if (error != N64Recomp::ModSymbolsError::Good) {
70 fprintf(stderr, "Error parsing mod symbols: %d\n", (int)error);
71 return EXIT_FAILURE;
72 }
73
74 mod_context.import_reference_context(reference_context);
75
76 // Populate R_MIPS_26 reloc symbol indices. Start by building a map of vram address to matching reference symbols.
77 std::unordered_map<uint32_t, std::vector<size_t>> reference_symbols_by_vram{};
78 for (size_t reference_symbol_index = 0; reference_symbol_index < mod_context.num_regular_reference_symbols(); reference_symbol_index++) {
79 const auto& sym = mod_context.get_regular_reference_symbol(reference_symbol_index);
80 uint16_t section_index = sym.section_index;
81 if (section_index != N64Recomp::SectionAbsolute) {
82 uint32_t section_vram = mod_context.get_reference_section_vram(section_index);
83 reference_symbols_by_vram[section_vram + sym.section_offset].push_back(reference_symbol_index);
84 }

Callers

nothing calls this directly

Calls 5

read_fileFunction · 0.70

Tested by

no test coverage detected