#ifndef PS2RECOMP_PS2_RECOMPILER_H #define PS2RECOMP_PS2_RECOMPILER_H #include "code_generator.h" #include "config_manager.h" #include "recompiler_reporter.h" #include #include #include #include #include #include #include namespace ps2recomp { class R5900Decoder; class ElfParser; enum class StubTarget { Unknown, Syscall, Stub }; class PS2Recompiler { public: explicit PS2Recompiler(const std::string &configPath); ~PS2Recompiler(); bool initialize(); bool recompile(); void generateOutput(); void printReport() const; const RecompilerReporter::Counters &reportCounters() const { return m_reporter.counters(); } static StubTarget resolveStubTarget(const std::string& name); static bool IsCorrectnessCriticalFunctionName(const std::string &name); static size_t DiscoverAdditionalEntryPoints( std::vector &functions, std::unordered_map> &decodedFunctions, const std::vector
§ions); static size_t ResliceEntryFunctions(std::vector &functions, std::unordered_map> &decodedFunctions); static size_t CollectInternalEntryTargets( const std::vector &functions, const std::unordered_map> &decodedFunctions, const std::unordered_set &entryAddresses, std::unordered_map> &targetsByOwner); static std::string ClampFilenameLength(const std::string& baseName, const std::string& extension, std::size_t maxLength); private: ConfigManager m_configManager; std::unique_ptr m_elfParser; std::unique_ptr m_decoder; std::unique_ptr m_codeGenerator; RecompilerConfig m_config; RecompilerReporter m_reporter; std::vector m_functions; std::vector m_symbols; std::vector
m_sections; std::vector m_relocations; std::unordered_map> m_decodedFunctions; std::unordered_map m_skipFunctions; std::unordered_set m_skipFunctionStarts; std::unordered_set m_stubFunctions; std::unordered_set m_stubFunctionStarts; std::unordered_map m_stubHandlerBindingsByStart; std::unordered_set m_entryPointHintStarts; std::unordered_set m_correctnessCriticalFunctionStarts; std::map m_generatedStubs; std::unordered_map m_functionRenames; std::unordered_map> m_resumeEntryTargetsByOwner; CodeGenerator::BootstrapInfo m_bootstrapInfo; bool decodeFunction(Function &function); void discoverAdditionalEntryPoints(); bool shouldSkipFunction(const Function &function) const; bool isStubFunction(const Function &function) const; bool isCorrectnessCriticalFunction(const Function &function) const; bool hasResolvedStubHandler(const Function &function) const; void collectCorrectnessCriticalFunctionStarts(); bool generateFunctionHeader(); bool generateStubHeader(); bool writeToFile(const std::string &path, const std::string &content); std::filesystem::path getOutputPath(const Function &function) const; static std::string clampFilenameLength(const std::string& baseName, const std::string& extension, std::size_t maxLength); std::string sanitizeFunctionName(const std::string &name) const; }; } #endif