2018-01-08 18:33:42 +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 <memory>
|
|
|
|
|
|
|
|
#include "backend_x64/callback.h"
|
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/mp.h"
|
|
|
|
|
|
|
|
namespace Dynarmic {
|
|
|
|
namespace BackendX64 {
|
|
|
|
|
|
|
|
namespace impl {
|
|
|
|
|
2018-01-12 17:31:21 +00:00
|
|
|
template <typename FunctionType, FunctionType mfp>
|
2018-01-08 18:33:42 +00:00
|
|
|
struct ThunkBuilder;
|
|
|
|
|
2018-01-12 17:31:21 +00:00
|
|
|
template <typename C, typename R, typename... Args, R(C::*mfp)(Args...)>
|
|
|
|
struct ThunkBuilder<R(C::*)(Args...), mfp> {
|
2018-01-08 18:33:42 +00:00
|
|
|
static R Thunk(C* this_, Args... args) {
|
2018-01-12 17:31:21 +00:00
|
|
|
return (this_->*mfp)(std::forward<Args>(args)...);
|
2018-01-08 18:33:42 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace impl
|
|
|
|
|
2018-01-12 17:31:21 +00:00
|
|
|
template <typename FunctionType, FunctionType mfp>
|
|
|
|
ArgCallback Devirtualize(mp::class_type_t<decltype(mfp)>* this_) {
|
|
|
|
return ArgCallback{&impl::ThunkBuilder<FunctionType, mfp>::Thunk, reinterpret_cast<u64>(this_)};
|
2018-01-08 18:33:42 +00:00
|
|
|
}
|
|
|
|
|
2018-01-12 17:31:21 +00:00
|
|
|
#define DEVIRT(this_, mfp) Dynarmic::BackendX64::Devirtualize<decltype(mfp), mfp>(this_)
|
|
|
|
|
2018-01-08 18:33:42 +00:00
|
|
|
} // namespace BackendX64
|
|
|
|
} // namespace Dynarmic
|