Mercurial > hg > CbC > CbC_llvm
comparison llvm/lib/Support/Program.cpp @ 207:2e18cbf3894f
LLVM12
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 08 Jun 2021 06:07:14 +0900 |
parents | 1d019706d866 |
children | c4bab56944e8 |
comparison
equal
deleted
inserted
replaced
173:0572611fdcc8 | 207:2e18cbf3894f |
---|---|
11 //===----------------------------------------------------------------------===// | 11 //===----------------------------------------------------------------------===// |
12 | 12 |
13 #include "llvm/Support/Program.h" | 13 #include "llvm/Support/Program.h" |
14 #include "llvm/ADT/StringRef.h" | 14 #include "llvm/ADT/StringRef.h" |
15 #include "llvm/Config/llvm-config.h" | 15 #include "llvm/Config/llvm-config.h" |
16 #include "llvm/Support/raw_ostream.h" | |
16 #include <system_error> | 17 #include <system_error> |
17 using namespace llvm; | 18 using namespace llvm; |
18 using namespace sys; | 19 using namespace sys; |
19 | 20 |
20 //===----------------------------------------------------------------------===// | 21 //===----------------------------------------------------------------------===// |
23 //===----------------------------------------------------------------------===// | 24 //===----------------------------------------------------------------------===// |
24 | 25 |
25 static bool Execute(ProcessInfo &PI, StringRef Program, | 26 static bool Execute(ProcessInfo &PI, StringRef Program, |
26 ArrayRef<StringRef> Args, Optional<ArrayRef<StringRef>> Env, | 27 ArrayRef<StringRef> Args, Optional<ArrayRef<StringRef>> Env, |
27 ArrayRef<Optional<StringRef>> Redirects, | 28 ArrayRef<Optional<StringRef>> Redirects, |
28 unsigned MemoryLimit, std::string *ErrMsg); | 29 unsigned MemoryLimit, std::string *ErrMsg, |
30 BitVector *AffinityMask); | |
29 | 31 |
30 int sys::ExecuteAndWait(StringRef Program, ArrayRef<StringRef> Args, | 32 int sys::ExecuteAndWait(StringRef Program, ArrayRef<StringRef> Args, |
31 Optional<ArrayRef<StringRef>> Env, | 33 Optional<ArrayRef<StringRef>> Env, |
32 ArrayRef<Optional<StringRef>> Redirects, | 34 ArrayRef<Optional<StringRef>> Redirects, |
33 unsigned SecondsToWait, unsigned MemoryLimit, | 35 unsigned SecondsToWait, unsigned MemoryLimit, |
34 std::string *ErrMsg, bool *ExecutionFailed) { | 36 std::string *ErrMsg, bool *ExecutionFailed, |
37 Optional<ProcessStatistics> *ProcStat, | |
38 BitVector *AffinityMask) { | |
35 assert(Redirects.empty() || Redirects.size() == 3); | 39 assert(Redirects.empty() || Redirects.size() == 3); |
36 ProcessInfo PI; | 40 ProcessInfo PI; |
37 if (Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg)) { | 41 if (Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg, |
42 AffinityMask)) { | |
38 if (ExecutionFailed) | 43 if (ExecutionFailed) |
39 *ExecutionFailed = false; | 44 *ExecutionFailed = false; |
40 ProcessInfo Result = Wait( | 45 ProcessInfo Result = |
41 PI, SecondsToWait, /*WaitUntilTerminates=*/SecondsToWait == 0, ErrMsg); | 46 Wait(PI, SecondsToWait, /*WaitUntilTerminates=*/SecondsToWait == 0, |
47 ErrMsg, ProcStat); | |
42 return Result.ReturnCode; | 48 return Result.ReturnCode; |
43 } | 49 } |
44 | 50 |
45 if (ExecutionFailed) | 51 if (ExecutionFailed) |
46 *ExecutionFailed = true; | 52 *ExecutionFailed = true; |
50 | 56 |
51 ProcessInfo sys::ExecuteNoWait(StringRef Program, ArrayRef<StringRef> Args, | 57 ProcessInfo sys::ExecuteNoWait(StringRef Program, ArrayRef<StringRef> Args, |
52 Optional<ArrayRef<StringRef>> Env, | 58 Optional<ArrayRef<StringRef>> Env, |
53 ArrayRef<Optional<StringRef>> Redirects, | 59 ArrayRef<Optional<StringRef>> Redirects, |
54 unsigned MemoryLimit, std::string *ErrMsg, | 60 unsigned MemoryLimit, std::string *ErrMsg, |
55 bool *ExecutionFailed) { | 61 bool *ExecutionFailed, BitVector *AffinityMask) { |
56 assert(Redirects.empty() || Redirects.size() == 3); | 62 assert(Redirects.empty() || Redirects.size() == 3); |
57 ProcessInfo PI; | 63 ProcessInfo PI; |
58 if (ExecutionFailed) | 64 if (ExecutionFailed) |
59 *ExecutionFailed = false; | 65 *ExecutionFailed = false; |
60 if (!Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg)) | 66 if (!Execute(PI, Program, Args, Env, Redirects, MemoryLimit, ErrMsg, |
67 AffinityMask)) | |
61 if (ExecutionFailed) | 68 if (ExecutionFailed) |
62 *ExecutionFailed = true; | 69 *ExecutionFailed = true; |
63 | 70 |
64 return PI; | 71 return PI; |
65 } | 72 } |
71 for (const char *A : Args) | 78 for (const char *A : Args) |
72 StringRefArgs.emplace_back(A); | 79 StringRefArgs.emplace_back(A); |
73 return commandLineFitsWithinSystemLimits(Program, StringRefArgs); | 80 return commandLineFitsWithinSystemLimits(Program, StringRefArgs); |
74 } | 81 } |
75 | 82 |
83 void sys::printArg(raw_ostream &OS, StringRef Arg, bool Quote) { | |
84 const bool Escape = Arg.find_first_of(" \"\\$") != StringRef::npos; | |
85 | |
86 if (!Quote && !Escape) { | |
87 OS << Arg; | |
88 return; | |
89 } | |
90 | |
91 // Quote and escape. This isn't really complete, but good enough. | |
92 OS << '"'; | |
93 for (const auto c : Arg) { | |
94 if (c == '"' || c == '\\' || c == '$') | |
95 OS << '\\'; | |
96 OS << c; | |
97 } | |
98 OS << '"'; | |
99 } | |
100 | |
76 // Include the platform-specific parts of this class. | 101 // Include the platform-specific parts of this class. |
77 #ifdef LLVM_ON_UNIX | 102 #ifdef LLVM_ON_UNIX |
78 #include "Unix/Program.inc" | 103 #include "Unix/Program.inc" |
79 #endif | 104 #endif |
80 #ifdef _WIN32 | 105 #ifdef _WIN32 |