Home | History | Annotate | Download | only in Common
      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 
     18 #if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
     19 #include "DebugAndroid.hpp"
     20 #else
     21 
     22 #include <assert.h>
     23 #include <stdio.h>
     24 
     25 #undef min
     26 #undef max
     27 
     28 namespace sw
     29 {
     30 void trace(const char *format, ...);
     31 inline void trace() {}
     32 }
     33 
     34 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
     35 	#define TRACE(format, ...) sw::trace("[0x%0.8X]%s(" format ")\n", this, __FUNCTION__, ##__VA_ARGS__)
     36 #else
     37 	#define TRACE(...) ((void)0)
     38 #endif
     39 
     40 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
     41 	#define UNIMPLEMENTED(...) do { \
     42 		sw::trace("\t! Unimplemented: %s(%d): ", __FUNCTION__, __LINE__); \
     43 		sw::trace(__VA_ARGS__); \
     44 		sw::trace("\n"); \
     45 		ASSERT(false); \
     46 	} while(0)
     47 #else
     48 	#define UNIMPLEMENTED(...) ((void)0)
     49 #endif
     50 
     51 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
     52 	#define ASSERT(expression) {if(!(expression)) sw::trace("\t! Assert failed in %s(%d): " #expression "\n", __FUNCTION__, __LINE__); assert(expression);}
     53 #else
     54 	#define ASSERT assert
     55 #endif
     56 
     57 #endif   // !__ANDROID__
     58 #endif   // Debug_hpp
     59