swr: [rasterizer] warning cleanup
[mesa.git] / src / gallium / drivers / swr / rasterizer / common / swr_assert.h
1 /****************************************************************************
2 * Copyright (C) 2014-2015 Intel Corporation. All Rights Reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 ****************************************************************************/
23
24 #ifndef __SWR_ASSERT_H__
25 #define __SWR_ASSERT_H__
26
27 #if !defined(__SWR_OS_H__)
28 #error swr_assert.h should not be included directly, please include "common/os.h" instead.
29 #endif
30
31 #if !defined(SWR_ENABLE_ASSERTS)
32
33 #if !defined(NDEBUG)
34 #define SWR_ENABLE_ASSERTS 1
35 #else
36 #define SWR_ENABLE_ASSERTS 0
37 #endif // _DEBUG
38
39 #endif // SWR_ENABLE_ASSERTS
40
41 #if !defined(SWR_ENABLE_REL_ASSERTS)
42 #define SWR_ENABLE_REL_ASSERTS 1
43 #endif
44
45 #if SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
46 #include "assert.h"
47
48 #if !defined(__cplusplus)
49
50 #pragma message("C++ is required for SWR Asserts, falling back to assert.h")
51
52 #if SWR_ENABLE_ASSERTS
53 #define SWR_ASSERT(e, ...) assert(e)
54 #endif
55
56 #if SWR_ENABLE_REL_ASSERTS
57 #define SWR_REL_ASSERT(e, ...) assert(e)
58 #endif
59
60 #else
61
62 bool SwrAssert(
63 bool chkDebugger,
64 bool& enabled,
65 const char* pExpression,
66 const char* pFileName,
67 uint32_t lineNum,
68 const char* function,
69 const char* pFmtString = nullptr,
70 ...);
71
72 #define _SWR_ASSERT(chkDebugger, e, ...) {\
73 bool expFailed = !(e);\
74 if (expFailed) {\
75 static bool swrAssertEnabled = true;\
76 expFailed = SwrAssert(chkDebugger, swrAssertEnabled, #e, __FILE__, __LINE__, __FUNCTION__, ##__VA_ARGS__);\
77 if (expFailed) { DEBUGBREAK; }\
78 }\
79 }
80
81 #if SWR_ENABLE_ASSERTS
82 #define SWR_ASSERT(e, ...) _SWR_ASSERT(true, e, ##__VA_ARGS__)
83
84 #if defined(assert)
85 #undef assert
86 #endif
87 #define assert(exp) SWR_ASSERT(exp)
88
89 #endif
90
91 #if SWR_ENABLE_REL_ASSERTS
92 #define SWR_REL_ASSERT(e, ...) _SWR_ASSERT(false, e, ##__VA_ARGS__)
93 #endif
94 #endif // C++
95
96 #endif // SWR_ENABLE_ASSERTS || SWR_ENABLE_REL_ASSERTS
97
98 #if !SWR_ENABLE_ASSERTS
99 #define SWR_ASSERT(e, ...) (void)(0)
100 #endif
101
102 #if !SWR_ENABLE_REL_ASSERTS
103 #define SWR_REL_ASSERT(e, ...) (void)(0)
104 #endif
105
106 #define SWR_NOT_IMPL SWR_ASSERT(0, "%s not implemented", __FUNCTION__)
107
108 #endif//__SWR_ASSERT_H__