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 | |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 20 | #ifdef __ANDROID__ |
| 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 |
| 33 | #ifdef TRACE_ENABLED |
| 34 | |
| 35 | #ifdef __cplusplus |
| 36 | extern "C" { |
| 37 | #endif // __cplusplus |
| 38 | void Trace(const char* format, ...); |
| 39 | #ifdef __cplusplus |
| 40 | } |
| 41 | #endif // __cplusplus |
| 42 | |
| 43 | #else // TRACE_ENABLED |
| 44 | |
| 45 | #define Trace(...) ((void)0) |
| 46 | |
| 47 | #endif // TRACE_ENABLED |
| 48 | |
| 49 | // A macro asserting a condition and outputting failures to the debug log |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 50 | #undef ASSERT |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 51 | #define ASSERT(expression) do { \ |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 52 | if(!(expression)) \ |
| 53 | Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \ |
| 54 | assert(expression); \ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 55 | } while(0) |
| 56 | |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 57 | #undef UNIMPLEMENTED |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 58 | #define UNIMPLEMENTED() do { \ |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 59 | Trace("Unimplemented invoked: %s(%d)\n", __FUNCTION__, __LINE__); \ |
| 60 | assert(false); \ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 61 | } while(0) |
| 62 | |
Nicolas Capens | 3713cd4 | 2015-06-22 10:41:54 -0400 | [diff] [blame] | 63 | #undef UNREACHABLE |
| 64 | #define UNREACHABLE(value) do { \ |
Nicolas Capens | 0bac285 | 2016-05-07 06:09:58 -0400 | [diff] [blame] | 65 | Trace("Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value); \ |
| 66 | assert(false); \ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 67 | } while(0) |
| 68 | |
Greg Hartman | d61ac5f | 2015-04-09 18:48:53 -0700 | [diff] [blame] | 69 | #endif // __ANDROID__ |
John Bauman | 66b8ab2 | 2014-05-06 15:57:45 -0400 | [diff] [blame] | 70 | #endif // COMPILER_DEBUG_H_ |
| 71 | |