diff --git a/llvm/utils/split-file/split-file.cpp b/llvm/utils/split-file/split-file.cpp --- a/llvm/utils/split-file/split-file.cpp +++ b/llvm/utils/split-file/split-file.cpp @@ -43,6 +43,15 @@ cl::desc("Don't preserve line numbers (default)"), cl::cat(cat)); +static cl::opt addFileExtension("add-file-extension", + cl::desc("Add an extension to output file names"), + cl::value_desc("ext"), + cl::cat(cat)); + +static cl::opt allowComments("allow-comments", + cl::desc("Allow comments to be introduced with a colon after the part name"), + cl::cat(cat)); + static StringRef toolName; static int errorCount; @@ -80,7 +89,15 @@ line.substr(markerLen - 4).startswith("--- "))) continue; separator = line.substr(0, markerLen); - const StringRef partName = line.substr(markerLen); + const StringRef partName = [&] { + StringRef partName = line.substr(markerLen); + if (allowComments) { + auto colonPos = partName.find(':'); + if (colonPos != StringRef::npos) + partName = partName.substr(0, colonPos); + } + return partName; + }(); if (partName.empty()) { error(input, lineNo, "empty part name"); continue; @@ -118,6 +135,11 @@ for (auto &keyValue : partToBegin) { partPath.clear(); sys::path::append(partPath, output, keyValue.first); + if (!addFileExtension.empty()) { + if (addFileExtension.getValue()[0] != '.') + partPath.append("."); + partPath.append(addFileExtension.getValue()); + } std::error_code ec = sys::fs::create_directories(sys::path::parent_path(partPath)); if (ec)