• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifdef __ANDROID__
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 #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
50 #undef ASSERT
51 #define ASSERT(expression) do { \
52 	if(!(expression)) \
53 		Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
54 	assert(expression); \
55 } while(0)
56 
57 #undef UNIMPLEMENTED
58 #define UNIMPLEMENTED() do { \
59 	Trace("Unimplemented invoked: %s(%d)\n", __FUNCTION__, __LINE__); \
60 	assert(false); \
61 } while(0)
62 
63 #undef UNREACHABLE
64 #define UNREACHABLE(value) do { \
65 	Trace("Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value); \
66 	assert(false); \
67 } while(0)
68 
69 #endif   // __ANDROID__
70 #endif   // COMPILER_DEBUG_H_
71 
72