Mercurial > hg > CbC > CbC_llvm
diff llvm/lib/Support/GraphWriter.cpp @ 173:0572611fdcc8 llvm10 llvm12
reorgnization done
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 25 May 2020 11:55:54 +0900 |
parents | 1d019706d866 |
children | 2e18cbf3894f |
line wrap: on
line diff
--- a/llvm/lib/Support/GraphWriter.cpp Mon May 25 11:50:15 2020 +0900 +++ b/llvm/lib/Support/GraphWriter.cpp Mon May 25 11:55:54 2020 +0900 @@ -76,10 +76,35 @@ return Colors[ColorNumber % NumColors]; } +static std::string replaceIllegalFilenameChars(std::string Filename, + const char ReplacementChar) { +#ifdef _WIN32 + std::string IllegalChars = "\\/:?\"<>|"; +#else + std::string IllegalChars = "/"; +#endif + + for (char IllegalChar : IllegalChars) { + std::replace(Filename.begin(), Filename.end(), IllegalChar, + ReplacementChar); + } + + return Filename; +} + std::string llvm::createGraphFilename(const Twine &Name, int &FD) { FD = -1; SmallString<128> Filename; - std::error_code EC = sys::fs::createTemporaryFile(Name, "dot", FD, Filename); + + // Windows can't always handle long paths, so limit the length of the name. + std::string N = Name.str(); + N = N.substr(0, std::min<std::size_t>(N.size(), 140)); + + // Replace illegal characters in graph Filename with '_' if needed + std::string CleansedName = replaceIllegalFilenameChars(N, '_'); + + std::error_code EC = + sys::fs::createTemporaryFile(CleansedName, "dot", FD, Filename); if (EC) { errs() << "Error: " << EC.message() << "\n"; return "";