Job.h revision 263508
1//===--- Job.h - Commands to Execute ----------------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef CLANG_DRIVER_JOB_H_ 11#define CLANG_DRIVER_JOB_H_ 12 13#include "clang/Basic/LLVM.h" 14#include "llvm/ADT/OwningPtr.h" 15#include "llvm/ADT/SmallVector.h" 16#include "llvm/Option/Option.h" 17 18namespace llvm { 19 class raw_ostream; 20} 21 22namespace clang { 23namespace driver { 24class Action; 25class Command; 26class Tool; 27 28// Re-export this as clang::driver::ArgStringList. 29using llvm::opt::ArgStringList; 30 31class Job { 32public: 33 enum JobClass { 34 CommandClass, 35 FallbackCommandClass, 36 JobListClass 37 }; 38 39private: 40 JobClass Kind; 41 42protected: 43 Job(JobClass _Kind) : Kind(_Kind) {} 44public: 45 virtual ~Job(); 46 47 JobClass getKind() const { return Kind; } 48 49 /// Print - Print this Job in -### format. 50 /// 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; 57}; 58 59/// Command - An executable path/name and argument vector to 60/// execute. 61class Command : public Job { 62 /// Source - The action which caused the creation of this job. 63 const Action &Source; 64 65 /// Tool - The tool which caused the creation of this job. 66 const Tool &Creator; 67 68 /// The executable to run. 69 const char *Executable; 70 71 /// The list of program arguments (not including the implicit first 72 /// argument, which will be the executable). 73 llvm::opt::ArgStringList Arguments; 74 75public: 76 Command(const Action &_Source, const Tool &_Creator, const char *_Executable, 77 const llvm::opt::ArgStringList &_Arguments); 78 79 virtual void Print(llvm::raw_ostream &OS, const char *Terminator, 80 bool Quote, bool CrashReport = false) const; 81 82 virtual int Execute(const StringRef **Redirects, std::string *ErrMsg, 83 bool *ExecutionFailed) const; 84 85 /// getSource - Return the Action which caused the creation of this job. 86 const Action &getSource() const { return Source; } 87 88 /// getCreator - Return the Tool which caused the creation of this job. 89 const Tool &getCreator() const { return Creator; } 90 91 const llvm::opt::ArgStringList &getArguments() const { return Arguments; } 92 93 static bool classof(const Job *J) { 94 return J->getKind() == CommandClass || 95 J->getKind() == FallbackCommandClass; 96 } 97}; 98 99/// Like Command, but with a fallback which is executed in case 100/// the primary command crashes. 101class FallbackCommand : public Command { 102public: 103 FallbackCommand(const Action &Source_, const Tool &Creator_, 104 const char *Executable_, const ArgStringList &Arguments_, 105 Command *Fallback_); 106 107 virtual void Print(llvm::raw_ostream &OS, const char *Terminator, 108 bool Quote, bool CrashReport = false) const; 109 110 virtual int Execute(const StringRef **Redirects, std::string *ErrMsg, 111 bool *ExecutionFailed) const; 112 113 static bool classof(const Job *J) { 114 return J->getKind() == FallbackCommandClass; 115 } 116 117private: 118 OwningPtr<Command> Fallback; 119}; 120 121/// JobList - A sequence of jobs to perform. 122class JobList : public Job { 123public: 124 typedef SmallVector<Job*, 4> list_type; 125 typedef list_type::size_type size_type; 126 typedef list_type::iterator iterator; 127 typedef list_type::const_iterator const_iterator; 128 129private: 130 list_type Jobs; 131 132public: 133 JobList(); 134 virtual ~JobList(); 135 136 virtual void Print(llvm::raw_ostream &OS, const char *Terminator, 137 bool Quote, bool CrashReport = false) const; 138 139 /// Add a job to the list (taking ownership). 140 void addJob(Job *J) { Jobs.push_back(J); } 141 142 /// Clear the job list. 143 void clear(); 144 145 const list_type &getJobs() const { return Jobs; } 146 147 size_type size() const { return Jobs.size(); } 148 iterator begin() { return Jobs.begin(); } 149 const_iterator begin() const { return Jobs.begin(); } 150 iterator end() { return Jobs.end(); } 151 const_iterator end() const { return Jobs.end(); } 152 153 static bool classof(const Job *J) { 154 return J->getKind() == JobListClass; 155 } 156}; 157 158} // end namespace driver 159} // end namespace clang 160 161#endif 162