2018-01-06 21:15:25 +00:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2018 MerryMage
|
|
|
|
* This software may be used and distributed according to the terms of the GNU
|
|
|
|
* General Public License version 2 or any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
2018-02-09 15:58:16 +00:00
|
|
|
#include <vector>
|
2018-01-06 21:15:25 +00:00
|
|
|
|
|
|
|
#include <xbyak.h>
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
namespace Dynarmic::BackendX64 {
|
2018-01-06 21:15:25 +00:00
|
|
|
|
2018-02-09 15:58:16 +00:00
|
|
|
using RegList = std::vector<Xbyak::Reg64>;
|
|
|
|
|
2018-01-06 21:15:25 +00:00
|
|
|
class BlockOfCode;
|
|
|
|
|
|
|
|
class Callback {
|
|
|
|
public:
|
|
|
|
virtual ~Callback() = default;
|
|
|
|
|
2018-02-09 15:58:16 +00:00
|
|
|
virtual void EmitCall(BlockOfCode& code, std::function<void(RegList)> fn = [](RegList){}) = 0;
|
|
|
|
virtual void EmitCallWithReturnPointer(BlockOfCode& code, std::function<void(Xbyak::Reg64, RegList)> fn) = 0;
|
2018-01-06 21:15:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class SimpleCallback final : public Callback {
|
|
|
|
public:
|
|
|
|
template <typename Function>
|
|
|
|
SimpleCallback(Function fn) : fn(reinterpret_cast<void(*)()>(fn)) {}
|
|
|
|
|
2018-01-27 02:25:27 +00:00
|
|
|
~SimpleCallback() override = default;
|
2018-01-06 21:15:25 +00:00
|
|
|
|
2018-02-09 15:58:16 +00:00
|
|
|
void EmitCall(BlockOfCode& code, std::function<void(RegList)> fn = [](RegList){}) override;
|
|
|
|
void EmitCallWithReturnPointer(BlockOfCode& code, std::function<void(Xbyak::Reg64, RegList)> fn) override;
|
2018-01-06 21:15:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void (*fn)();
|
|
|
|
};
|
|
|
|
|
|
|
|
class ArgCallback final : public Callback {
|
|
|
|
public:
|
|
|
|
template <typename Function>
|
|
|
|
ArgCallback(Function fn, u64 arg) : fn(reinterpret_cast<void(*)()>(fn)), arg(arg) {}
|
|
|
|
|
2018-01-27 02:25:27 +00:00
|
|
|
~ArgCallback() override = default;
|
2018-01-06 21:15:25 +00:00
|
|
|
|
2018-02-09 15:58:16 +00:00
|
|
|
void EmitCall(BlockOfCode& code, std::function<void(RegList)> fn = [](RegList){}) override;
|
|
|
|
void EmitCallWithReturnPointer(BlockOfCode& code, std::function<void(Xbyak::Reg64, RegList)> fn) override;
|
2018-01-06 21:15:25 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void (*fn)();
|
|
|
|
u64 arg;
|
|
|
|
};
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
} // namespace Dynarmic::BackendX64
|