blob: 0c862d4dc070e093dce33d4193d2de9aca3b15ea [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 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 Debug_hpp
16#define Debug_hpp
17
Stephen Whitee6ab01f2019-04-04 14:31:25 -040018#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
Nicolas Capens0bac2852016-05-07 06:09:58 -040019#include "DebugAndroid.hpp"
20#else
21
22#include <assert.h>
23#include <stdio.h>
24
25#undef min
26#undef max
27
Nicolas Capensa5dfd97d2018-09-28 15:27:08 -040028namespace sw
29{
Nicolas Capens0bac2852016-05-07 06:09:58 -040030void trace(const char *format, ...);
Nicolas Capensa5dfd97d2018-09-28 15:27:08 -040031inline void trace() {}
32}
Nicolas Capens0bac2852016-05-07 06:09:58 -040033
Alexis Hetu0c5035b2017-09-20 15:55:08 -040034#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
Nicolas Capensa5dfd97d2018-09-28 15:27:08 -040035 #define TRACE(format, ...) sw::trace("[0x%0.8X]%s(" format ")\n", this, __FUNCTION__, ##__VA_ARGS__)
Nicolas Capens0bac2852016-05-07 06:09:58 -040036#else
37 #define TRACE(...) ((void)0)
38#endif
39
Alexis Hetu0c5035b2017-09-20 15:55:08 -040040#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
Nicolas Capensa5dfd97d2018-09-28 15:27:08 -040041 #define UNIMPLEMENTED(...) do { \
42 sw::trace("\t! Unimplemented: %s(%d): ", __FUNCTION__, __LINE__); \
Nicolas Capens60be5c42018-10-02 10:49:22 -040043 sw::trace(__VA_ARGS__); \
Nicolas Capensa5dfd97d2018-09-28 15:27:08 -040044 sw::trace("\n"); \
45 ASSERT(false); \
46 } while(0)
Nicolas Capens0bac2852016-05-07 06:09:58 -040047#else
Nicolas Capensa5dfd97d2018-09-28 15:27:08 -040048 #define UNIMPLEMENTED(...) ((void)0)
Nicolas Capens0bac2852016-05-07 06:09:58 -040049#endif
50
Alexis Hetu0c5035b2017-09-20 15:55:08 -040051#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
Nicolas Capensa5dfd97d2018-09-28 15:27:08 -040052 #define ASSERT(expression) {if(!(expression)) sw::trace("\t! Assert failed in %s(%d): " #expression "\n", __FUNCTION__, __LINE__); assert(expression);}
Nicolas Capens0bac2852016-05-07 06:09:58 -040053#else
54 #define ASSERT assert
55#endif
56
Nicolas Capensa5dfd97d2018-09-28 15:27:08 -040057#endif // !__ANDROID__
Nicolas Capens0bac2852016-05-07 06:09:58 -040058#endif // Debug_hpp