Skip to content

[Driver] Refactor ToolChains into separate files. #16091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/Basic/TaskQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class TaskQueue {
/// \param NumberOfParallelTasks indicates the number of tasks which should
/// be run in parallel. If 0, the TaskQueue will choose the most appropriate
/// number of parallel tasks for the current system.
/// \param Optional stats reporter to count I/O and subprocess events.
/// \param USR Optional stats reporter to count I/O and subprocess events.
TaskQueue(unsigned NumberOfParallelTasks = 0,
UnifiedStatsReporter *USR = nullptr);
virtual ~TaskQueue();
Expand Down
129 changes: 84 additions & 45 deletions include/swift/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@

#include "swift/Basic/LLVM.h"
#include "swift/Driver/Action.h"
#include "swift/Driver/Job.h"
#include "swift/Frontend/FileTypes.h"
#include "swift/Option/Options.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Option/Option.h"

#include <memory>

namespace swift {
namespace driver {
class CommandOutput;
class Compilation;
class Driver;
class Job;
class OutputInfo;
class CommandOutput;
class Compilation;
class Driver;
class Job;
class OutputInfo;

/// A ToolChain is responsible for turning abstract Actions into concrete,
/// runnable Jobs.
Expand All @@ -47,7 +49,7 @@ class ToolChain {
ToolChain(const Driver &D, const llvm::Triple &T) : D(D), Triple(T) {}

/// A special name used to identify the Swift executable itself.
constexpr static const char * const SWIFT_EXECUTABLE_NAME = "swift";
constexpr static const char *const SWIFT_EXECUTABLE_NAME = "swift";

/// Packs together the supplementary information about the job being created.
class JobContext {
Expand Down Expand Up @@ -122,45 +124,36 @@ class ToolChain {

InvocationInfo(const char *name, llvm::opt::ArgStringList args = {},
decltype(ExtraEnvironment) extraEnv = {})
: ExecutableName(name), Arguments(std::move(args)),
ExtraEnvironment(std::move(extraEnv)) {}
: ExecutableName(name), Arguments(std::move(args)),
ExtraEnvironment(std::move(extraEnv)) {}
};

virtual InvocationInfo
constructInvocation(const CompileJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const InterpretJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const BackendJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const MergeModuleJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const ModuleWrapJobAction &job,
const JobContext &context) const;

virtual InvocationInfo
constructInvocation(const REPLJobAction &job,
const JobContext &context) const;

virtual InvocationInfo
constructInvocation(const GenerateDSYMJobAction &job,
const JobContext &context) const;
virtual InvocationInfo constructInvocation(const CompileJobAction &job,
const JobContext &context) const;
virtual InvocationInfo constructInvocation(const InterpretJobAction &job,
const JobContext &context) const;
virtual InvocationInfo constructInvocation(const BackendJobAction &job,
const JobContext &context) const;
virtual InvocationInfo constructInvocation(const MergeModuleJobAction &job,
const JobContext &context) const;
virtual InvocationInfo constructInvocation(const ModuleWrapJobAction &job,
const JobContext &context) const;

virtual InvocationInfo constructInvocation(const REPLJobAction &job,
const JobContext &context) const;

virtual InvocationInfo constructInvocation(const GenerateDSYMJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const VerifyDebugInfoJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const GeneratePCHJobAction &job,
const JobContext &context) const;
virtual InvocationInfo constructInvocation(const GeneratePCHJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const AutolinkExtractJobAction &job,
const JobContext &context) const;
virtual InvocationInfo
constructInvocation(const LinkJobAction &job,
const JobContext &context) const;
virtual InvocationInfo constructInvocation(const LinkJobAction &job,
const JobContext &context) const;

/// Searches for the given executable in appropriate paths relative to the
/// Swift binary.
Expand All @@ -176,6 +169,34 @@ class ToolChain {
/// This method is invoked by findProgramRelativeToSwift().
virtual std::string findProgramRelativeToSwiftImpl(StringRef name) const;

void addInputsOfType(llvm::opt::ArgStringList &Arguments,
ArrayRef<const Action *> Inputs,
file_types::ID InputType,
const char *PrefixArgument = nullptr) const;

void addInputsOfType(llvm::opt::ArgStringList &Arguments,
ArrayRef<const Job *> Jobs,
const llvm::opt::ArgList &Args, file_types::ID InputType,
const char *PrefixArgument = nullptr) const;

void addPrimaryInputsOfType(llvm::opt::ArgStringList &Arguments,
ArrayRef<const Job *> Jobs,
const llvm::opt::ArgList &Args,
file_types::ID InputType,
const char *PrefixArgument = nullptr) const;

/// Get the runtime library link path, which is platform-specific and found
/// relative to the compiler.
void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
const llvm::opt::ArgList &args, bool shared) const;

void addPathEnvironmentVariableIfNeeded(Job::EnvironmentVector &env,
const char *name,
const char *separator,
options::ID optionID,
const llvm::opt::ArgList &args,
StringRef extraEntry = "") const;

public:
virtual ~ToolChain() = default;

Expand All @@ -187,8 +208,7 @@ class ToolChain {
///
/// This method dispatches to the various \c constructInvocation methods,
/// which may be overridden by platform-specific subclasses.
std::unique_ptr<Job> constructJob(const JobAction &JA,
Compilation &C,
std::unique_ptr<Job> constructJob(const JobAction &JA, Compilation &C,
SmallVectorImpl<const Job *> &&inputs,
ArrayRef<const Action *> inputActions,
std::unique_ptr<CommandOutput> output,
Expand Down Expand Up @@ -221,16 +241,35 @@ class ToolChain {
/// Return the default language type to use for the given extension.
/// If the extension is empty or is otherwise not recognized, return
/// the invalid type \c TY_INVALID.
virtual file_types::ID lookupTypeForExtension(StringRef Ext) const;
file_types::ID lookupTypeForExtension(StringRef Ext) const;

/// Check whether a clang library with a given name exists.
/// Copies the path for the directory clang libraries would be stored in on
/// the current toolchain.
void getClangLibraryPath(const llvm::opt::ArgList &Args,
SmallString<128> &LibPath) const;

/// Returns the name the clang library for a given sanitizer would have on
/// the current toolchain.
///
/// \param Sanitizer Sanitizer name.
/// \param shared Whether the library is shared
virtual std::string sanitizerRuntimeLibName(StringRef Sanitizer,
bool shared = true) const = 0;

/// Returns whether a given sanitizer exists for the current toolchain.
///
/// \param args Invocation arguments.
/// \param sanitizer Sanitizer name.
/// \param shared Whether the library is shared
virtual bool sanitizerRuntimeLibExists(const llvm::opt::ArgList &args,
StringRef sanitizer,
bool shared=true) const;
bool sanitizerRuntimeLibExists(const llvm::opt::ArgList &args,
StringRef sanitizer, bool shared = true) const;

/// Adds a runtime library to the arguments list for linking.
///
/// \param LibName The library name
/// \param Arguments The arguments list to append to
void addLinkRuntimeLib(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &Arguments,
StringRef LibName) const;
};
} // end namespace driver
} // end namespace swift
Expand Down
3 changes: 3 additions & 0 deletions lib/Driver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
set(swiftDriver_sources
Action.cpp
Compilation.cpp
DarwinToolChains.cpp
DependencyGraph.cpp
Driver.cpp
FrontendUtil.cpp
Expand All @@ -9,6 +10,8 @@ set(swiftDriver_sources
PrettyStackTrace.cpp
ToolChain.cpp
ToolChains.cpp
UnixToolChains.cpp
WindowsToolChains.cpp
)

set(swiftDriver_targetDefines)
Expand Down
Loading