1 //===--- Job.h - Commands to Execute ----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_DRIVER_JOB_H_
11 #define CLANG_DRIVER_JOB_H_
13 #include "clang/Basic/LLVM.h"
14 #include "llvm/ADT/SmallVector.h"
15 #include "llvm/Option/Option.h"
28 // Re-export this as clang::driver::ArgStringList.
29 using llvm::opt::ArgStringList;
43 Job(JobClass _Kind) : Kind(_Kind) {}
47 JobClass getKind() const { return Kind; }
49 /// Print - Print this Job in -### format.
51 /// \param OS - The stream to print on.
52 /// \param Terminator - A string to print at the end of the line.
53 /// \param Quote - Should separate arguments be quoted.
54 /// \param CrashReport - Whether to print for inclusion in a crash report.
55 virtual void Print(llvm::raw_ostream &OS, const char *Terminator,
56 bool Quote, bool CrashReport = false) const = 0;
59 /// Command - An executable path/name and argument vector to
61 class Command : public Job {
62 /// Source - The action which caused the creation of this job.
65 /// Tool - The tool which caused the creation of this job.
68 /// The executable to run.
69 const char *Executable;
71 /// The list of program arguments (not including the implicit first
72 /// argument, which will be the executable).
73 llvm::opt::ArgStringList Arguments;
76 Command(const Action &_Source, const Tool &_Creator, const char *_Executable,
77 const llvm::opt::ArgStringList &_Arguments);
79 void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
80 bool CrashReport = false) const override;
82 virtual int Execute(const StringRef **Redirects, std::string *ErrMsg,
83 bool *ExecutionFailed) const;
85 /// getSource - Return the Action which caused the creation of this job.
86 const Action &getSource() const { return Source; }
88 /// getCreator - Return the Tool which caused the creation of this job.
89 const Tool &getCreator() const { return Creator; }
91 const char *getExecutable() const { return Executable; }
93 const llvm::opt::ArgStringList &getArguments() const { return Arguments; }
95 static bool classof(const Job *J) {
96 return J->getKind() == CommandClass ||
97 J->getKind() == FallbackCommandClass;
101 /// Like Command, but with a fallback which is executed in case
102 /// the primary command crashes.
103 class FallbackCommand : public Command {
105 FallbackCommand(const Action &Source_, const Tool &Creator_,
106 const char *Executable_, const ArgStringList &Arguments_,
109 void Print(llvm::raw_ostream &OS, const char *Terminator, bool Quote,
110 bool CrashReport = false) const override;
112 int Execute(const StringRef **Redirects, std::string *ErrMsg,
113 bool *ExecutionFailed) const override;
115 static bool classof(const Job *J) {
116 return J->getKind() == FallbackCommandClass;
120 std::unique_ptr<Command> Fallback;
123 /// JobList - A sequence of jobs to perform.
124 class JobList : public Job {
126 typedef SmallVector<Job*, 4> list_type;
127 typedef list_type::size_type size_type;
128 typedef list_type::iterator iterator;
129 typedef list_type::const_iterator const_iterator;
138 void Print(llvm::raw_ostream &OS, const char *Terminator,
139 bool Quote, bool CrashReport = false) const override;
141 /// Add a job to the list (taking ownership).
142 void addJob(Job *J) { Jobs.push_back(J); }
144 /// Clear the job list.
147 const list_type &getJobs() const { return Jobs; }
149 size_type size() const { return Jobs.size(); }
150 iterator begin() { return Jobs.begin(); }
151 const_iterator begin() const { return Jobs.begin(); }
152 iterator end() { return Jobs.end(); }
153 const_iterator end() const { return Jobs.end(); }
155 static bool classof(const Job *J) {
156 return J->getKind() == JobListClass;
160 } // end namespace driver
161 } // end namespace clang