@@ -26,17 +26,27 @@ namespace llvm {
26
26
// << "] " << "Bitset contains: " << Bitset << "\n");
27
27
#define LDBG () DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), DEBUG_TYPE)
28
28
29
+ #if defined(__SHORT_FILE__)
30
+ #define DEBUGLOG_WITH_STREAM_AND_TYPE (STREAM, TYPE ) \
31
+ for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
32
+ _c = false ) \
33
+ ::llvm::impl::LogWithNewline (TYPE, __SHORT_FILE__, __LINE__, (STREAM))
34
+ #else
29
35
#define DEBUGLOG_WITH_STREAM_AND_TYPE (STREAM, TYPE ) \
30
36
for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
31
37
_c = false ) \
32
38
::llvm::impl::LogWithNewline (TYPE, __FILE__, __LINE__, (STREAM))
39
+ #endif
33
40
34
41
namespace impl {
35
42
class LogWithNewline {
36
43
public:
37
44
LogWithNewline (const char *debug_type, const char *file, int line,
38
45
raw_ostream &os)
39
46
: os(os) {
47
+ #if !defined(__SHORT_FILE__)
48
+ file = ::llvm::impl::LogWithNewline::getShortFileName (file);
49
+ #endif
40
50
if (debug_type)
41
51
os << " [" << debug_type << " ] " ;
42
52
os << file << " :" << line << " " ;
@@ -51,6 +61,16 @@ class LogWithNewline {
51
61
LogWithNewline (const LogWithNewline &) = delete ;
52
62
LogWithNewline &operator =(const LogWithNewline &) = delete ;
53
63
LogWithNewline &operator =(LogWithNewline &&) = delete ;
64
+ static constexpr const char *getShortFileName (const char *path) {
65
+ // Remove the path prefix from the file name.
66
+ const char *filename = path;
67
+ for (const char *p = path; *p != ' \0 ' ; ++p) {
68
+ if (*p == ' /' || *p == ' \\ ' ) {
69
+ filename = p + 1 ;
70
+ }
71
+ }
72
+ return filename;
73
+ }
54
74
55
75
private:
56
76
raw_ostream &os;
0 commit comments