diff --git a/llvm/cmake/modules/LLVMProcessSources.cmake b/llvm/cmake/modules/LLVMProcessSources.cmake index 0670d60bf2afd..a7f9517ad767c 100644 --- a/llvm/cmake/modules/LLVMProcessSources.cmake +++ b/llvm/cmake/modules/LLVMProcessSources.cmake @@ -58,6 +58,15 @@ function(llvm_process_sources OUT_VAR) set(sources ${ARG_UNPARSED_ARGUMENTS}) llvm_check_source_file_list(${sources}) + foreach(fn ${sources}) + get_filename_component(suf ${fn} EXT) + if("${suf}" STREQUAL ".cpp" OR "${suf}" STREQUAL ".c") + get_filename_component(short_name ${fn} NAME) + set_source_files_properties(${fn} PROPERTIES COMPILE_DEFINITIONS "__SHORT_FILE__=\"${short_name}\"") + endif() + endforeach() + + # This adds .td and .h files to the Visual Studio solution: add_td_sources(sources) find_all_header_files(hdrs "${ARG_ADDITIONAL_HEADER_DIRS}") diff --git a/llvm/include/llvm/Support/DebugLog.h b/llvm/include/llvm/Support/DebugLog.h index 3e53944edc905..b1b17e3ede950 100644 --- a/llvm/include/llvm/Support/DebugLog.h +++ b/llvm/include/llvm/Support/DebugLog.h @@ -26,10 +26,17 @@ namespace llvm { // << "] " << "Bitset contains: " << Bitset << "\n"); #define LDBG() DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), DEBUG_TYPE) +#if defined(__SHORT_FILE__) +#define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \ + for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \ + _c = false) \ + ::llvm::impl::LogWithNewline(TYPE, __SHORT_FILE__, __LINE__, (STREAM)) +#else #define DEBUGLOG_WITH_STREAM_AND_TYPE(STREAM, TYPE) \ for (bool _c = (::llvm::DebugFlag && ::llvm::isCurrentDebugType(TYPE)); _c; \ _c = false) \ ::llvm::impl::LogWithNewline(TYPE, __FILE__, __LINE__, (STREAM)) +#endif namespace impl { class LogWithNewline { @@ -37,6 +44,9 @@ class LogWithNewline { LogWithNewline(const char *debug_type, const char *file, int line, raw_ostream &os) : os(os) { +#if !defined(__SHORT_FILE__) + file = ::llvm::impl::LogWithNewline::getShortFileName(file); +#endif if (debug_type) os << "[" << debug_type << "] "; os << file << ":" << line << " "; @@ -51,6 +61,16 @@ class LogWithNewline { LogWithNewline(const LogWithNewline &) = delete; LogWithNewline &operator=(const LogWithNewline &) = delete; LogWithNewline &operator=(LogWithNewline &&) = delete; + static constexpr const char *getShortFileName(const char *path) { + // Remove the path prefix from the file name. + const char *filename = path; + for (const char *p = path; *p != '\0'; ++p) { + if (*p == '/' || *p == '\\') { + filename = p + 1; + } + } + return filename; + } private: raw_ostream &os;