|
13 | 13 | #ifndef SWIFT_DRIVER_TOOLCHAIN_H
|
14 | 14 | #define SWIFT_DRIVER_TOOLCHAIN_H
|
15 | 15 |
|
16 |
| -#include "swift/Basic/LLVM.h" |
17 | 16 | #include "swift/Driver/Action.h"
|
18 | 17 | #include "swift/Driver/Types.h"
|
19 |
| -#include "llvm/Support/Program.h" |
| 18 | +#include "swift/Basic/LLVM.h" |
| 19 | +#include "llvm/Option/Option.h" |
20 | 20 | #include "llvm/ADT/Triple.h"
|
21 | 21 |
|
22 | 22 | #include <memory>
|
23 | 23 |
|
24 |
| -namespace llvm { |
25 |
| -namespace opt { |
26 |
| - class ArgList; |
27 |
| - class DerivedArgList; |
28 |
| - class InputArgList; |
29 |
| -} |
30 |
| -} |
31 |
| - |
32 | 24 | namespace swift {
|
33 | 25 | namespace driver {
|
| 26 | + class CommandOutput; |
34 | 27 | class Compilation;
|
35 | 28 | class Driver;
|
36 |
| - class Tool; |
37 |
| - |
| 29 | + class Job; |
| 30 | + class OutputInfo; |
| 31 | + |
| 32 | +/// A ToolChain is responsible for turning abstract Actions into concrete, |
| 33 | +/// runnable Jobs. |
| 34 | +/// |
| 35 | +/// The primary purpose of a ToolChain is built around the |
| 36 | +/// \c constructInvocation family of methods. This is a set of callbacks |
| 37 | +/// following the Visitor pattern for the various JobAction subclasses, which |
| 38 | +/// returns an executable name and arguments for the Job to be run. The base |
| 39 | +/// ToolChain knows how to perform most operations, but some (like linking) |
| 40 | +/// require platform-specific knowledge, provided in subclasses. |
38 | 41 | class ToolChain {
|
39 | 42 | const Driver &D;
|
40 | 43 | const llvm::Triple Triple;
|
41 |
| - |
42 |
| - mutable std::unique_ptr<Tool> Swift; |
43 |
| - mutable std::unique_ptr<Tool> MergeModule; |
44 |
| - mutable std::unique_ptr<Tool> LLDB; |
45 |
| - mutable std::unique_ptr<Tool> Linker; |
46 |
| - mutable std::unique_ptr<Tool> Dsymutil; |
47 |
| - mutable std::unique_ptr<Tool> AutolinkExtract; |
48 |
| - |
49 |
| - Tool *getSwift() const; |
50 |
| - Tool *getMergeModule() const; |
51 |
| - Tool *getLLDB() const; |
52 |
| - Tool *getLinker() const; |
53 |
| - Tool *getDsymutil() const; |
54 |
| - Tool *getAutolinkExtract() const; |
| 44 | + mutable llvm::StringMap<std::string> ProgramLookupCache; |
55 | 45 |
|
56 | 46 | protected:
|
57 | 47 | ToolChain(const Driver &D, const llvm::Triple &T) : D(D), Triple(T) {}
|
58 | 48 |
|
59 |
| - virtual std::unique_ptr<Tool> buildLinker() const = 0; |
| 49 | + /// A special name used to identify the Swift executable itself. |
| 50 | + constexpr static const char * const SWIFT_EXECUTABLE_NAME = "swift"; |
| 51 | + |
| 52 | + /// Packs together the supplementary information about the job being created. |
| 53 | + struct JobContext { |
| 54 | + ArrayRef<const Job *> Inputs; |
| 55 | + const CommandOutput &Output; |
| 56 | + ArrayRef<const Action *> InputActions; |
| 57 | + const llvm::opt::ArgList &Args; |
| 58 | + const OutputInfo &OI; |
| 59 | + }; |
| 60 | + |
| 61 | + virtual std::pair<const char *, llvm::opt::ArgStringList> |
| 62 | + constructInvocation(const CompileJobAction &job, |
| 63 | + const JobContext &context) const; |
| 64 | + virtual std::pair<const char *, llvm::opt::ArgStringList> |
| 65 | + constructInvocation(const BackendJobAction &job, |
| 66 | + const JobContext &context) const; |
| 67 | + virtual std::pair<const char *, llvm::opt::ArgStringList> |
| 68 | + constructInvocation(const MergeModuleJobAction &job, |
| 69 | + const JobContext &context) const; |
| 70 | + |
| 71 | + virtual std::pair<const char *, llvm::opt::ArgStringList> |
| 72 | + constructInvocation(const REPLJobAction &job, |
| 73 | + const JobContext &context) const; |
| 74 | + |
| 75 | + virtual std::pair<const char *, llvm::opt::ArgStringList> |
| 76 | + constructInvocation(const GenerateDSYMJobAction &job, |
| 77 | + const JobContext &context) const; |
| 78 | + virtual std::pair<const char *, llvm::opt::ArgStringList> |
| 79 | + constructInvocation(const AutolinkExtractJobAction &job, |
| 80 | + const JobContext &context) const; |
| 81 | + virtual std::pair<const char *, llvm::opt::ArgStringList> |
| 82 | + constructInvocation(const LinkJobAction &job, |
| 83 | + const JobContext &context) const; |
| 84 | + |
| 85 | + /// Searches for the given executable in appropriate paths relative to the |
| 86 | + /// Swift binary. |
| 87 | + /// |
| 88 | + /// This method caches its results. |
| 89 | + /// |
| 90 | + /// \sa findProgramRelativeToSwiftImpl |
| 91 | + std::string findProgramRelativeToSwift(StringRef name) const; |
| 92 | + |
| 93 | + /// An override point for platform-specific subclasses to customize how to |
| 94 | + /// do relative searches for programs. |
| 95 | + /// |
| 96 | + /// This method is invoked by findProgramRelativeToSwift(). |
| 97 | + virtual std::string findProgramRelativeToSwiftImpl(StringRef name) const; |
60 | 98 |
|
61 | 99 | public:
|
62 | 100 | virtual ~ToolChain() = default;
|
63 | 101 |
|
64 |
| - // Accessors |
65 |
| - |
66 | 102 | const Driver &getDriver() const { return D; }
|
67 | 103 | const llvm::Triple &getTriple() const { return Triple; }
|
68 | 104 |
|
69 |
| - /// Choose a tool to use to handle the action \p JA. |
70 |
| - virtual Tool *selectTool(const JobAction &JA) const; |
| 105 | + /// Construct a Job for the action \p JA, taking the given information into |
| 106 | + /// account. |
| 107 | + /// |
| 108 | + /// This method dispatches to the various \c constructInvocation methods, |
| 109 | + /// which may be overridden by platform-specific subclasses. |
| 110 | + std::unique_ptr<Job> constructJob(const JobAction &JA, |
| 111 | + SmallVectorImpl<const Job *> &&inputs, |
| 112 | + std::unique_ptr<CommandOutput> output, |
| 113 | + const ActionList &inputActions, |
| 114 | + const llvm::opt::ArgList &args, |
| 115 | + const OutputInfo &OI) const; |
71 | 116 |
|
72 | 117 | /// Look up \p Name in the list of program search paths.
|
73 |
| - virtual std::string getProgramPath(StringRef Name) const; |
74 |
| - |
75 |
| - // Platform defaults information |
76 |
| - |
| 118 | + /// |
77 | 119 | /// Return the default langauge type to use for the given extension.
|
78 | 120 | virtual types::ID lookupTypeForExtension(StringRef Ext) const;
|
79 | 121 | };
|
|
0 commit comments