blob: f9f92d54c12740f4ccdab5d34537463016544bd6 [file] [log] [blame]
Nicolas Capens0bac2852016-05-07 06:09:58 -04001// Copyright 2016 The SwiftShader Authors. All Rights Reserved.
John Bauman66b8ab22014-05-06 15:57:45 -04002//
Nicolas Capens0bac2852016-05-07 06:09:58 -04003// 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 Bauman66b8ab22014-05-06 15:57:45 -04006//
Nicolas Capens0bac2852016-05-07 06:09:58 -04007// 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 Bauman66b8ab22014-05-06 15:57:45 -040014
15// debug.h: Debugging utilities.
16
17#ifndef COMPILER_DEBUG_H_
18#define COMPILER_DEBUG_H_
19
Alistair Strachanc28d28a2018-03-24 12:24:00 -070020#if defined(__ANDROID__) && !defined(ANDROID_HOST_BUILD)
Greg Hartmand61ac5f2015-04-09 18:48:53 -070021#include "../../Common/DebugAndroid.hpp"
22
23#define Trace(...) ((void)0)
24#else
25
John Bauman66b8ab22014-05-06 15:57:45 -040026#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 Capensa5dfd972018-09-28 15:27:08 -040033namespace sh {
John Bauman66b8ab22014-05-06 15:57:45 -040034#ifdef TRACE_ENABLED
John Bauman66b8ab22014-05-06 15:57:45 -040035void Trace(const char* format, ...);
Nicolas Capensa5dfd972018-09-28 15:27:08 -040036#else
37inline void Trace(const char* format, ...) {}
38#endif
39inline void Trace() {}
John Bauman66b8ab22014-05-06 15:57:45 -040040}
John Bauman66b8ab22014-05-06 15:57:45 -040041
42// A macro asserting a condition and outputting failures to the debug log
Nicolas Capens3713cd42015-06-22 10:41:54 -040043#undef ASSERT
John Bauman66b8ab22014-05-06 15:57:45 -040044#define ASSERT(expression) do { \
Nicolas Capens0bac2852016-05-07 06:09:58 -040045 if(!(expression)) \
Nicolas Capensa5dfd972018-09-28 15:27:08 -040046 sh::Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
Nicolas Capens0bac2852016-05-07 06:09:58 -040047 assert(expression); \
John Bauman66b8ab22014-05-06 15:57:45 -040048} while(0)
49
Nicolas Capens3713cd42015-06-22 10:41:54 -040050#undef UNIMPLEMENTED
Nicolas Capensa5dfd972018-09-28 15:27:08 -040051#define UNIMPLEMENTED(...) do { \
52 sh::Trace("Unimplemented invoked: %s(%d): ", __FUNCTION__, __LINE__); \
53 sh::Trace(##__VA_ARGS__); \
54 sh::Trace("\n"); \
Nicolas Capens0bac2852016-05-07 06:09:58 -040055 assert(false); \
John Bauman66b8ab22014-05-06 15:57:45 -040056} while(0)
57
Nicolas Capens3713cd42015-06-22 10:41:54 -040058#undef UNREACHABLE
59#define UNREACHABLE(value) do { \
Nicolas Capensa5dfd972018-09-28 15:27:08 -040060 sh::Trace("Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value); \
Nicolas Capens0bac2852016-05-07 06:09:58 -040061 assert(false); \
John Bauman66b8ab22014-05-06 15:57:45 -040062} while(0)
63
Nicolas Capensa5dfd972018-09-28 15:27:08 -040064#endif // !__ANDROID__
John Bauman66b8ab22014-05-06 15:57:45 -040065#endif // COMPILER_DEBUG_H_
66