2024-07-30 11:42:36 +00:00
|
|
|
// SPDX-FileCopyrightText: 2002-2024 PCSX2 Dev Team
|
|
|
|
// SPDX-License-Identifier: GPL-3.0+
|
2009-11-16 00:40:09 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-01 20:31:46 +00:00
|
|
|
#include "common/Pcsx2Defs.h"
|
|
|
|
|
2009-12-14 12:18:55 +00:00
|
|
|
#ifndef __pxFUNCTION__
|
|
|
|
#if defined(__GNUG__)
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __pxFUNCTION__ __PRETTY_FUNCTION__
|
2009-12-14 12:18:55 +00:00
|
|
|
#else
|
2016-11-12 15:28:37 +00:00
|
|
|
#define __pxFUNCTION__ __FUNCTION__
|
2009-12-14 12:18:55 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-12-22 10:30:31 +00:00
|
|
|
// pxAssertRel - assertion check even in Release builds.
|
|
|
|
// pxFailRel - aborts program even in Release builds.
|
|
|
|
//
|
|
|
|
// pxAssert[Msg] - assertion check only in Debug/Devel builds, noop in Release.
|
|
|
|
// pxAssume[Msg] - assertion check in Debug/Devel builds, optimization hint in Release builds.
|
|
|
|
// pxFail - aborts program only in Debug/Devel builds, noop in Release.
|
2009-12-14 12:18:55 +00:00
|
|
|
|
2022-05-24 11:21:31 +00:00
|
|
|
extern void pxOnAssertFail(const char* file, int line, const char* func, const char* msg);
|
|
|
|
|
2023-12-22 10:30:31 +00:00
|
|
|
#define pxAssertRel(cond, msg) do { if (!(cond)) [[unlikely]] { pxOnAssertFail(__FILE__, __LINE__, __pxFUNCTION__, msg); } } while(0)
|
|
|
|
#define pxFailRel(msg) pxOnAssertFail(__FILE__, __LINE__, __pxFUNCTION__, msg)
|
2009-11-16 00:40:09 +00:00
|
|
|
|
2023-12-22 10:30:31 +00:00
|
|
|
#if defined(PCSX2_DEBUG) || defined(PCSX2_DEVBUILD)
|
2009-11-16 00:40:09 +00:00
|
|
|
|
2016-11-12 15:28:37 +00:00
|
|
|
#define pxAssertMsg(cond, msg) pxAssertRel(cond, msg)
|
2023-12-22 10:30:31 +00:00
|
|
|
#define pxAssumeMsg(cond, msg) pxAssertRel(cond, msg)
|
|
|
|
#define pxFail(msg) pxFailRel(msg)
|
2009-11-16 00:40:09 +00:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2023-12-22 10:30:31 +00:00
|
|
|
#define pxAssertMsg(cond, msg) ((void)0)
|
|
|
|
#define pxAssumeMsg(cond, msg) ASSUME(cond)
|
|
|
|
#define pxFail(msg) ((void)0)
|
2009-11-16 00:40:09 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2022-05-29 13:54:53 +00:00
|
|
|
#define pxAssert(cond) pxAssertMsg(cond, #cond)
|
|
|
|
#define pxAssume(cond) pxAssumeMsg(cond, #cond)
|
2009-12-14 12:18:55 +00:00
|
|
|
|
2023-12-22 10:30:31 +00:00
|
|
|
// jNO_DEFAULT -- disables the default case in a switch, which improves switch optimization.
|
2021-09-06 18:28:26 +00:00
|
|
|
#define jNO_DEFAULT \
|
|
|
|
default: \
|
|
|
|
{ \
|
2023-12-22 10:30:31 +00:00
|
|
|
pxAssumeMsg(false, "Incorrect usage of jNO_DEFAULT detected (default case is not unreachable!)"); \
|
2021-09-06 18:28:26 +00:00
|
|
|
break; \
|
|
|
|
}
|