llvm.org GIT mirror llvm / c3c9239
Add DEBUG_WITH_TYPE as a clean alternative to tweaking DEBUG_TYPE. This: -- #undef DEBUG_TYPE #define DEBUG_TYPE "foo" DEBUG(...) #undef DEBUG_TYPE #define DEBUG_TYPE "" -- becomes this: -- DEBUG_WITH_TYPE("foo", ...) -- git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78435 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 11 years ago
2 changed file(s) with 34 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
645645 for instruction scheduling to be enabled with -debug-type=InstrSched,
646646 even if the source lives in multiple files.

647647
648

The DEBUG_WITH_TYPE macro is also available for situations where you

649 would like to set DEBUG_TYPE, but only for one specific DEBUG
650 statement. It takes an additional first parameter, which is the type to use. For
651 example, the preceeding example could be written as:

652
653
654
655

                  
                
656 DEBUG_WITH_TYPE("", errs() << "No debug type\n");
657 DEBUG_WITH_TYPE("foo", errs() << "'foo' debug type\n");
658 DEBUG_WITH_TYPE("bar", errs() << "'bar' debug type\n"));
659 DEBUG_WITH_TYPE("", errs() << "No debug type (2)\n");
660
661
662
648663
649664
650665
4141 //
4242 bool isCurrentDebugType(const char *Type);
4343
44 // DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug
45 // information. In the '-debug' option is specified on the commandline, and if
46 // this is a debug build, then the code specified as the option to the macro
47 // will be executed. Otherwise it will not be. Example:
48 //
49 // DEBUG_WITH_TYPE("bitset", errs() << "Bitset contains: " << Bitset << "\n");
50 //
51 // This will emit the debug information if -debug is present, and -debug-only is
52 // not specified, or is specified as "bitset".
53
54 #ifdef NDEBUG
55 #define DEBUG_WITH_TYPE(TYPE, X) do { } while (0)
56 #else
57 #define DEBUG_WITH_TYPE(TYPE, X) \
58 do { if (DebugFlag && isCurrentDebugType(TYPE)) { X; } } while (0)
59 #endif
60
4461 // DEBUG macro - This macro should be used by passes to emit debug information.
4562 // In the '-debug' option is specified on the commandline, and if this is a
4663 // debug build, then the code specified as the option to the macro will be
4764 // executed. Otherwise it will not be. Example:
4865 //
49 // DEBUG(cerr << "Bitset contains: " << Bitset << "\n");
66 // DEBUG(errs() << "Bitset contains: " << Bitset << "\n");
5067 //
5168
5269 #ifndef DEBUG_TYPE
5370 #define DEBUG_TYPE ""
5471 #endif
5572
56 #ifdef NDEBUG
57 #define DEBUG(X)
58 #else
59 #define DEBUG(X) \
60 do { if (DebugFlag && isCurrentDebugType(DEBUG_TYPE)) { X; } } while (0)
61 #endif
73 #define DEBUG(X) DEBUG_WITH_TYPE(DEBUG_TYPE, X)
6274
6375 /// getNullOutputStream - Return a null string that does not output
6476 /// anything. This hides the static variable from other modules.