@@ -26,17 +26,27 @@ namespace llvm {
2626// << "] " << "Bitset contains: " << Bitset << "\n");
2727#define LDBG () DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), DEBUG_TYPE)
2828
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
2935#define DEBUGLOG_WITH_STREAM_AND_TYPE (STREAM, TYPE ) \
3036 for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \
3137 _c = false ) \
3238 ::llvm::impl::LogWithNewline (TYPE, __FILE__, __LINE__, (STREAM))
39+ #endif
3340
3441namespace impl {
3542class LogWithNewline {
3643public:
3744 LogWithNewline (const char *debug_type, const char *file, int line,
3845 raw_ostream &os)
3946 : os(os) {
47+ #if !defined(__SHORT_FILE__)
48+ file = ::llvm::impl::LogWithNewline::getShortFileName (file);
49+ #endif
4050 if (debug_type)
4151 os << " [" << debug_type << " ] " ;
4252 os << file << " :" << line << " " ;
@@ -51,6 +61,16 @@ class LogWithNewline {
5161 LogWithNewline (const LogWithNewline &) = delete ;
5262 LogWithNewline &operator =(const LogWithNewline &) = delete ;
5363 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+ }
5474
5575private:
5676 raw_ostream &os;
0 commit comments