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/SmallVector.h" 15 #include "llvm/Option/Option.h" 16 17 namespace clang { 18 namespace driver { 19 class Action; 20 class Command; 21 class Tool; 22 23 using llvm::opt::ArgStringList; 24 25 class Job { 26 public: 27 enum JobClass { 28 CommandClass, 29 JobListClass 30 }; 31 32 private: 33 JobClass Kind; 34 35 protected: 36 Job(JobClass _Kind) : Kind(_Kind) {} 37 public: 38 virtual ~Job(); 39 40 JobClass getKind() const { return Kind; } 41 42 /// addCommand - Append a command to the current job, which must be 43 /// either a piped job or a job list. 44 void addCommand(Command *C); 45 }; 46 47 /// Command - An executable path/name and argument vector to 48 /// execute. 49 class Command : public Job { 50 virtual void anchor(); 51 52 /// Source - The action which caused the creation of this job. 53 const Action &Source; 54 55 /// Tool - The tool which caused the creation of this job. 56 const Tool &Creator; 57 58 /// The executable to run. 59 const char *Executable; 60 61 /// The list of program arguments (not including the implicit first 62 /// argument, which will be the executable). 63 llvm::opt::ArgStringList Arguments; 64 65 public: 66 Command(const Action &_Source, const Tool &_Creator, const char *_Executable, 67 const llvm::opt::ArgStringList &_Arguments); 68 69 /// getSource - Return the Action which caused the creation of this job. 70 const Action &getSource() const { return Source; } 71 72 /// getCreator - Return the Tool which caused the creation of this job. 73 const Tool &getCreator() const { return Creator; } 74 75 const char *getExecutable() const { return Executable; } 76 77 const llvm::opt::ArgStringList &getArguments() const { return Arguments; } 78 79 static bool classof(const Job *J) { 80 return J->getKind() == CommandClass; 81 } 82 }; 83 84 /// JobList - A sequence of jobs to perform. 85 class JobList : public Job { 86 public: 87 typedef SmallVector<Job*, 4> list_type; 88 typedef list_type::size_type size_type; 89 typedef list_type::iterator iterator; 90 typedef list_type::const_iterator const_iterator; 91 92 private: 93 list_type Jobs; 94 95 public: 96 JobList(); 97 virtual ~JobList(); 98 99 /// Add a job to the list (taking ownership). 100 void addJob(Job *J) { Jobs.push_back(J); } 101 102 /// Clear the job list. 103 void clear(); 104 105 const list_type &getJobs() const { return Jobs; } 106 107 size_type size() const { return Jobs.size(); } 108 iterator begin() { return Jobs.begin(); } 109 const_iterator begin() const { return Jobs.begin(); } 110 iterator end() { return Jobs.end(); } 111 const_iterator end() const { return Jobs.end(); } 112 113 static bool classof(const Job *J) { 114 return J->getKind() == JobListClass; 115 } 116 }; 117 118 } // end namespace driver 119 } // end namespace clang 120 121 #endif 122