mirror of
https://github.com/N64Recomp/N64Recomp.git
synced 2026-01-10 00:34:34 +00:00
Implements the [[patches.func]] feature that was mentioned as planned in the README. This allows defining recompiler hooks in the config file that call specific functions at designated points. Added FunctionHookDefinition struct supporting two modes: - before_call: Hook at function entry - before_vram: Hook at specific instruction address Hook functions receive rdram and recomp_context parameters for full access to registers and memory. The implementation reuses the existing function_hooks map so it integrates cleanly with the current pipeline. Includes validation for nonexistent functions, invalid addresses, and misaligned vram values with helpful error messages.
88 lines
No EOL
2.9 KiB
C++
88 lines
No EOL
2.9 KiB
C++
#ifndef __RECOMP_CONFIG_H__
|
|
#define __RECOMP_CONFIG_H__
|
|
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
|
|
namespace N64Recomp {
|
|
struct InstructionPatch {
|
|
std::string func_name;
|
|
int32_t vram;
|
|
uint32_t value;
|
|
};
|
|
|
|
struct FunctionTextHook {
|
|
std::string func_name;
|
|
int32_t before_vram;
|
|
std::string text;
|
|
};
|
|
|
|
struct FunctionHookDefinition {
|
|
std::string func_name;
|
|
std::string hook_func_name;
|
|
int32_t before_vram;
|
|
bool before_call; // If true, hook before function call; if false, hook at specific vram
|
|
};
|
|
|
|
struct FunctionSize {
|
|
std::string func_name;
|
|
uint32_t size_bytes;
|
|
|
|
FunctionSize(const std::string& func_name, uint32_t size_bytes) : func_name(std::move(func_name)), size_bytes(size_bytes) {}
|
|
};
|
|
|
|
struct ManualFunction {
|
|
std::string func_name;
|
|
std::string section_name;
|
|
uint32_t vram;
|
|
uint32_t size;
|
|
|
|
ManualFunction(const std::string& func_name, std::string section_name, uint32_t vram, uint32_t size) : func_name(std::move(func_name)), section_name(std::move(section_name)), vram(vram), size(size) {}
|
|
};
|
|
|
|
struct Config {
|
|
int32_t entrypoint;
|
|
int32_t functions_per_output_file;
|
|
bool has_entrypoint;
|
|
bool uses_mips3_float_mode;
|
|
bool single_file_output;
|
|
bool use_absolute_symbols;
|
|
bool unpaired_lo16_warnings;
|
|
bool use_mdebug;
|
|
bool trace_mode;
|
|
bool allow_exports;
|
|
bool strict_patch_mode;
|
|
std::filesystem::path elf_path;
|
|
std::filesystem::path symbols_file_path;
|
|
std::filesystem::path func_reference_syms_file_path;
|
|
std::vector<std::filesystem::path> data_reference_syms_file_paths;
|
|
std::filesystem::path rom_file_path;
|
|
std::filesystem::path output_func_path;
|
|
std::filesystem::path relocatable_sections_path;
|
|
std::filesystem::path output_binary_path;
|
|
std::vector<std::string> stubbed_funcs;
|
|
std::vector<std::string> ignored_funcs;
|
|
std::vector<std::string> renamed_funcs;
|
|
std::vector<InstructionPatch> instruction_patches;
|
|
std::vector<FunctionTextHook> function_hooks;
|
|
std::vector<FunctionHookDefinition> function_hook_definitions;
|
|
std::vector<FunctionSize> manual_func_sizes;
|
|
std::vector<ManualFunction> manual_functions;
|
|
std::string bss_section_suffix;
|
|
std::string recomp_include;
|
|
// Manual mappings of mdebug file records to elf sections.
|
|
std::unordered_map<std::string, std::string> mdebug_text_map;
|
|
std::unordered_map<std::string, std::string> mdebug_data_map;
|
|
std::unordered_map<std::string, std::string> mdebug_rodata_map;
|
|
std::unordered_map<std::string, std::string> mdebug_bss_map;
|
|
|
|
Config(const char* path);
|
|
bool good() { return !bad; }
|
|
private:
|
|
bool bad;
|
|
};
|
|
}
|
|
|
|
#endif |