Twilight Princess
Decompilation of The Legend of Zelda: Twilight Princess
Loading...
Searching...
No Matches
assert.h
Go to the documentation of this file.
1#ifndef NW4R_DB_ASSERT_H
2#define NW4R_DB_ASSERT_H
3
4#include <revolution/types.h>
5
6#include <cstdio>
7
8namespace nw4hbm {
9 namespace db {
10 // Forward declarations
11 namespace detail {
12 class ConsoleHead;
13 }
14
15 /* DECL_WEAK */ void VPanic(const char* file, int line, const char* fmt, std::va_list vlist);
16 /* DECL_WEAK */ void VWarning(const char* file, int line, const char* fmt, std::va_list vlist);
17
18 namespace detail {
19 void Log(const char* fmt, ...);
20 /* DECL_WEAK */ void Panic(const char* file, int line, const char* fmt, ...);
21 /* DECL_WEAK */ void Warning(const char* file, int line, const char* msg, ...);
22 }
23
24 detail::ConsoleHead* Assertion_SetConsole(detail::ConsoleHead* console);
25 detail::ConsoleHead* Assertion_GetConsole();
29 bool Assertion_SetAutoWarning(bool enable);
30 } // namespace db
31} // namespace nw4r
32
33#if NW4HBM_DEBUG
34#define NW4R_DB_WARNING(line, exp, ...) \
35 (void)((exp) || (nw4hbm::db::detail::Warning(__FILE__, line, __VA_ARGS__), 0))
36#define NW4R_DB_ASSERTMSG(line, exp, ...) \
37 (void)((exp) || (nw4hbm::db::detail::Panic(__FILE__, line, __VA_ARGS__), 0))
38#else
39#define NW4R_DB_WARNING(line, exp, ...) (void)0
40#define NW4R_DB_ASSERTMSG(line, exp, ...) (void)0
41#endif
42
43#define NW4R_ASSERT(line, exp) \
44 NW4R_DB_ASSERTMSG(line, (exp), "Failed assertion " #exp)
45
46#define NW4R_ASSERT_CHECK_NULL(line, ptr) \
47 NW4R_DB_ASSERTMSG(line, (ptr != NULL), "Pointer must not be NULL ("#ptr")")
48
49#define POINTER_VALID_TEST(ptr_) \
50 (((unsigned long)ptr_ & 0xFF000000) == 0x80000000 || ((unsigned long)ptr_ & 0xFF800000) == 0x81000000 || \
51 ((unsigned long)ptr_ & 0xF8000000) == 0x90000000 || ((unsigned long)ptr_ & 0xFF000000) == 0xC0000000 || \
52 ((unsigned long)ptr_ & 0xFF800000) == 0xC1000000 || ((unsigned long)ptr_ & 0xF8000000) == 0xD0000000 || \
53 ((unsigned long)ptr_ & 0xFFFFC000) == 0xE0000000)
54
55#define NW4R_ASSERT_VALID_PTR(line, ptr) \
56 NW4R_DB_ASSERTMSG(line, POINTER_VALID_TEST(ptr), "Pointer Error\n" #ptr "(=%p) is not valid pointer.", ptr)
57
58#define NW4R_ASSERT_MIN(line_, var_, minValue_) \
59 NW4R_DB_ASSERTMSG(line_, minValue_ <= var_, \
60 #var_ " is out of bounds(%d)\n%d <= " #var_ " not satisfied.", (int)(var_), \
61 (int)(minValue_))
62
63#define NW4R_ASSERT_MINMAX(line_, var_, minValue_, maxValue_) \
64 NW4R_DB_ASSERTMSG(line_, (var_) >= (minValue_) && (var_) < (maxValue_), \
65 #var_ " is out of bounds(%d)\n%d <= " #var_ " < %d not satisfied.", (int)(var_), \
66 (int)(minValue_), (int)(maxValue_))
67
68#define NW4R_ASSERT_MINMAXLT(line_, var_, minValue_, maxValue_) \
69 NW4R_DB_ASSERTMSG(line_, (var_) >= (minValue_) && (var_) <= (maxValue_), \
70 #var_ " is out of bounds(%d)\n%d <= " #var_ " <= %d not satisfied.", (int)(var_), \
71 (int)(minValue_), (int)(maxValue_))
72
73#define NW4R_IS_ALIGNED_(x, align) \
74 (((unsigned long)(x) & ((align) - 1)) == 0)
75
76#define NW4R_ASSERT_ALIGN2(line, exp) \
77 NW4R_DB_ASSERTMSG(line, NW4R_IS_ALIGNED_(exp, 2), \
78 "Alignment Error(0x%x)\n" #exp " must be aligned to 2 bytes boundary.", \
79 exp)
80
81#define NW4R_ASSERT_ALIGN32(line, exp) \
82 NW4R_DB_ASSERTMSG(line, NW4R_IS_ALIGNED_(exp, 32), \
83 "Alignment Error(0x%x)\n" #exp " must be aligned to 32 bytes boundary.", \
84 exp)
85
86// NW4HBM variants
87#define NW4HBM_ASSERT_CHECK_NULL(line, ptr) \
88 NW4R_DB_ASSERTMSG(line, (ptr != NULL), "NW4HBM:Pointer must not be NULL ("#ptr")")
89
90#define NW4HBM_ASSERT(line, exp) \
91 NW4R_DB_ASSERTMSG(line, (exp), "NW4HBM:Failed assertion " #exp)
92
93#define NW4HBM_ASSERT_VALID_PTR(line, ptr) \
94 NW4R_DB_ASSERTMSG(line, POINTER_VALID_TEST(ptr), "NW4HBM:Pointer Error\n" #ptr "(=%p) is not valid pointer.", ptr)
95
96#define NW4HBM_ASSERT_ALIGN2(line, exp) \
97 NW4R_DB_ASSERTMSG(line, NW4R_IS_ALIGNED_(exp, 2), \
98 "NW4HBM:Alignment Error(0x%x)\n" #exp " must be aligned to 2 bytes boundary.", \
99 exp)
100
101#define NW4HBM_ASSERT_ALIGN32(line, exp) \
102 NW4R_DB_ASSERTMSG(line, NW4R_IS_ALIGNED_(exp, 32), \
103 "NW4HBM:Alignment Error(0x%x)\n" #exp " must be aligned to 32 bytes boundary.", \
104 exp)
105
106#define NW4HBM_ASSERT_ALIGNED(line, exp, align) \
107 NW4R_DB_ASSERTMSG(line, NW4R_IS_ALIGNED_(exp, align), \
108 "NW4HBM:Alignment Error(0x%x)\n" #exp " must be aligned to " #align " bytes boundary.", \
109 exp)
110
111#endif
OSTime time
Definition GXInit.c:34
unsigned long u32
Definition types.h:12
void Log(const char *fmt,...)
Definition db_assert.cpp:144
void Warning(const char *file, int line, const char *msg,...)
Definition db_assert.cpp:127
void Panic(const char *file, int line, const char *fmt,...)
Definition db_assert.cpp:104
void VWarning(const char *file, int line, const char *fmt, std::va_list vlist)
Definition db_assert.cpp:113
void Assertion_HideConsole()
Definition db_assert.cpp:170
detail::ConsoleHead * Assertion_SetConsole(detail::ConsoleHead *console)
Definition db_assert.cpp:149
detail::ConsoleHead * Assertion_GetConsole()
Definition db_assert.cpp:155
void Assertion_SetWarningTime(u32 time)
Definition db_assert.cpp:174
bool Assertion_SetAutoWarning(bool enable)
void Assertion_ShowConsole(u32 time)
Definition db_assert.cpp:159
void VPanic(const char *file, int line, const char *fmt, std::va_list vlist)
Definition db_assert.cpp:70
Definition HBMAnmController.h:6
Definition console.h:13