1//===- debug.h - Debugging output utilities ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of the ORC runtime support library.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef ORC_RT_DEBUG_H
14#define ORC_RT_DEBUG_H
15
16#include <atomic>
17
18#ifndef NDEBUG
19
20namespace orc_rt {
21
22extern std::atomic<const char *> DebugTypes;
23extern char DebugTypesAll;
24extern char DebugTypesNone;
25
26const char *initializeDebug();
27bool debugTypeEnabled(const char *Type, const char *Types);
28void printdbg(const char *format, ...);
29
30} // namespace orc_rt
31
32#define ORC_RT_DEBUG_WITH_TYPE(TYPE, X) \
33 do { \
34 const char *Types = ::orc_rt::DebugTypes.load(std::memory_order_relaxed); \
35 if (!Types) \
36 Types = initializeDebug(); \
37 if (Types == &DebugTypesNone) \
38 break; \
39 if (Types == &DebugTypesAll || ::orc_rt::debugTypeEnabled(TYPE, Types)) { \
40 X; \
41 } \
42 } while (false)
43
44#else
45
46#define ORC_RT_DEBUG_WITH_TYPE(TYPE, X) \
47 do { \
48 } while (false)
49
50#endif // !NDEBUG
51
52#define ORC_RT_DEBUG(X) ORC_RT_DEBUG_WITH_TYPE(DEBUG_TYPE, X)
53
54#endif // ORC_RT_DEBUG_H
55