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