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/OwningPtr.h"
15 #include "llvm/ADT/SmallVector.h"
16 #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 virtual void Print(llvm::raw_ostream &OS, const char *Terminator,
80 bool Quote, bool CrashReport = false) const;
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 llvm::opt::ArgStringList &getArguments() const { return Arguments; }
93 static bool classof(const Job *J) {
94 return J->getKind() == CommandClass ||
95 J->getKind() == FallbackCommandClass;
99 /// Like Command, but with a fallback which is executed in case
100 /// the primary command crashes.
101 class FallbackCommand : public Command {
103 FallbackCommand(const Action &Source_, const Tool &Creator_,
104 const char *Executable_, const ArgStringList &Arguments_,
107 virtual void Print(llvm::raw_ostream &OS, const char *Terminator,
108 bool Quote, bool CrashReport = false) const;
110 virtual int Execute(const StringRef **Redirects, std::string *ErrMsg,
111 bool *ExecutionFailed) const;
113 static bool classof(const Job *J) {
114 return J->getKind() == FallbackCommandClass;
118 OwningPtr<Command> Fallback;
121 /// JobList - A sequence of jobs to perform.
122 class JobList : public Job {
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;
136 virtual void Print(llvm::raw_ostream &OS, const char *Terminator,
137 bool Quote, bool CrashReport = false) const;
139 /// Add a job to the list (taking ownership).
140 void addJob(Job *J) { Jobs.push_back(J); }
142 /// Clear the job list.
145 const list_type &getJobs() const { return Jobs; }
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(); }
153 static bool classof(const Job *J) {
154 return J->getKind() == JobListClass;
158 } // end namespace driver
159 } // end namespace clang