1515
1616#include " swift/Basic/LLVM.h"
1717#include " swift/Driver/Action.h"
18+ #include " swift/Driver/Job.h"
1819#include " swift/Frontend/FileTypes.h"
20+ #include " swift/Option/Options.h"
1921#include " llvm/ADT/Triple.h"
2022#include " llvm/Option/Option.h"
2123
2224#include < memory>
2325
2426namespace swift {
2527namespace 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 ;
3133
3234// / A ToolChain is responsible for turning abstract Actions into concrete,
3335// / runnable Jobs.
@@ -47,7 +49,7 @@ class ToolChain {
4749 ToolChain (const Driver &D, const llvm::Triple &T) : D(D), Triple(T) {}
4850
4951 // / 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" ;
5153
5254 // / Packs together the supplementary information about the job being created.
5355 class JobContext {
@@ -122,45 +124,36 @@ class ToolChain {
122124
123125 InvocationInfo (const char *name, llvm::opt::ArgStringList args = {},
124126 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)) {}
127129 };
128130
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 ;
152147 virtual InvocationInfo
153148 constructInvocation (const VerifyDebugInfoJobAction &job,
154149 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 ;
158152 virtual InvocationInfo
159153 constructInvocation (const AutolinkExtractJobAction &job,
160154 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 ;
164157
165158 // / Searches for the given executable in appropriate paths relative to the
166159 // / Swift binary.
@@ -176,6 +169,34 @@ class ToolChain {
176169 // / This method is invoked by findProgramRelativeToSwift().
177170 virtual std::string findProgramRelativeToSwiftImpl (StringRef name) const ;
178171
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+
179200public:
180201 virtual ~ToolChain () = default ;
181202
@@ -187,8 +208,7 @@ class ToolChain {
187208 // /
188209 // / This method dispatches to the various \c constructInvocation methods,
189210 // / 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,
192212 SmallVectorImpl<const Job *> &&inputs,
193213 ArrayRef<const Action *> inputActions,
194214 std::unique_ptr<CommandOutput> output,
@@ -221,16 +241,35 @@ class ToolChain {
221241 // / Return the default language type to use for the given extension.
222242 // / If the extension is empty or is otherwise not recognized, return
223243 // / the invalid type \c TY_INVALID.
224- virtual file_types::ID lookupTypeForExtension (StringRef Ext) const ;
244+ file_types::ID lookupTypeForExtension (StringRef Ext) const ;
225245
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.
227260 // /
228- // / \param args Invocation arguments.
229261 // / \param sanitizer Sanitizer name.
230262 // / \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 ;
234273};
235274} // end namespace driver
236275} // end namespace swift
0 commit comments