Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 1 | // Copyright 2016 The SwiftShader Authors. All Rights Reserved. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 2 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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 |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 6 | // |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 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. |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 14 | |
| 15 | // debug.h: Debugging utilities. |
| 16 | |
| 17 | #ifndef COMPILER_DEBUG_H_ |
| 18 | #define COMPILER_DEBUG_H_ |
| 19 | |
Alistair Strachan | c28d28a | 2018-03-24 12:24:00 -0700 | [diff] [blame] | 20 | #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 21 | #include "../../Common/DebugAndroid.hpp" |
| 22 | |
| 23 | #define Trace(...) ((void)0) |
| 24 | #else |
| 25 | |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 26 | #include <assert.h> |
| 27 | |
| 28 | #ifdef _DEBUG |
| 29 | #define TRACE_ENABLED // define to enable debug message tracing |
| 30 | #endif // _DEBUG |
| 31 | |
| 32 | // Outputs text to the debug log |
Nicolas Capens | a5dfd97 | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 33 | namespace sh { |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 34 | #ifdef TRACE_ENABLED |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 35 | void Trace(const char* format, ...); |
Nicolas Capens | a5dfd97 | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 36 | #else |
| 37 | inline void Trace(const char* format, ...) {} |
| 38 | #endif |
| 39 | inline void Trace() {} |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 40 | } |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 41 | |
| 42 | // A macro asserting a condition and outputting failures to the debug log |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 43 | #undef ASSERT |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 44 | #define ASSERT(expression) do { \ |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 45 | if(!(expression)) \ |
Nicolas Capens | a5dfd97 | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 46 | sh::Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 47 | assert(expression); \ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 48 | } while(0) |
| 49 | |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 50 | #undef UNIMPLEMENTED |
Nicolas Capens | a5dfd97 | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 51 | #define UNIMPLEMENTED(...) do { \ |
| 52 | sh::Trace("Unimplemented invoked: %s(%d): ", __FUNCTION__, __LINE__); \ |
Nicolas Capens | 60be5c4 | 2018-10-02 10:49:22 -0400 | [diff] [blame^] | 53 | sh::Trace(__VA_ARGS__); \ |
Nicolas Capens | a5dfd97 | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 54 | sh::Trace("\n"); \ |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 55 | assert(false); \ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 56 | } while(0) |
| 57 | |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 58 | #undef UNREACHABLE |
| 59 | #define UNREACHABLE(value) do { \ |
Nicolas Capens | a5dfd97 | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 60 | sh::Trace("Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value); \ |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 61 | assert(false); \ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 62 | } while(0) |
| 63 | |
Nicolas Capens | a5dfd97 | 2018-09-28 15:27:08 -0400 | [diff] [blame] | 64 | #endif // !__ANDROID__ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 65 | #endif // COMPILER_DEBUG_H_ |
| 66 | |