From dff4392c1043c2748d70c52a888bf19e1869d679 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Sat, 12 Dec 2020 14:24:01 +0300 Subject: [PATCH] Move error_code to ErrorCodes.h --- Utilities/types.h | 60 -------------------- rpcs3/Emu/Cell/ErrorCodes.h | 77 ++++++++++++++++++++++++++ rpcs3/Emu/Cell/Modules/cellMsgDialog.h | 1 + rpcs3/Emu/Cell/Modules/cellRtc.h | 1 + rpcs3/Emu/Cell/Modules/sceNp.h | 1 + rpcs3/Emu/Cell/Modules/sceNpTrophy.h | 1 + rpcs3/Emu/Cell/PPUThread.h | 14 ----- rpcs3/Emu/Cell/lv2/sys_bdemu.h | 1 + rpcs3/Emu/Cell/lv2/sys_btsetting.h | 1 + rpcs3/Emu/Cell/lv2/sys_crypto_engine.h | 1 + rpcs3/Emu/Cell/lv2/sys_dbg.h | 1 + rpcs3/Emu/Cell/lv2/sys_gpio.h | 1 + rpcs3/Emu/Cell/lv2/sys_memory.h | 1 + rpcs3/Emu/Cell/lv2/sys_mmapper.h | 1 + rpcs3/Emu/Cell/lv2/sys_net.h | 1 + rpcs3/Emu/Cell/lv2/sys_ppu_thread.h | 1 + rpcs3/Emu/Cell/lv2/sys_process.h | 3 +- rpcs3/Emu/Cell/lv2/sys_prx.h | 1 + rpcs3/Emu/Cell/lv2/sys_rsx.h | 1 + rpcs3/Emu/Cell/lv2/sys_rsxaudio.h | 1 + rpcs3/Emu/Cell/lv2/sys_sm.h | 1 + rpcs3/Emu/Cell/lv2/sys_spu.h | 1 + rpcs3/Emu/Cell/lv2/sys_storage.h | 1 + rpcs3/Emu/Cell/lv2/sys_time.h | 1 + rpcs3/Emu/Cell/lv2/sys_usbd.h | 1 + rpcs3/Emu/System.cpp | 1 + 26 files changed, 101 insertions(+), 75 deletions(-) diff --git a/Utilities/types.h b/Utilities/types.h index 53ea90e2c9..695f271eaf 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -884,66 +884,6 @@ struct value_hash } }; -// Error code type (return type), implements error reporting. Could be a template. -class error_code -{ - // Use fixed s32 type for now - s32 value; - -public: - error_code() = default; - - // Implementation must be provided specially - static s32 error_report(const fmt_type_info* sup, u64 arg, const fmt_type_info* sup2, u64 arg2); - - // Helper type - enum class not_an_error : s32 - { - __not_an_error // SFINAE marker - }; - - // __not_an_error tester - template - struct is_error : std::integral_constant::value || std::is_integral::value> - { - }; - - template - struct is_error> : std::false_type - { - }; - - // Common constructor - template - error_code(const ET& value) - : value(static_cast(value)) - { - if constexpr(is_error::value) - { - this->value = error_report(fmt::get_type_info>(), fmt_unveil::get(value), nullptr, 0); - } - } - - // Error constructor (2 args) - template - error_code(const ET& value, const T2& value2) - : value(error_report(fmt::get_type_info>(), fmt_unveil::get(value), fmt::get_type_info>(), fmt_unveil::get(value2))) - { - } - - operator s32() const - { - return value; - } -}; - -// Helper function for error_code -template -constexpr FORCE_INLINE error_code::not_an_error not_an_error(const T& value) -{ - return static_cast(static_cast(value)); -} - // Synchronization helper (cache-friendly busy waiting) inline void busy_wait(std::size_t cycles = 3000) { diff --git a/rpcs3/Emu/Cell/ErrorCodes.h b/rpcs3/Emu/Cell/ErrorCodes.h index 8cf16e442c..fe7bfdbf7a 100644 --- a/rpcs3/Emu/Cell/ErrorCodes.h +++ b/rpcs3/Emu/Cell/ErrorCodes.h @@ -2,6 +2,83 @@ #include "Utilities/types.h" +// Error code type (return type), implements error reporting. +class error_code +{ + s32 value; + +public: + error_code() = default; + + // Implementation must be provided independently + static s32 error_report(const fmt_type_info* sup, u64 arg, const fmt_type_info* sup2, u64 arg2); + + // Helper type + enum class not_an_error : s32 + { + __not_an_error // SFINAE marker + }; + + // __not_an_error tester + template + struct is_error : std::integral_constant::value || std::is_integral::value> + { + }; + + template + struct is_error> : std::false_type + { + }; + + // Common constructor + template + error_code(const ET& value) + : value(static_cast(value)) + { + if constexpr(is_error::value) + { + this->value = error_report(fmt::get_type_info>(), fmt_unveil::get(value), nullptr, 0); + } + } + + // Error constructor (2 args) + template + error_code(const ET& value, const T2& value2) + : value(error_report(fmt::get_type_info>(), fmt_unveil::get(value), fmt::get_type_info>(), fmt_unveil::get(value2))) + { + } + + operator s32() const + { + return value; + } +}; + +// Helper function for error_code +template +constexpr FORCE_INLINE error_code::not_an_error not_an_error(const T& value) +{ + return static_cast(static_cast(value)); +} + +template +struct ppu_gpr_cast_impl; + +template <> +struct ppu_gpr_cast_impl +{ + static inline u64 to(const error_code& code) + { + return code; + } + + static inline error_code from(const u64 reg) + { + return not_an_error(reg); + } +}; + + enum CellNotAnError : s32 { CELL_OK = 0, diff --git a/rpcs3/Emu/Cell/Modules/cellMsgDialog.h b/rpcs3/Emu/Cell/Modules/cellMsgDialog.h index 4b1743d173..8c8828b92a 100644 --- a/rpcs3/Emu/Cell/Modules/cellMsgDialog.h +++ b/rpcs3/Emu/Cell/Modules/cellMsgDialog.h @@ -2,6 +2,7 @@ #include "Utilities/BitField.h" #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" enum { diff --git a/rpcs3/Emu/Cell/Modules/cellRtc.h b/rpcs3/Emu/Cell/Modules/cellRtc.h index 40250b4733..d40af85cfb 100644 --- a/rpcs3/Emu/Cell/Modules/cellRtc.h +++ b/rpcs3/Emu/Cell/Modules/cellRtc.h @@ -2,6 +2,7 @@ #include "Utilities/BEType.h" #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // Return Codes enum CellRtcError diff --git a/rpcs3/Emu/Cell/Modules/sceNp.h b/rpcs3/Emu/Cell/Modules/sceNp.h index a10dbad770..cca520bd00 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.h +++ b/rpcs3/Emu/Cell/Modules/sceNp.h @@ -1,6 +1,7 @@ #pragma once #include "cellRtc.h" +#include "Emu/Cell/ErrorCodes.h" #include "Utilities/BEType.h" diff --git a/rpcs3/Emu/Cell/Modules/sceNpTrophy.h b/rpcs3/Emu/Cell/Modules/sceNpTrophy.h index 9733ba1d38..c898b93c16 100644 --- a/rpcs3/Emu/Cell/Modules/sceNpTrophy.h +++ b/rpcs3/Emu/Cell/Modules/sceNpTrophy.h @@ -2,6 +2,7 @@ #include "stdafx.h" #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // Error codes enum SceNpTrophyError : u32 diff --git a/rpcs3/Emu/Cell/PPUThread.h b/rpcs3/Emu/Cell/PPUThread.h index 15b4039b93..e1d148c1a8 100644 --- a/rpcs3/Emu/Cell/PPUThread.h +++ b/rpcs3/Emu/Cell/PPUThread.h @@ -318,20 +318,6 @@ struct ppu_gpr_cast_impl } }; -template<> -struct ppu_gpr_cast_impl -{ - static inline u64 to(const error_code& code) - { - return code; - } - - static inline error_code from(const u64 reg) - { - return not_an_error(reg); - } -}; - template struct ppu_gpr_cast_impl, void> { diff --git a/rpcs3/Emu/Cell/lv2/sys_bdemu.h b/rpcs3/Emu/Cell/lv2/sys_bdemu.h index e3771e253c..4093f8b54f 100644 --- a/rpcs3/Emu/Cell/lv2/sys_bdemu.h +++ b/rpcs3/Emu/Cell/lv2/sys_bdemu.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // SysCalls diff --git a/rpcs3/Emu/Cell/lv2/sys_btsetting.h b/rpcs3/Emu/Cell/lv2/sys_btsetting.h index 9d8ab2c3e4..9224bf0e06 100644 --- a/rpcs3/Emu/Cell/lv2/sys_btsetting.h +++ b/rpcs3/Emu/Cell/lv2/sys_btsetting.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // SysCalls diff --git a/rpcs3/Emu/Cell/lv2/sys_crypto_engine.h b/rpcs3/Emu/Cell/lv2/sys_crypto_engine.h index d100fce56e..a9be56ee25 100644 --- a/rpcs3/Emu/Cell/lv2/sys_crypto_engine.h +++ b/rpcs3/Emu/Cell/lv2/sys_crypto_engine.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // SysCalls diff --git a/rpcs3/Emu/Cell/lv2/sys_dbg.h b/rpcs3/Emu/Cell/lv2/sys_dbg.h index e142d732a2..0f3a740ee9 100644 --- a/rpcs3/Emu/Cell/lv2/sys_dbg.h +++ b/rpcs3/Emu/Cell/lv2/sys_dbg.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // Syscalls diff --git a/rpcs3/Emu/Cell/lv2/sys_gpio.h b/rpcs3/Emu/Cell/lv2/sys_gpio.h index f312542c72..3208c4f7f9 100644 --- a/rpcs3/Emu/Cell/lv2/sys_gpio.h +++ b/rpcs3/Emu/Cell/lv2/sys_gpio.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" enum : u64 { diff --git a/rpcs3/Emu/Cell/lv2/sys_memory.h b/rpcs3/Emu/Cell/lv2/sys_memory.h index d2456733b9..eac4ddbfbd 100644 --- a/rpcs3/Emu/Cell/lv2/sys_memory.h +++ b/rpcs3/Emu/Cell/lv2/sys_memory.h @@ -2,6 +2,7 @@ #include "Emu/Memory/vm_ptr.h" #include "Emu/IdManager.h" +#include "Emu/Cell/ErrorCodes.h" class cpu_thread; diff --git a/rpcs3/Emu/Cell/lv2/sys_mmapper.h b/rpcs3/Emu/Cell/lv2/sys_mmapper.h index 13244c4b90..7a6506e638 100644 --- a/rpcs3/Emu/Cell/lv2/sys_mmapper.h +++ b/rpcs3/Emu/Cell/lv2/sys_mmapper.h @@ -3,6 +3,7 @@ #include "sys_sync.h" #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" #include diff --git a/rpcs3/Emu/Cell/lv2/sys_net.h b/rpcs3/Emu/Cell/lv2/sys_net.h index 2a563a5b61..ae6b10571a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_net.h +++ b/rpcs3/Emu/Cell/lv2/sys_net.h @@ -4,6 +4,7 @@ #include "Utilities/mutex.h" #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" #include #include diff --git a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.h b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.h index 0f8bcd34d3..7aad07d40a 100644 --- a/rpcs3/Emu/Cell/lv2/sys_ppu_thread.h +++ b/rpcs3/Emu/Cell/lv2/sys_ppu_thread.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" class ppu_thread; diff --git a/rpcs3/Emu/Cell/lv2/sys_process.h b/rpcs3/Emu/Cell/lv2/sys_process.h index 784d2b44c8..3ce1714a5d 100644 --- a/rpcs3/Emu/Cell/lv2/sys_process.h +++ b/rpcs3/Emu/Cell/lv2/sys_process.h @@ -2,6 +2,7 @@ #include "Crypto/unself.h" #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // Process Local Object Type enum : u32 @@ -37,7 +38,7 @@ struct sys_exit2_param vm::bpptr args; }; -struct ps3_process_info_t +struct ps3_process_info_t { u32 sdk_ver; u32 ppc_seg; diff --git a/rpcs3/Emu/Cell/lv2/sys_prx.h b/rpcs3/Emu/Cell/lv2/sys_prx.h index c4612357a3..bbbbfa8c79 100644 --- a/rpcs3/Emu/Cell/lv2/sys_prx.h +++ b/rpcs3/Emu/Cell/lv2/sys_prx.h @@ -3,6 +3,7 @@ #include "sys_sync.h" #include "Emu/Cell/PPUAnalyser.h" +#include "Emu/Cell/ErrorCodes.h" #include "Emu/Memory/vm_ptr.h" // Return codes diff --git a/rpcs3/Emu/Cell/lv2/sys_rsx.h b/rpcs3/Emu/Cell/lv2/sys_rsx.h index 885148ac0a..db44c0e71c 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsx.h +++ b/rpcs3/Emu/Cell/lv2/sys_rsx.h @@ -2,6 +2,7 @@ #include "Utilities/mutex.h" #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" class cpu_thread; diff --git a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h index b3802d6146..445080c2f4 100644 --- a/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h +++ b/rpcs3/Emu/Cell/lv2/sys_rsxaudio.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // SysCalls diff --git a/rpcs3/Emu/Cell/lv2/sys_sm.h b/rpcs3/Emu/Cell/lv2/sys_sm.h index 71dbbd64b8..bcf43d2e82 100644 --- a/rpcs3/Emu/Cell/lv2/sys_sm.h +++ b/rpcs3/Emu/Cell/lv2/sys_sm.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // SysCalls diff --git a/rpcs3/Emu/Cell/lv2/sys_spu.h b/rpcs3/Emu/Cell/lv2/sys_spu.h index 169d8ce7d4..b533b5848f 100644 --- a/rpcs3/Emu/Cell/lv2/sys_spu.h +++ b/rpcs3/Emu/Cell/lv2/sys_spu.h @@ -3,6 +3,7 @@ #include "sys_sync.h" #include "sys_event.h" #include "Emu/Cell/SPUThread.h" +#include "Emu/Cell/ErrorCodes.h" #include "Emu/Memory/vm_ptr.h" #include "Utilities/File.h" diff --git a/rpcs3/Emu/Cell/lv2/sys_storage.h b/rpcs3/Emu/Cell/lv2/sys_storage.h index 737eebbdf8..b5f87ad6d6 100644 --- a/rpcs3/Emu/Cell/lv2/sys_storage.h +++ b/rpcs3/Emu/Cell/lv2/sys_storage.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" struct StorageDeviceInfo { diff --git a/rpcs3/Emu/Cell/lv2/sys_time.h b/rpcs3/Emu/Cell/lv2/sys_time.h index df7f7f9c61..3e72ee1aae 100644 --- a/rpcs3/Emu/Cell/lv2/sys_time.h +++ b/rpcs3/Emu/Cell/lv2/sys_time.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" // SysCalls diff --git a/rpcs3/Emu/Cell/lv2/sys_usbd.h b/rpcs3/Emu/Cell/lv2/sys_usbd.h index 1978259dbe..3f829cd900 100644 --- a/rpcs3/Emu/Cell/lv2/sys_usbd.h +++ b/rpcs3/Emu/Cell/lv2/sys_usbd.h @@ -1,6 +1,7 @@ #pragma once #include "Emu/Memory/vm_ptr.h" +#include "Emu/Cell/ErrorCodes.h" class ppu_thread; diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index 1af3ab1990..2fa324bafe 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -5,6 +5,7 @@ #include "Emu/System.h" #include "Emu/perf_meter.hpp" +#include "Emu/Cell/ErrorCodes.h" #include "Emu/Cell/PPUThread.h" #include "Emu/Cell/PPUCallback.h" #include "Emu/Cell/PPUOpcodes.h"