Move error_code to ErrorCodes.h

This commit is contained in:
Nekotekina 2020-12-12 14:24:01 +03:00
parent b09b7c1184
commit dff4392c10
26 changed files with 101 additions and 75 deletions

View File

@ -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<typename ET, typename = void>
struct is_error : std::integral_constant<bool, std::is_enum<ET>::value || std::is_integral<ET>::value>
{
};
template<typename ET>
struct is_error<ET, std::enable_if_t<sizeof(ET::__not_an_error) != 0>> : std::false_type
{
};
// Common constructor
template<typename ET>
error_code(const ET& value)
: value(static_cast<s32>(value))
{
if constexpr(is_error<ET>::value)
{
this->value = error_report(fmt::get_type_info<fmt_unveil_t<ET>>(), fmt_unveil<ET>::get(value), nullptr, 0);
}
}
// Error constructor (2 args)
template<typename ET, typename T2>
error_code(const ET& value, const T2& value2)
: value(error_report(fmt::get_type_info<fmt_unveil_t<ET>>(), fmt_unveil<ET>::get(value), fmt::get_type_info<fmt_unveil_t<T2>>(), fmt_unveil<T2>::get(value2)))
{
}
operator s32() const
{
return value;
}
};
// Helper function for error_code
template <typename T>
constexpr FORCE_INLINE error_code::not_an_error not_an_error(const T& value)
{
return static_cast<error_code::not_an_error>(static_cast<s32>(value));
}
// Synchronization helper (cache-friendly busy waiting)
inline void busy_wait(std::size_t cycles = 3000)
{

View File

@ -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<typename ET, typename = void>
struct is_error : std::integral_constant<bool, std::is_enum<ET>::value || std::is_integral<ET>::value>
{
};
template<typename ET>
struct is_error<ET, std::enable_if_t<sizeof(ET::__not_an_error) != 0>> : std::false_type
{
};
// Common constructor
template<typename ET>
error_code(const ET& value)
: value(static_cast<s32>(value))
{
if constexpr(is_error<ET>::value)
{
this->value = error_report(fmt::get_type_info<fmt_unveil_t<ET>>(), fmt_unveil<ET>::get(value), nullptr, 0);
}
}
// Error constructor (2 args)
template<typename ET, typename T2>
error_code(const ET& value, const T2& value2)
: value(error_report(fmt::get_type_info<fmt_unveil_t<ET>>(), fmt_unveil<ET>::get(value), fmt::get_type_info<fmt_unveil_t<T2>>(), fmt_unveil<T2>::get(value2)))
{
}
operator s32() const
{
return value;
}
};
// Helper function for error_code
template <typename T>
constexpr FORCE_INLINE error_code::not_an_error not_an_error(const T& value)
{
return static_cast<error_code::not_an_error>(static_cast<s32>(value));
}
template <typename T, typename>
struct ppu_gpr_cast_impl;
template <>
struct ppu_gpr_cast_impl<error_code, void>
{
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,

View File

@ -2,6 +2,7 @@
#include "Utilities/BitField.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
enum
{

View File

@ -2,6 +2,7 @@
#include "Utilities/BEType.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// Return Codes
enum CellRtcError

View File

@ -1,6 +1,7 @@
#pragma once
#include "cellRtc.h"
#include "Emu/Cell/ErrorCodes.h"
#include "Utilities/BEType.h"

View File

@ -2,6 +2,7 @@
#include "stdafx.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// Error codes
enum SceNpTrophyError : u32

View File

@ -318,20 +318,6 @@ struct ppu_gpr_cast_impl<b8, void>
}
};
template<>
struct ppu_gpr_cast_impl<error_code, void>
{
static inline u64 to(const error_code& code)
{
return code;
}
static inline error_code from(const u64 reg)
{
return not_an_error(reg);
}
};
template<typename T, typename AT>
struct ppu_gpr_cast_impl<vm::_ptr_base<T, AT>, void>
{

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// SysCalls

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// SysCalls

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// SysCalls

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// Syscalls

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
enum : u64
{

View File

@ -2,6 +2,7 @@
#include "Emu/Memory/vm_ptr.h"
#include "Emu/IdManager.h"
#include "Emu/Cell/ErrorCodes.h"
class cpu_thread;

View File

@ -3,6 +3,7 @@
#include "sys_sync.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
#include <vector>

View File

@ -4,6 +4,7 @@
#include "Utilities/mutex.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
#include <vector>
#include <utility>

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
class ppu_thread;

View File

@ -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<char, u64, u64> args;
};
struct ps3_process_info_t
struct ps3_process_info_t
{
u32 sdk_ver;
u32 ppc_seg;

View File

@ -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

View File

@ -2,6 +2,7 @@
#include "Utilities/mutex.h"
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
class cpu_thread;

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// SysCalls

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// SysCalls

View File

@ -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"

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
struct StorageDeviceInfo
{

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
// SysCalls

View File

@ -1,6 +1,7 @@
#pragma once
#include "Emu/Memory/vm_ptr.h"
#include "Emu/Cell/ErrorCodes.h"
class ppu_thread;

View File

@ -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"