Job.h revision daab7b1016f0a82fefa4f7be6e63c57c06b19ffc
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/Driver/Util.h" 14#include "llvm/ADT/SmallVector.h" 15 16#include "llvm/Support/Casting.h" 17using llvm::isa; 18using llvm::cast; 19using llvm::cast_or_null; 20using llvm::dyn_cast; 21using llvm::dyn_cast_or_null; 22 23namespace clang { 24namespace driver { 25class Command; 26class Tool; 27 28class Job { 29public: 30 enum JobClass { 31 CommandClass, 32 PipedJobClass, 33 JobListClass 34 }; 35 36private: 37 JobClass Kind; 38 39protected: 40 Job(JobClass _Kind) : Kind(_Kind) {} 41public: 42 virtual ~Job(); 43 44 JobClass getKind() const { return Kind; } 45 46 /// addCommand - Append a command to the current job, which must be 47 /// either a piped job or a job list. 48 void addCommand(Command *C); 49 50 static bool classof(const Job *) { return true; } 51}; 52 53 /// Command - An executable path/name and argument vector to 54 /// execute. 55class Command : public Job { 56 /// Source - The action which caused the creation of this job. 57 const Action &Source; 58 59 /// Tool - The tool which caused the creation of this job. 60 const Tool &Creator; 61 62 /// The executable to run. 63 const char *Executable; 64 65 /// The list of program arguments (not including the implicit first 66 /// argument, which will be the executable). 67 ArgStringList Arguments; 68 69public: 70 Command(const Action &_Source, const Tool &_Creator, const char *_Executable, 71 const ArgStringList &_Arguments); 72 73 /// getSource - Return the Action which caused the creation of this job. 74 const Action &getSource() const { return Source; } 75 76 /// getCreator - Return the Tool which caused the creation of this job. 77 const Tool &getCreator() const { return Creator; } 78 79 const char *getExecutable() const { return Executable; } 80 81 const ArgStringList &getArguments() const { return Arguments; } 82 83 static bool classof(const Job *J) { 84 return J->getKind() == CommandClass; 85 } 86 static bool classof(const Command *) { return true; } 87}; 88 89 /// PipedJob - A list of Commands which should be executed together 90 /// with their standard inputs and outputs connected. 91class PipedJob : public Job { 92public: 93 typedef llvm::SmallVector<Command*, 4> list_type; 94 typedef list_type::size_type size_type; 95 typedef list_type::iterator iterator; 96 typedef list_type::const_iterator const_iterator; 97 98private: 99 list_type Commands; 100 101public: 102 PipedJob(); 103 104 void addCommand(Command *C) { Commands.push_back(C); } 105 106 const list_type &getCommands() const { return Commands; } 107 108 size_type size() const { return Commands.size(); } 109 iterator begin() { return Commands.begin(); } 110 const_iterator begin() const { return Commands.begin(); } 111 iterator end() { return Commands.end(); } 112 const_iterator end() const { return Commands.end(); } 113 114 static bool classof(const Job *J) { 115 return J->getKind() == PipedJobClass; 116 } 117 static bool classof(const PipedJob *) { return true; } 118}; 119 120 /// JobList - A sequence of jobs to perform. 121class JobList : public Job { 122public: 123 typedef llvm::SmallVector<Job*, 4> list_type; 124 typedef list_type::size_type size_type; 125 typedef list_type::iterator iterator; 126 typedef list_type::const_iterator const_iterator; 127 128private: 129 list_type Jobs; 130 131public: 132 JobList(); 133 134 void addJob(Job *J) { Jobs.push_back(J); } 135 136 const list_type &getJobs() const { return Jobs; } 137 138 size_type size() const { return Jobs.size(); } 139 iterator begin() { return Jobs.begin(); } 140 const_iterator begin() const { return Jobs.begin(); } 141 iterator end() { return Jobs.end(); } 142 const_iterator end() const { return Jobs.end(); } 143 144 static bool classof(const Job *J) { 145 return J->getKind() == JobListClass; 146 } 147 static bool classof(const JobList *) { return true; } 148}; 149 150} // end namespace driver 151} // end namespace clang 152 153#endif 154