XenonRecomp/PowerRecomp/recompiler.h

71 lines
1.6 KiB
C
Raw Normal View History

2024-09-21 16:59:55 +03:00
#pragma once
#include "pch.h"
#include "recompiler_config.h"
2024-09-21 16:59:55 +03:00
struct RecompilerLocalVariables
{
bool ctr{};
bool xer{};
bool reserved{};
bool cr[8]{};
bool r[32]{};
bool f[32]{};
bool v[128]{};
bool env{};
bool temp{};
bool vTemp{};
bool ea{};
};
enum class CSRState
{
Unknown,
FPU,
VMX
};
2024-09-21 16:59:55 +03:00
struct Recompiler
{
2024-11-24 15:36:50 +06:00
// Enforce In-order Execution of I/O constant for quick comparison
static constexpr uint32_t c_eieio = 0xAC06007C;
2024-09-21 16:59:55 +03:00
Image image;
std::vector<Function> functions;
std::string out;
size_t cppFileIndex = 0;
RecompilerConfig config;
2024-09-21 16:59:55 +03:00
void LoadConfig(const std::string_view& configFilePath);
2024-09-21 16:59:55 +03:00
template<class... Args>
2024-12-13 18:31:55 +03:00
void print(fmt::format_string<Args...> fmt, Args&&... args)
2024-09-21 16:59:55 +03:00
{
2024-12-13 18:31:55 +03:00
fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...));
2024-09-21 16:59:55 +03:00
}
template<class... Args>
2024-12-13 18:31:55 +03:00
void println(fmt::format_string<Args...> fmt, Args&&... args)
2024-09-21 16:59:55 +03:00
{
2024-12-13 18:31:55 +03:00
fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...));
2024-09-21 16:59:55 +03:00
out += '\n';
}
void Analyse();
// TODO: make a RecompileArgs struct instead this is getting messy
bool Recompile(
const Function& fn,
uint32_t base,
2024-11-24 15:36:50 +06:00
const ppc_insn& insn,
const uint32_t* data,
std::unordered_map<uint32_t, RecompilerSwitchTable>::iterator& switchTable,
RecompilerLocalVariables& localVariables,
CSRState& csrState);
2024-09-21 16:59:55 +03:00
2024-09-21 21:47:34 +03:00
bool Recompile(const Function& fn);
2024-09-21 16:59:55 +03:00
void Recompile();
2024-09-21 16:59:55 +03:00
void SaveCurrentOutData(const std::string_view& name = std::string_view());
2024-09-21 16:59:55 +03:00
};