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 // debug.h: Debugging utilities.
16
17 #ifndef COMPILER_DEBUG_H_
18 #define COMPILER_DEBUG_H_
19
20 #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD) && !defined(ANDROID_NDK_BUILD)
21 #include "../../Common/DebugAndroid.hpp"
22
23 #define Trace(...) ((void)0)
24 #else
25
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 namespace sh {
34 #ifdef TRACE_ENABLED
35 void Trace(const char* format, ...);
36 #else
37 inline void Trace(const char* format, ...) {}
38 #endif
Trace()39 inline void Trace() {}
40 }
41
42 // A macro asserting a condition and outputting failures to the debug log
43 #undef ASSERT
44 #define ASSERT(expression) do { \
45 if(!(expression)) \
46 sh::Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
47 assert(expression); \
48 } while(0)
49
50 #undef UNIMPLEMENTED
51 #define UNIMPLEMENTED(...) do { \
52 sh::Trace("Unimplemented invoked: %s(%d): ", __FUNCTION__, __LINE__); \
53 sh::Trace(__VA_ARGS__); \
54 sh::Trace("\n"); \
55 assert(false); \
56 } while(0)
57
58 #undef UNREACHABLE
59 #define UNREACHABLE(value) do { \
60 sh::Trace("Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value); \
61 assert(false); \
62 } while(0)
63
64 #endif // !__ANDROID__
65 #endif // COMPILER_DEBUG_H_
66
67