1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | #ifndef LLVM_CLANG_DRIVER_JOB_H |
10 | #define LLVM_CLANG_DRIVER_JOB_H |
11 | |
12 | #include "clang/Basic/LLVM.h" |
13 | #include "llvm/ADT/ArrayRef.h" |
14 | #include "llvm/ADT/Optional.h" |
15 | #include "llvm/ADT/SmallVector.h" |
16 | #include "llvm/ADT/StringRef.h" |
17 | #include "llvm/ADT/iterator.h" |
18 | #include "llvm/Option/Option.h" |
19 | #include <memory> |
20 | #include <string> |
21 | #include <utility> |
22 | #include <vector> |
23 | |
24 | namespace clang { |
25 | namespace driver { |
26 | |
27 | class Action; |
28 | class InputInfo; |
29 | class Tool; |
30 | |
31 | struct CrashReportInfo { |
32 | StringRef Filename; |
33 | StringRef VFSPath; |
34 | |
35 | CrashReportInfo(StringRef Filename, StringRef VFSPath) |
36 | : Filename(Filename), VFSPath(VFSPath) {} |
37 | }; |
38 | |
39 | |
40 | |
41 | class Command { |
42 | |
43 | const Action &Source; |
44 | |
45 | |
46 | const Tool &Creator; |
47 | |
48 | |
49 | const char *Executable; |
50 | |
51 | |
52 | |
53 | llvm::opt::ArgStringList Arguments; |
54 | |
55 | |
56 | llvm::opt::ArgStringList InputFilenames; |
57 | |
58 | |
59 | bool PrintInputFilenames = false; |
60 | |
61 | |
62 | |
63 | const char *ResponseFile = nullptr; |
64 | |
65 | |
66 | |
67 | llvm::opt::ArgStringList InputFileList; |
68 | |
69 | |
70 | |
71 | std::string ResponseFileFlag; |
72 | |
73 | |
74 | std::vector<const char *> Environment; |
75 | |
76 | |
77 | |
78 | |
79 | |
80 | void buildArgvForResponseFile(llvm::SmallVectorImpl<const char *> &Out) const; |
81 | |
82 | |
83 | |
84 | |
85 | |
86 | void writeResponseFile(raw_ostream &OS) const; |
87 | |
88 | public: |
89 | Command(const Action &Source, const Tool &Creator, const char *Executable, |
90 | const llvm::opt::ArgStringList &Arguments, |
91 | ArrayRef<InputInfo> Inputs); |
92 | |
93 | |
94 | Command(const Command &) = default; |
95 | virtual ~Command() = default; |
96 | |
97 | virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, |
98 | CrashReportInfo *CrashInfo = nullptr) const; |
99 | |
100 | virtual int Execute(ArrayRef<Optional<StringRef>> Redirects, |
101 | std::string *ErrMsg, bool *ExecutionFailed) const; |
102 | |
103 | |
104 | const Action &getSource() const { return Source; } |
105 | |
106 | |
107 | const Tool &getCreator() const { return Creator; } |
108 | |
109 | |
110 | void setResponseFile(const char *FileName); |
111 | |
112 | |
113 | |
114 | void setInputFileList(llvm::opt::ArgStringList List) { |
115 | InputFileList = std::move(List); |
116 | } |
117 | |
118 | |
119 | |
120 | |
121 | |
122 | void setEnvironment(llvm::ArrayRef<const char *> NewEnvironment); |
123 | |
124 | const char *getExecutable() const { return Executable; } |
125 | |
126 | const llvm::opt::ArgStringList &getArguments() const { return Arguments; } |
127 | |
128 | |
129 | static void printArg(llvm::raw_ostream &OS, StringRef Arg, bool Quote); |
130 | |
131 | |
132 | void setPrintInputFilenames(bool P) { PrintInputFilenames = P; } |
133 | }; |
134 | |
135 | |
136 | |
137 | class FallbackCommand : public Command { |
138 | public: |
139 | FallbackCommand(const Action &Source_, const Tool &Creator_, |
140 | const char *Executable_, |
141 | const llvm::opt::ArgStringList &Arguments_, |
142 | ArrayRef<InputInfo> Inputs, |
143 | std::unique_ptr<Command> Fallback_); |
144 | |
145 | void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, |
146 | CrashReportInfo *CrashInfo = nullptr) const override; |
147 | |
148 | int Execute(ArrayRef<Optional<StringRef>> Redirects, std::string *ErrMsg, |
149 | bool *ExecutionFailed) const override; |
150 | |
151 | private: |
152 | std::unique_ptr<Command> Fallback; |
153 | }; |
154 | |
155 | |
156 | class ForceSuccessCommand : public Command { |
157 | public: |
158 | ForceSuccessCommand(const Action &Source_, const Tool &Creator_, |
159 | const char *Executable_, |
160 | const llvm::opt::ArgStringList &Arguments_, |
161 | ArrayRef<InputInfo> Inputs); |
162 | |
163 | void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, |
164 | CrashReportInfo *CrashInfo = nullptr) const override; |
165 | |
166 | int Execute(ArrayRef<Optional<StringRef>> Redirects, std::string *ErrMsg, |
167 | bool *ExecutionFailed) const override; |
168 | }; |
169 | |
170 | |
171 | class JobList { |
172 | public: |
173 | using list_type = SmallVector<std::unique_ptr<Command>, 4>; |
174 | using size_type = list_type::size_type; |
175 | using iterator = llvm::pointee_iterator<list_type::iterator>; |
176 | using const_iterator = llvm::pointee_iterator<list_type::const_iterator>; |
177 | |
178 | private: |
179 | list_type Jobs; |
180 | |
181 | public: |
182 | void Print(llvm::raw_ostream &OS, const char *Terminator, |
183 | bool Quote, CrashReportInfo *CrashInfo = nullptr) const; |
184 | |
185 | |
186 | void addJob(std::unique_ptr<Command> J) { Jobs.push_back(std::move(J)); } |
187 | |
188 | |
189 | void clear(); |
190 | |
191 | const list_type &getJobs() const { return Jobs; } |
192 | |
193 | bool empty() const { return Jobs.empty(); } |
194 | size_type size() const { return Jobs.size(); } |
195 | iterator begin() { return Jobs.begin(); } |
196 | const_iterator begin() const { return Jobs.begin(); } |
197 | iterator end() { return Jobs.end(); } |
198 | const_iterator end() const { return Jobs.end(); } |
199 | }; |
200 | |
201 | } |
202 | } |
203 | |
204 | #endif |
205 | |