From 4d9add5e7cf22122622067f1b0ab6e0e056bf143 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 13 Jun 2015 17:48:21 +0300 Subject: [PATCH] vm::ref improved, bugfixes --- Utilities/BEType.h | 2 ++ rpcs3/Emu/Memory/vm_ref.h | 68 ++++++++++++++++++++++++--------------- rpcs3/stdafx.h | 2 ++ 3 files changed, 46 insertions(+), 26 deletions(-) diff --git a/Utilities/BEType.h b/Utilities/BEType.h index b75b5291d3..ba32ca069e 100644 --- a/Utilities/BEType.h +++ b/Utilities/BEType.h @@ -787,6 +787,7 @@ template struct to_be using type = volatile to_be_t>; }; +template<> struct to_be { using type = u128; }; template<> struct to_be { using type = void; }; template<> struct to_be { using type = bool; }; template<> struct to_be { using type = char; }; @@ -907,6 +908,7 @@ template struct to_le using type = volatile to_le_t>; }; +template<> struct to_le { using type = u128; }; template<> struct to_le { using type = void; }; template<> struct to_le { using type = bool; }; template<> struct to_le { using type = char; }; diff --git a/rpcs3/Emu/Memory/vm_ref.h b/rpcs3/Emu/Memory/vm_ref.h index ccc5528370..4777091120 100644 --- a/rpcs3/Emu/Memory/vm_ref.h +++ b/rpcs3/Emu/Memory/vm_ref.h @@ -5,49 +5,65 @@ namespace vm template struct _ref_base { - const AT m_addr; - - using type = T; + AT m_addr; static_assert(!std::is_pointer::value, "vm::_ref_base<> error: invalid type (pointer)"); static_assert(!std::is_reference::value, "vm::_ref_base<> error: invalid type (reference)"); - //template operator std::enable_if_t::value, CT>() - //{ - // return get_ref(m_addr); - //} - - // temporarily, because SFINAE doesn't work for some reason: - - operator to_ne_t() const - { - return get_ref(m_addr); - } - - operator T() const - { - return get_ref(m_addr); - } - AT addr() const { return m_addr; } - static _ref_base make(const AT& addr) + template static _ref_base make(const AT2& addr) { - return{ addr }; + return{ convert_le_be(addr) }; } - template const _ref_base& operator =(const _ref_base& right) const + T& get_ref() const { - get_ref(m_addr) = right; + return vm::get_ref(vm::cast(m_addr)); + } + + T& priv_ref() const + { + return vm::priv_ref(vm::cast(m_addr)); + } + + // conversion operator + //template operator std::enable_if_t::value, CT>() + //{ + // return get_ref(); + //} + + // temporarily, because SFINAE doesn't work for some reason: + + operator to_ne_t() const + { + return get_ref(); + } + + operator T() const + { + return get_ref(); + } + + // copy assignment operator + _ref_base& operator =(const _ref_base& right) + { + get_ref() = right.get_ref(); + return *this; + } + + template std::enable_if_t::value, const _ref_base&> operator =(const _ref_base& right) const + { + get_ref() = right.get_ref(); return *this; } template std::enable_if_t::value, const _ref_base&> operator =(const CT& right) const { - get_ref(m_addr) = right; + get_ref() = right; return *this; } }; @@ -90,7 +106,7 @@ namespace vm //PS3 emulation is main now, so lets it be as default using namespace ps3; -}; +} // external specialization for is_be_t<> diff --git a/rpcs3/stdafx.h b/rpcs3/stdafx.h index 0b3601d755..da1c808a45 100644 --- a/rpcs3/stdafx.h +++ b/rpcs3/stdafx.h @@ -57,6 +57,8 @@ template force_inline T align(const T addr, int align) return (addr + (align - 1)) & ~(align - 1); } +template using func_def = T; // workaround for MSVC bug + #include "Utilities/BEType.h" #include "Utilities/StrFmt.h"