Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // 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 White | e6ab01f | 2019-04-04 14:31:25 -0400 | [diff] [blame] | 18 | #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD) |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 19 | #include "DebugAndroid.hpp" |
| 20 | #else |
| 21 | |
| 22 | #include <assert.h> |
| 23 | #include <stdio.h> |
| 24 | |
| 25 | #undef min |
| 26 | #undef max |
| 27 | |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 28 | namespace sw |
| 29 | { |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 30 | void trace(const char *format, ...); |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 31 | inline void trace() {} |
| 32 | } |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 33 | |
Alexis Hetu | 0c5035b | 2017-09-20 15:55:08 -0400 | [diff] [blame] | 34 | #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 35 | #define TRACE(format, ...) sw::trace("[0x%0.8X]%s(" format ")\n", this, __FUNCTION__, ##__VA_ARGS__) |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 36 | #else |
| 37 | #define TRACE(...) ((void)0) |
| 38 | #endif |
| 39 | |
Alexis Hetu | 0c5035b | 2017-09-20 15:55:08 -0400 | [diff] [blame] | 40 | #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 41 | #define UNIMPLEMENTED(...) do { \ |
| 42 | sw::trace("\t! Unimplemented: %s(%d): ", __FUNCTION__, __LINE__); \ |
Nicolas Capens | 60be5c4 | 2018-10-02 10:49:22 -0400 | [diff] [blame] | 43 | sw::trace(__VA_ARGS__); \ |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 44 | sw::trace("\n"); \ |
| 45 | ASSERT(false); \ |
| 46 | } while(0) |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 47 | #else |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 48 | #define UNIMPLEMENTED(...) ((void)0) |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 49 | #endif |
| 50 | |
Alexis Hetu | 0c5035b | 2017-09-20 15:55:08 -0400 | [diff] [blame] | 51 | #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 52 | #define ASSERT(expression) {if(!(expression)) sw::trace("\t! Assert failed in %s(%d): " #expression "\n", __FUNCTION__, __LINE__); assert(expression);} |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 53 | #else |
| 54 | #define ASSERT assert |
| 55 | #endif |
| 56 | |
Nicolas Capens | a5dfd97d | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 57 | #endif // !__ANDROID__ |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 58 | #endif // Debug_hpp |