blob: 2755d23fec5bcd98618fb7eaf0741e348e656f6f [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
Greg Hartmand61ac5f2015-04-09 18:48:53 -070020#ifdef __ANDROID__
21#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
33#ifdef TRACE_ENABLED
34
35#ifdef __cplusplus
36extern "C" {
37#endif // __cplusplus
38void 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 Capens3713cd42015-06-22 10:41:54 -040050#undef ASSERT
John Bauman66b8ab22014-05-06 15:57:45 -040051#define ASSERT(expression) do { \
Nicolas Capens0bac2852016-05-07 06:09:58 -040052 if(!(expression)) \
53 Trace("Assert failed: %s(%d): "#expression"\n", __FUNCTION__, __LINE__); \
54 assert(expression); \
John Bauman66b8ab22014-05-06 15:57:45 -040055} while(0)
56
Nicolas Capens3713cd42015-06-22 10:41:54 -040057#undef UNIMPLEMENTED
John Bauman66b8ab22014-05-06 15:57:45 -040058#define UNIMPLEMENTED() do { \
Nicolas Capens0bac2852016-05-07 06:09:58 -040059 Trace("Unimplemented invoked: %s(%d)\n", __FUNCTION__, __LINE__); \
60 assert(false); \
John Bauman66b8ab22014-05-06 15:57:45 -040061} while(0)
62
Nicolas Capens3713cd42015-06-22 10:41:54 -040063#undef UNREACHABLE
64#define UNREACHABLE(value) do { \
Nicolas Capens0bac2852016-05-07 06:09:58 -040065 Trace("Unreachable reached: %s(%d). %s: %d\n", __FUNCTION__, __LINE__, #value, value); \
66 assert(false); \
John Bauman66b8ab22014-05-06 15:57:45 -040067} while(0)
68
Greg Hartmand61ac5f2015-04-09 18:48:53 -070069#endif // __ANDROID__
John Bauman66b8ab22014-05-06 15:57:45 -040070#endif // COMPILER_DEBUG_H_
71