2023-11-30 06:50:02 +00:00
|
|
|
#ifndef _ASSERT
|
|
|
|
#define _ASSERT
|
2023-03-30 02:27:34 +00:00
|
|
|
#include "musyx/version.h"
|
2023-11-30 06:50:02 +00:00
|
|
|
#include "musyx/platform.h"
|
2022-12-24 22:54:58 +00:00
|
|
|
|
2023-11-30 06:50:02 +00:00
|
|
|
#if MUSY_TARGET == MUSY_TARGET_DOLPHIN
|
2022-12-24 22:54:58 +00:00
|
|
|
extern void OSPanic(const char* file, int line, const char* msg, ...);
|
2023-02-24 17:42:08 +00:00
|
|
|
extern void OSReport(const char* msg, ...);
|
2022-12-24 22:54:58 +00:00
|
|
|
|
2023-11-30 06:50:02 +00:00
|
|
|
#ifndef MUSY_PANIC
|
|
|
|
#define MUSY_PANIC OSPanic
|
|
|
|
#endif
|
|
|
|
#ifndef MUSY_REPORT
|
|
|
|
#define MUSY_REPORT OSReport
|
|
|
|
#endif
|
|
|
|
#elif MUSY_TARGET == MUSY_TARGET_PC
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#ifndef MUSY_PANIC
|
|
|
|
#define MUSY_PANIC assert
|
|
|
|
#endif
|
|
|
|
#ifndef MUSY_REPORT
|
|
|
|
#define MUSY_REPORT printf
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// TODO: Cleanup
|
2023-03-30 02:27:34 +00:00
|
|
|
static inline unsigned __SOME_ASSERT_DERP1() { return 0; }
|
2023-02-27 14:14:29 +00:00
|
|
|
|
2023-03-30 02:27:34 +00:00
|
|
|
static inline unsigned __SOME_ASSERT_DERP2() { return __SOME_ASSERT_DERP1(); }
|
2023-02-27 14:14:29 +00:00
|
|
|
|
2023-03-30 02:27:34 +00:00
|
|
|
static inline void __SOME_ASSERT_DERP() { __SOME_ASSERT_DERP2() != 0; }
|
2023-02-27 14:14:29 +00:00
|
|
|
|
2023-11-30 06:50:02 +00:00
|
|
|
#ifndef MUSY_ASSERT
|
2022-12-24 22:54:58 +00:00
|
|
|
#ifdef _DEBUG
|
2023-03-30 02:27:34 +00:00
|
|
|
#define MUSY_ASSERT(cond) \
|
|
|
|
do { \
|
|
|
|
if (!(cond)) { \
|
2023-11-30 06:50:02 +00:00
|
|
|
MUSY_PANIC(__FILE__, __LINE__, "Failed assertion " #cond); \
|
2023-03-30 02:27:34 +00:00
|
|
|
} \
|
|
|
|
__SOME_ASSERT_DERP(); \
|
|
|
|
} while (0)
|
2022-12-24 22:54:58 +00:00
|
|
|
#else
|
2023-02-27 14:14:29 +00:00
|
|
|
#define MUSY_ASSERT(cond)
|
2022-12-24 22:54:58 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-02-27 14:14:29 +00:00
|
|
|
#ifndef MUSY_ASSERT_MSG
|
2022-12-24 22:54:58 +00:00
|
|
|
#ifdef _DEBUG
|
2023-10-23 19:22:07 +00:00
|
|
|
#if MUSY_VERSION >= MUSY_VERSION_CHECK(2, 0, 0)
|
2023-03-30 02:27:34 +00:00
|
|
|
#define MUSY_ASSERT_MSG(cond, msg) \
|
|
|
|
do { \
|
|
|
|
s32 tmp = 1; \
|
|
|
|
s32 tmp2; \
|
|
|
|
if (!(cond)) { \
|
2023-11-30 06:50:02 +00:00
|
|
|
MUSY_PANIC(__FILE__, __LINE__, msg); \
|
2023-03-30 02:27:34 +00:00
|
|
|
tmp2 = 0; \
|
|
|
|
if (tmp2 == 0) { \
|
|
|
|
tmp = 0; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#else
|
|
|
|
#define MUSY_ASSERT_MSG(cond, msg) \
|
|
|
|
do { \
|
|
|
|
if (!(cond)) { \
|
2023-11-30 06:50:02 +00:00
|
|
|
MUSY_PANIC(__FILE__, __LINE__, msg); \
|
2023-03-30 02:27:34 +00:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
#endif
|
2022-12-24 22:54:58 +00:00
|
|
|
#else
|
2023-02-27 14:14:29 +00:00
|
|
|
#define MUSY_ASSERT_MSG(cond, msg)
|
2022-12-24 22:54:58 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-02-23 07:04:07 +00:00
|
|
|
#ifndef MUSY_DEBUG
|
2023-02-24 17:42:08 +00:00
|
|
|
#ifdef _DEBUG
|
2023-11-30 06:50:02 +00:00
|
|
|
#define MUSY_DEBUG MUSY_REPORT
|
2023-03-30 02:27:34 +00:00
|
|
|
#else
|
2023-02-23 07:04:07 +00:00
|
|
|
#define MUSY_DEBUG
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-03-30 02:27:34 +00:00
|
|
|
#ifndef MUSY_FATAL
|
|
|
|
#ifdef _DEBUG
|
2023-11-30 06:50:02 +00:00
|
|
|
#define MUSY_FATAL(msg) MUSY_PANIC(__FILE__, __LINE__, msg)
|
2023-03-30 02:27:34 +00:00
|
|
|
#else
|
|
|
|
#define MUSY_FATAL
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2023-11-30 06:50:02 +00:00
|
|
|
#endif // _ASSERT
|