Job.h revision 4832ee31e6ab96b77ad429ef9347fbf09c099f47
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 17namespace llvm { 18 class raw_ostream; 19} 20 21namespace clang { 22namespace driver { 23class Action; 24class Command; 25class Tool; 26 27// Users of this class will use clang::driver::ArgStringList. 28typedef llvm::opt::ArgStringList ArgStringList; 29 30class Job { 31public: 32 enum JobClass { 33 CommandClass, 34 JobListClass 35 }; 36 37private: 38 JobClass Kind; 39 40protected: 41 Job(JobClass _Kind) : Kind(_Kind) {} 42public: 43 virtual ~Job(); 44 45 JobClass getKind() const { return Kind; } 46 47 /// Print - Print this Job in -### format. 48 /// 49 /// \param OS - The stream to print on. 50 /// \param Terminator - A string to print at the end of the line. 51 /// \param Quote - Should separate arguments be quoted. 52 /// \param CrashReport - Whether to print for inclusion in a crash report. 53 virtual void Print(llvm::raw_ostream &OS, const char *Terminator, 54 bool Quote, bool CrashReport = false) const = 0; 55}; 56 57 /// Command - An executable path/name and argument vector to 58 /// execute. 59class Command : public Job { 60 /// Source - The action which caused the creation of this job. 61 const Action &Source; 62 63 /// Tool - The tool which caused the creation of this job. 64 const Tool &Creator; 65 66 /// The executable to run. 67 const char *Executable; 68 69 /// The list of program arguments (not including the implicit first 70 /// argument, which will be the executable). 71 ArgStringList Arguments; 72 73public: 74 Command(const Action &_Source, const Tool &_Creator, const char *_Executable, 75 const ArgStringList &_Arguments); 76 77 virtual void Print(llvm::raw_ostream &OS, const char *Terminator, 78 bool Quote, bool CrashReport = false) const; 79 80 int Execute(const StringRef **Redirects, std::string *ErrMsg, 81 bool *ExecutionFailed) const; 82 83 /// getSource - Return the Action which caused the creation of this job. 84 const Action &getSource() const { return Source; } 85 86 /// getCreator - Return the Tool which caused the creation of this job. 87 const Tool &getCreator() const { return Creator; } 88 89 const ArgStringList &getArguments() const { return Arguments; } 90 91 static bool classof(const Job *J) { 92 return J->getKind() == CommandClass; 93 } 94}; 95 96 /// JobList - A sequence of jobs to perform. 97class JobList : public Job { 98public: 99 typedef SmallVector<Job*, 4> list_type; 100 typedef list_type::size_type size_type; 101 typedef list_type::iterator iterator; 102 typedef list_type::const_iterator const_iterator; 103 104private: 105 list_type Jobs; 106 107public: 108 JobList(); 109 virtual ~JobList(); 110 111 virtual void Print(llvm::raw_ostream &OS, const char *Terminator, 112 bool Quote, bool CrashReport = false) const; 113 114 /// Add a job to the list (taking ownership). 115 void addJob(Job *J) { Jobs.push_back(J); } 116 117 /// Clear the job list. 118 void clear(); 119 120 const list_type &getJobs() const { return Jobs; } 121 122 size_type size() const { return Jobs.size(); } 123 iterator begin() { return Jobs.begin(); } 124 const_iterator begin() const { return Jobs.begin(); } 125 iterator end() { return Jobs.end(); } 126 const_iterator end() const { return Jobs.end(); } 127 128 static bool classof(const Job *J) { 129 return J->getKind() == JobListClass; 130 } 131}; 132 133} // end namespace driver 134} // end namespace clang 135 136#endif 137