xref: /aosp_15_r20/external/swiftshader/src/Reactor/Assert.hpp (revision 03ce13f70fcc45d86ee91b7ee4cab1936a95046e)
1 // Copyright 2021 The SwiftShader Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef rr_Assert_hpp
16 #define rr_Assert_hpp
17 
18 #include "Reactor.hpp"
19 
20 namespace rr {
21 
22 void failedAssert(const char *expression, const char *file, unsigned int line, const char *func);
23 
24 #if defined(_MSC_VER)
25 #	define FUNCSIG __FUNCSIG__
26 #elif defined(__clang__) || defined(__GNUC__)
27 #	define FUNCSIG __PRETTY_FUNCTION__
28 #else
29 #	define FUNCSIG __func__
30 #endif
31 
32 #ifdef NDEBUG
33 #	define Assert(expression) ((void)0)
34 #else
35 #	define Assert(expression)                                                                                                        \
36 		If(!(expression))                                                                                                             \
37 		{                                                                                                                             \
38 			Call(failedAssert, ConstantPointer(#expression), ConstantPointer(__FILE__), rr::Int(__LINE__), ConstantPointer(FUNCSIG)); \
39 		};
40 #endif
41 
42 }  // namespace rr
43 
44 #endif  // rr_Assert_hpp
45