15
15
16
16
#include " swift/Basic/LLVM.h"
17
17
#include " swift/Driver/Action.h"
18
+ #include " swift/Driver/Job.h"
18
19
#include " swift/Frontend/FileTypes.h"
20
+ #include " swift/Option/Options.h"
19
21
#include " llvm/ADT/Triple.h"
20
22
#include " llvm/Option/Option.h"
21
23
22
24
#include < memory>
23
25
24
26
namespace swift {
25
27
namespace driver {
26
- class CommandOutput ;
27
- class Compilation ;
28
- class Driver ;
29
- class Job ;
30
- class OutputInfo ;
28
+ class CommandOutput ;
29
+ class Compilation ;
30
+ class Driver ;
31
+ class Job ;
32
+ class OutputInfo ;
31
33
32
34
// / A ToolChain is responsible for turning abstract Actions into concrete,
33
35
// / runnable Jobs.
@@ -47,7 +49,7 @@ class ToolChain {
47
49
ToolChain (const Driver &D, const llvm::Triple &T) : D(D), Triple(T) {}
48
50
49
51
// / A special name used to identify the Swift executable itself.
50
- constexpr static const char * const SWIFT_EXECUTABLE_NAME = " swift" ;
52
+ constexpr static const char *const SWIFT_EXECUTABLE_NAME = " swift" ;
51
53
52
54
// / Packs together the supplementary information about the job being created.
53
55
class JobContext {
@@ -122,45 +124,36 @@ class ToolChain {
122
124
123
125
InvocationInfo (const char *name, llvm::opt::ArgStringList args = {},
124
126
decltype (ExtraEnvironment) extraEnv = {})
125
- : ExecutableName(name), Arguments(std::move(args)),
126
- ExtraEnvironment (std::move(extraEnv)) {}
127
+ : ExecutableName(name), Arguments(std::move(args)),
128
+ ExtraEnvironment (std::move(extraEnv)) {}
127
129
};
128
130
129
- virtual InvocationInfo
130
- constructInvocation (const CompileJobAction &job,
131
- const JobContext &context) const ;
132
- virtual InvocationInfo
133
- constructInvocation (const InterpretJobAction &job,
134
- const JobContext &context) const ;
135
- virtual InvocationInfo
136
- constructInvocation (const BackendJobAction &job,
137
- const JobContext &context) const ;
138
- virtual InvocationInfo
139
- constructInvocation (const MergeModuleJobAction &job,
140
- const JobContext &context) const ;
141
- virtual InvocationInfo
142
- constructInvocation (const ModuleWrapJobAction &job,
143
- const JobContext &context) const ;
144
-
145
- virtual InvocationInfo
146
- constructInvocation (const REPLJobAction &job,
147
- const JobContext &context) const ;
148
-
149
- virtual InvocationInfo
150
- constructInvocation (const GenerateDSYMJobAction &job,
151
- const JobContext &context) const ;
131
+ virtual InvocationInfo constructInvocation (const CompileJobAction &job,
132
+ const JobContext &context) const ;
133
+ virtual InvocationInfo constructInvocation (const InterpretJobAction &job,
134
+ const JobContext &context) const ;
135
+ virtual InvocationInfo constructInvocation (const BackendJobAction &job,
136
+ const JobContext &context) const ;
137
+ virtual InvocationInfo constructInvocation (const MergeModuleJobAction &job,
138
+ const JobContext &context) const ;
139
+ virtual InvocationInfo constructInvocation (const ModuleWrapJobAction &job,
140
+ const JobContext &context) const ;
141
+
142
+ virtual InvocationInfo constructInvocation (const REPLJobAction &job,
143
+ const JobContext &context) const ;
144
+
145
+ virtual InvocationInfo constructInvocation (const GenerateDSYMJobAction &job,
146
+ const JobContext &context) const ;
152
147
virtual InvocationInfo
153
148
constructInvocation (const VerifyDebugInfoJobAction &job,
154
149
const JobContext &context) const ;
155
- virtual InvocationInfo
156
- constructInvocation (const GeneratePCHJobAction &job,
157
- const JobContext &context) const ;
150
+ virtual InvocationInfo constructInvocation (const GeneratePCHJobAction &job,
151
+ const JobContext &context) const ;
158
152
virtual InvocationInfo
159
153
constructInvocation (const AutolinkExtractJobAction &job,
160
154
const JobContext &context) const ;
161
- virtual InvocationInfo
162
- constructInvocation (const LinkJobAction &job,
163
- const JobContext &context) const ;
155
+ virtual InvocationInfo constructInvocation (const LinkJobAction &job,
156
+ const JobContext &context) const ;
164
157
165
158
// / Searches for the given executable in appropriate paths relative to the
166
159
// / Swift binary.
@@ -176,6 +169,34 @@ class ToolChain {
176
169
// / This method is invoked by findProgramRelativeToSwift().
177
170
virtual std::string findProgramRelativeToSwiftImpl (StringRef name) const ;
178
171
172
+ void addInputsOfType (llvm::opt::ArgStringList &Arguments,
173
+ ArrayRef<const Action *> Inputs,
174
+ file_types::ID InputType,
175
+ const char *PrefixArgument = nullptr ) const ;
176
+
177
+ void addInputsOfType (llvm::opt::ArgStringList &Arguments,
178
+ ArrayRef<const Job *> Jobs,
179
+ const llvm::opt::ArgList &Args, file_types::ID InputType,
180
+ const char *PrefixArgument = nullptr ) const ;
181
+
182
+ void addPrimaryInputsOfType (llvm::opt::ArgStringList &Arguments,
183
+ ArrayRef<const Job *> Jobs,
184
+ const llvm::opt::ArgList &Args,
185
+ file_types::ID InputType,
186
+ const char *PrefixArgument = nullptr ) const ;
187
+
188
+ // / Get the runtime library link path, which is platform-specific and found
189
+ // / relative to the compiler.
190
+ void getRuntimeLibraryPath (SmallVectorImpl<char > &runtimeLibPath,
191
+ const llvm::opt::ArgList &args, bool shared) const ;
192
+
193
+ void addPathEnvironmentVariableIfNeeded (Job::EnvironmentVector &env,
194
+ const char *name,
195
+ const char *separator,
196
+ options::ID optionID,
197
+ const llvm::opt::ArgList &args,
198
+ StringRef extraEntry = " " ) const ;
199
+
179
200
public:
180
201
virtual ~ToolChain () = default ;
181
202
@@ -187,8 +208,7 @@ class ToolChain {
187
208
// /
188
209
// / This method dispatches to the various \c constructInvocation methods,
189
210
// / which may be overridden by platform-specific subclasses.
190
- std::unique_ptr<Job> constructJob (const JobAction &JA,
191
- Compilation &C,
211
+ std::unique_ptr<Job> constructJob (const JobAction &JA, Compilation &C,
192
212
SmallVectorImpl<const Job *> &&inputs,
193
213
ArrayRef<const Action *> inputActions,
194
214
std::unique_ptr<CommandOutput> output,
@@ -221,16 +241,35 @@ class ToolChain {
221
241
// / Return the default language type to use for the given extension.
222
242
// / If the extension is empty or is otherwise not recognized, return
223
243
// / the invalid type \c TY_INVALID.
224
- virtual file_types::ID lookupTypeForExtension (StringRef Ext) const ;
244
+ file_types::ID lookupTypeForExtension (StringRef Ext) const ;
225
245
226
- // / Check whether a clang library with a given name exists.
246
+ // / Copies the path for the directory clang libraries would be stored in on
247
+ // / the current toolchain.
248
+ void getClangLibraryPath (const llvm::opt::ArgList &Args,
249
+ SmallString<128 > &LibPath) const ;
250
+
251
+ // / Returns the name the clang library for a given sanitizer would have on
252
+ // / the current toolchain.
253
+ // /
254
+ // / \param Sanitizer Sanitizer name.
255
+ // / \param shared Whether the library is shared
256
+ virtual std::string sanitizerRuntimeLibName (StringRef Sanitizer,
257
+ bool shared = true ) const = 0;
258
+
259
+ // / Returns whether a given sanitizer exists for the current toolchain.
227
260
// /
228
- // / \param args Invocation arguments.
229
261
// / \param sanitizer Sanitizer name.
230
262
// / \param shared Whether the library is shared
231
- virtual bool sanitizerRuntimeLibExists (const llvm::opt::ArgList &args,
232
- StringRef sanitizer,
233
- bool shared=true ) const ;
263
+ bool sanitizerRuntimeLibExists (const llvm::opt::ArgList &args,
264
+ StringRef sanitizer, bool shared = true ) const ;
265
+
266
+ // / Adds a runtime library to the arguments list for linking.
267
+ // /
268
+ // / \param LibName The library name
269
+ // / \param Arguments The arguments list to append to
270
+ void addLinkRuntimeLib (const llvm::opt::ArgList &Args,
271
+ llvm::opt::ArgStringList &Arguments,
272
+ StringRef LibName) const ;
234
273
};
235
274
} // end namespace driver
236
275
} // end namespace swift
0 commit comments