dynarmic/src/backend/x64/callback.h

55 lines
1.5 KiB
C
Raw Normal View History

2018-01-06 21:15:25 +00:00
/* This file is part of the dynarmic project.
* Copyright (c) 2018 MerryMage
2020-04-23 15:25:11 +01:00
* SPDX-License-Identifier: 0BSD
2018-01-06 21:15:25 +00:00
*/
#pragma once
#include <functional>
#include <vector>
2018-01-06 21:15:25 +00:00
#include <xbyak.h>
#include "common/common_types.h"
namespace Dynarmic::Backend::X64 {
2018-01-06 21:15:25 +00:00
using RegList = std::vector<Xbyak::Reg64>;
2018-01-06 21:15:25 +00:00
class BlockOfCode;
class Callback {
public:
virtual ~Callback();
2018-01-06 21:15:25 +00:00
virtual void EmitCall(BlockOfCode& code, std::function<void(RegList)> fn = [](RegList){}) const = 0;
virtual void EmitCallWithReturnPointer(BlockOfCode& code, std::function<void(Xbyak::Reg64, RegList)> fn) const = 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)) {}
void EmitCall(BlockOfCode& code, std::function<void(RegList)> fn = [](RegList){}) const override;
void EmitCallWithReturnPointer(BlockOfCode& code, std::function<void(Xbyak::Reg64, RegList)> fn) const 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) {}
void EmitCall(BlockOfCode& code, std::function<void(RegList)> fn = [](RegList){}) const override;
void EmitCallWithReturnPointer(BlockOfCode& code, std::function<void(Xbyak::Reg64, RegList)> fn) const override;
2018-01-06 21:15:25 +00:00
private:
void (*fn)();
u64 arg;
};
} // namespace Dynarmic::Backend::X64