From eb4602db1a5063263d3fae4b271ab0243446cc38 Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 2 Jul 2015 22:52:08 +0000 Subject: [PATCH] Driver: Remove the Job class. NFC We had a strange relationship here where we made a list of Jobs inherit from a single Job, but there weren't actually any places where this arbitrary nesting was used or needed. Simplify all of this by removing Job entirely and updating all of the users to either work with a JobList or a single Command. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241310 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Driver/Compilation.h | 5 ++- include/clang/Driver/Driver.h | 4 +- include/clang/Driver/Job.h | 59 ++++------------------------- lib/Driver/Compilation.cpp | 16 +++----- lib/Driver/Driver.cpp | 25 ++++-------- lib/Driver/Job.cpp | 8 +--- lib/Tooling/CompilationDatabase.cpp | 13 +++---- 7 files changed, 34 insertions(+), 96 deletions(-) diff --git a/include/clang/Driver/Compilation.h b/include/clang/Driver/Compilation.h index 5574e2ca05..f0c1bedb39 100644 --- a/include/clang/Driver/Compilation.h +++ b/include/clang/Driver/Compilation.h @@ -169,8 +169,9 @@ public: /// /// \param FailingCommands - For non-zero results, this will be a vector of /// failing commands and their associated result code. - void ExecuteJob(const Job &J, - SmallVectorImpl< std::pair > &FailingCommands) const; + void ExecuteJobs( + const JobList &Jobs, + SmallVectorImpl> &FailingCommands) const; /// initCompilationForDiagnostics - Remove stale state and suppress output /// so compilation can be reexecuted to generate additional diagnostic diff --git a/include/clang/Driver/Driver.h b/include/clang/Driver/Driver.h index 577826ed6a..15c194b098 100644 --- a/include/clang/Driver/Driver.h +++ b/include/clang/Driver/Driver.h @@ -42,7 +42,7 @@ namespace driver { class Command; class Compilation; class InputInfo; - class Job; + class JobList; class JobAction; class SanitizerArgs; class ToolChain; @@ -195,7 +195,7 @@ private: llvm::opt::Arg **FinalPhaseArg = nullptr) const; // Before executing jobs, sets up response files for commands that need them. - void setUpResponseFiles(Compilation &C, Job &J); + void setUpResponseFiles(Compilation &C, Command &Cmd); void generatePrefixedToolNames(const char *Tool, const ToolChain &TC, SmallVectorImpl &Names) const; diff --git a/include/clang/Driver/Job.h b/include/clang/Driver/Job.h index dda3ab5864..8fc2e8d3a5 100644 --- a/include/clang/Driver/Job.h +++ b/include/clang/Driver/Job.h @@ -37,37 +37,9 @@ struct CrashReportInfo { : Filename(Filename), VFSPath(VFSPath) {} }; -class Job { -public: - enum JobClass { - CommandClass, - FallbackCommandClass, - JobListClass - }; - -private: - JobClass Kind; - -protected: - Job(JobClass Kind) : Kind(Kind) {} -public: - virtual ~Job(); - - JobClass getKind() const { return Kind; } - - /// Print - Print this Job in -### format. - /// - /// \param OS - The stream to print on. - /// \param Terminator - A string to print at the end of the line. - /// \param Quote - Should separate arguments be quoted. - /// \param CrashInfo - Details for inclusion in a crash report. - virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, - CrashReportInfo *CrashInfo = nullptr) const = 0; -}; - /// Command - An executable path/name and argument vector to /// execute. -class Command : public Job { +class Command { /// Source - The action which caused the creation of this job. const Action &Source; @@ -108,9 +80,10 @@ class Command : public Job { public: Command(const Action &Source, const Tool &Creator, const char *Executable, const llvm::opt::ArgStringList &Arguments); + virtual ~Command() {} - void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, - CrashReportInfo *CrashInfo = nullptr) const override; + virtual void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote, + CrashReportInfo *CrashInfo = nullptr) const; virtual int Execute(const StringRef **Redirects, std::string *ErrMsg, bool *ExecutionFailed) const; @@ -133,11 +106,6 @@ public: const char *getExecutable() const { return Executable; } const llvm::opt::ArgStringList &getArguments() const { return Arguments; } - - static bool classof(const Job *J) { - return J->getKind() == CommandClass || - J->getKind() == FallbackCommandClass; - } }; /// Like Command, but with a fallback which is executed in case @@ -154,18 +122,14 @@ public: int Execute(const StringRef **Redirects, std::string *ErrMsg, bool *ExecutionFailed) const override; - static bool classof(const Job *J) { - return J->getKind() == FallbackCommandClass; - } - private: std::unique_ptr Fallback; }; /// JobList - A sequence of jobs to perform. -class JobList : public Job { +class JobList { public: - typedef SmallVector, 4> list_type; + typedef SmallVector, 4> list_type; typedef list_type::size_type size_type; typedef llvm::pointee_iterator iterator; typedef llvm::pointee_iterator const_iterator; @@ -174,14 +138,11 @@ private: list_type Jobs; public: - JobList(); - ~JobList() override {} - void Print(llvm::raw_ostream &OS, const char *Terminator, - bool Quote, CrashReportInfo *CrashInfo = nullptr) const override; + bool Quote, CrashReportInfo *CrashInfo = nullptr) const; /// Add a job to the list (taking ownership). - void addJob(std::unique_ptr J) { Jobs.push_back(std::move(J)); } + void addJob(std::unique_ptr J) { Jobs.push_back(std::move(J)); } /// Clear the job list. void clear(); @@ -193,10 +154,6 @@ public: const_iterator begin() const { return Jobs.begin(); } iterator end() { return Jobs.end(); } const_iterator end() const { return Jobs.end(); } - - static bool classof(const Job *J) { - return J->getKind() == JobListClass; - } }; } // end namespace driver diff --git a/lib/Driver/Compilation.cpp b/lib/Driver/Compilation.cpp index 2bcbd5cf94..101d1fcc83 100644 --- a/lib/Driver/Compilation.cpp +++ b/lib/Driver/Compilation.cpp @@ -192,18 +192,14 @@ static bool InputsOk(const Command &C, return !ActionFailed(&C.getSource(), FailingCommands); } -void Compilation::ExecuteJob(const Job &J, - FailingCommandList &FailingCommands) const { - if (const Command *C = dyn_cast(&J)) { - if (!InputsOk(*C, FailingCommands)) - return; +void Compilation::ExecuteJobs(const JobList &Jobs, + FailingCommandList &FailingCommands) const { + for (const auto &Job : Jobs) { + if (!InputsOk(Job, FailingCommands)) + continue; const Command *FailingCommand = nullptr; - if (int Res = ExecuteCommand(*C, FailingCommand)) + if (int Res = ExecuteCommand(Job, FailingCommand)) FailingCommands.push_back(std::make_pair(Res, FailingCommand)); - } else { - const JobList *Jobs = cast(&J); - for (const auto &Job : *Jobs) - ExecuteJob(Job, FailingCommands); } } diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index a146ba0f46..b9dc35d621 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -500,7 +500,7 @@ void Driver::generateCompilationDiagnostics(Compilation &C, // Generate preprocessed output. SmallVector, 4> FailingCommands; - C.ExecuteJob(C.getJobs(), FailingCommands); + C.ExecuteJobs(C.getJobs(), FailingCommands); // If any of the preprocessing commands failed, clean up and exit. if (!FailingCommands.empty()) { @@ -560,26 +560,16 @@ void Driver::generateCompilationDiagnostics(Compilation &C, << "\n\n********************"; } -void Driver::setUpResponseFiles(Compilation &C, Job &J) { - if (JobList *Jobs = dyn_cast(&J)) { - for (auto &Job : *Jobs) - setUpResponseFiles(C, Job); - return; - } - - Command *CurCommand = dyn_cast(&J); - if (!CurCommand) - return; - +void Driver::setUpResponseFiles(Compilation &C, Command &Cmd) { // Since argumentsFitWithinSystemLimits() may underestimate system's capacity // if the tool does not support response files, there is a chance/ that things // will just work without a response file, so we silently just skip it. - if (CurCommand->getCreator().getResponseFilesSupport() == Tool::RF_None || - llvm::sys::argumentsFitWithinSystemLimits(CurCommand->getArguments())) + if (Cmd.getCreator().getResponseFilesSupport() == Tool::RF_None || + llvm::sys::argumentsFitWithinSystemLimits(Cmd.getArguments())) return; std::string TmpName = GetTemporaryPath("response", "txt"); - CurCommand->setResponseFile( + Cmd.setResponseFile( C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()))); } @@ -597,9 +587,10 @@ int Driver::ExecuteCompilation( return 1; // Set up response file names for each command, if necessary - setUpResponseFiles(C, C.getJobs()); + for (auto &Job : C.getJobs()) + setUpResponseFiles(C, Job); - C.ExecuteJob(C.getJobs(), FailingCommands); + C.ExecuteJobs(C.getJobs(), FailingCommands); // Remove temp files. C.CleanupFileList(C.getTempFiles()); diff --git a/lib/Driver/Job.cpp b/lib/Driver/Job.cpp index 4b5b839e52..ac18e1eb56 100644 --- a/lib/Driver/Job.cpp +++ b/lib/Driver/Job.cpp @@ -25,12 +25,10 @@ using llvm::raw_ostream; using llvm::StringRef; using llvm::ArrayRef; -Job::~Job() {} - Command::Command(const Action &Source, const Tool &Creator, const char *Executable, const ArgStringList &Arguments) - : Job(CommandClass), Source(Source), Creator(Creator), - Executable(Executable), Arguments(Arguments), ResponseFile(nullptr) {} + : Source(Source), Creator(Creator), Executable(Executable), + Arguments(Arguments), ResponseFile(nullptr) {} static int skipArgs(const char *Flag, bool HaveCrashVFS) { // These flags are all of the form -Flag and are treated as two @@ -293,8 +291,6 @@ int FallbackCommand::Execute(const StringRef **Redirects, std::string *ErrMsg, return SecondaryStatus; } -JobList::JobList() : Job(JobListClass) {} - void JobList::Print(raw_ostream &OS, const char *Terminator, bool Quote, CrashReportInfo *CrashInfo) const { for (const auto &Job : *this) diff --git a/lib/Tooling/CompilationDatabase.cpp b/lib/Tooling/CompilationDatabase.cpp index 4483b189ca..2272be632b 100644 --- a/lib/Tooling/CompilationDatabase.cpp +++ b/lib/Tooling/CompilationDatabase.cpp @@ -250,14 +250,11 @@ static bool stripPositionalArgs(std::vector Args, CompileJobAnalyzer CompileAnalyzer; - for (const auto &Job : Jobs) { - if (Job.getKind() == driver::Job::CommandClass) { - const driver::Command &Cmd = cast(Job); - // Collect only for Assemble jobs. If we do all jobs we get duplicates - // since Link jobs point to Assemble jobs as inputs. - if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass) - CompileAnalyzer.run(&Cmd.getSource()); - } + for (const auto &Cmd : Jobs) { + // Collect only for Assemble jobs. If we do all jobs we get duplicates + // since Link jobs point to Assemble jobs as inputs. + if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass) + CompileAnalyzer.run(&Cmd.getSource()); } if (CompileAnalyzer.Inputs.empty()) { -- 2.40.0