blob: 78e848ae521a3b22d0438ec19d8fae595ab5d69c [file] [log] [blame]
Nicolas Capens08c62002021-11-17 00:25:05 -05001// 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
20namespace rr {
21
22void 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
Sean Risseree0d0b42022-04-20 16:27:26 -040035# define Assert(expression) \
36 If(!(expression)) \
37 { \
38 Call(failedAssert, ConstantPointer(#expression), ConstantPointer(__FILE__), rr::Int(__LINE__), ConstantPointer(FUNCSIG)); \
Nicolas Capens08c62002021-11-17 00:25:05 -050039 };
40#endif
41
42} // namespace rr
43
44#endif // rr_Assert_hpp