1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[Clang] Move clang::Job::printArg to llvm::sys::printArg. NFCI.

This patch is to support/simplify https://reviews.llvm.org/D80833
This commit is contained in:
Alexandre Ganea 2020-06-17 18:33:18 -04:00
parent c5d367254d
commit df9adf49f1
2 changed files with 22 additions and 0 deletions

View File

@ -210,6 +210,9 @@ namespace sys {
/// stored.
);
/// Print a command argument, and optionally quote it.
void printArg(llvm::raw_ostream &OS, StringRef Arg, bool Quote);
#if defined(_WIN32)
/// Given a list of command line arguments, quote and escape them as necessary
/// to build a single flat command line appropriate for calling CreateProcess

View File

@ -13,6 +13,7 @@
#include "llvm/Support/Program.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/raw_ostream.h"
#include <system_error>
using namespace llvm;
using namespace sys;
@ -75,6 +76,24 @@ bool sys::commandLineFitsWithinSystemLimits(StringRef Program,
return commandLineFitsWithinSystemLimits(Program, StringRefArgs);
}
void sys::printArg(raw_ostream &OS, StringRef Arg, bool Quote) {
const bool Escape = Arg.find_first_of(" \"\\$") != StringRef::npos;
if (!Quote && !Escape) {
OS << Arg;
return;
}
// Quote and escape. This isn't really complete, but good enough.
OS << '"';
for (const auto c : Arg) {
if (c == '"' || c == '\\' || c == '$')
OS << '\\';
OS << c;
}
OS << '"';
}
// Include the platform-specific parts of this class.
#ifdef LLVM_ON_UNIX
#include "Unix/Program.inc"