clang  3.7.0
Action.h
Go to the documentation of this file.
1 //===--- Action.h - Abstract compilation steps ------------------*- 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 LLVM_CLANG_DRIVER_ACTION_H
11 #define LLVM_CLANG_DRIVER_ACTION_H
12 
13 #include "clang/Driver/Types.h"
14 #include "clang/Driver/Util.h"
15 #include "llvm/ADT/SmallVector.h"
16 
17 namespace llvm {
18 namespace opt {
19  class Arg;
20 }
21 }
22 
23 namespace clang {
24 namespace driver {
25 
26 /// Action - Represent an abstract compilation step to perform.
27 ///
28 /// An action represents an edge in the compilation graph; typically
29 /// it is a job to transform an input using some tool.
30 ///
31 /// The current driver is hard wired to expect actions which produce a
32 /// single primary output, at least in terms of controlling the
33 /// compilation. Actions can produce auxiliary files, but can only
34 /// produce a single output to feed into subsequent actions.
35 class Action {
36 public:
37  typedef ActionList::size_type size_type;
38  typedef ActionList::iterator iterator;
39  typedef ActionList::const_iterator const_iterator;
40 
41  enum ActionClass {
58 
61  };
62 
63  static const char *getClassName(ActionClass AC);
64 
65 private:
67 
68  /// The output type of this action.
70 
71  ActionList Inputs;
72 
73  unsigned OwnsInputs : 1;
74 
75 protected:
77  : Kind(Kind), Type(Type), OwnsInputs(true) {}
78  Action(ActionClass Kind, std::unique_ptr<Action> Input, types::ID Type)
79  : Kind(Kind), Type(Type), Inputs(1, Input.release()), OwnsInputs(true) {
80  }
81  Action(ActionClass Kind, std::unique_ptr<Action> Input)
82  : Kind(Kind), Type(Input->getType()), Inputs(1, Input.release()),
83  OwnsInputs(true) {}
85  : Kind(Kind), Type(Type), Inputs(Inputs), OwnsInputs(true) {}
86 public:
87  virtual ~Action();
88 
89  const char *getClassName() const { return Action::getClassName(getKind()); }
90 
91  bool getOwnsInputs() { return OwnsInputs; }
92  void setOwnsInputs(bool Value) { OwnsInputs = Value; }
93 
94  ActionClass getKind() const { return Kind; }
95  types::ID getType() const { return Type; }
96 
97  ActionList &getInputs() { return Inputs; }
98  const ActionList &getInputs() const { return Inputs; }
99 
100  size_type size() const { return Inputs.size(); }
101 
102  iterator begin() { return Inputs.begin(); }
103  iterator end() { return Inputs.end(); }
104  const_iterator begin() const { return Inputs.begin(); }
105  const_iterator end() const { return Inputs.end(); }
106 };
107 
108 class InputAction : public Action {
109  virtual void anchor();
110  const llvm::opt::Arg &Input;
111 
112 public:
113  InputAction(const llvm::opt::Arg &Input, types::ID Type);
114 
115  const llvm::opt::Arg &getInputArg() const { return Input; }
116 
117  static bool classof(const Action *A) {
118  return A->getKind() == InputClass;
119  }
120 };
121 
122 class BindArchAction : public Action {
123  virtual void anchor();
124  /// The architecture to bind, or 0 if the default architecture
125  /// should be bound.
126  const char *ArchName;
127 
128 public:
129  BindArchAction(std::unique_ptr<Action> Input, const char *ArchName);
130 
131  const char *getArchName() const { return ArchName; }
132 
133  static bool classof(const Action *A) {
134  return A->getKind() == BindArchClass;
135  }
136 };
137 
138 class CudaDeviceAction : public Action {
139  virtual void anchor();
140  /// GPU architecture to bind -- e.g 'sm_35'.
141  const char *GpuArchName;
142  /// True when action results are not consumed by the host action (e.g when
143  /// -fsyntax-only or --cuda-device-only options are used).
144  bool AtTopLevel;
145 
146 public:
147  CudaDeviceAction(std::unique_ptr<Action> Input, const char *ArchName,
148  bool AtTopLevel);
149 
150  const char *getGpuArchName() const { return GpuArchName; }
151  bool isAtTopLevel() const { return AtTopLevel; }
152 
153  static bool classof(const Action *A) {
154  return A->getKind() == CudaDeviceClass;
155  }
156 };
157 
158 class CudaHostAction : public Action {
159  virtual void anchor();
160  ActionList DeviceActions;
161 
162 public:
163  CudaHostAction(std::unique_ptr<Action> Input,
164  const ActionList &DeviceActions);
165  ~CudaHostAction() override;
166 
167  ActionList &getDeviceActions() { return DeviceActions; }
168  const ActionList &getDeviceActions() const { return DeviceActions; }
169 
170  static bool classof(const Action *A) { return A->getKind() == CudaHostClass; }
171 };
172 
173 class JobAction : public Action {
174  virtual void anchor();
175 protected:
176  JobAction(ActionClass Kind, std::unique_ptr<Action> Input, types::ID Type);
177  JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
178 
179 public:
180  static bool classof(const Action *A) {
181  return (A->getKind() >= JobClassFirst &&
182  A->getKind() <= JobClassLast);
183  }
184 };
185 
187  void anchor() override;
188 public:
189  PreprocessJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
190 
191  static bool classof(const Action *A) {
192  return A->getKind() == PreprocessJobClass;
193  }
194 };
195 
197  void anchor() override;
198 public:
199  PrecompileJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
200 
201  static bool classof(const Action *A) {
202  return A->getKind() == PrecompileJobClass;
203  }
204 };
205 
206 class AnalyzeJobAction : public JobAction {
207  void anchor() override;
208 public:
209  AnalyzeJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
210 
211  static bool classof(const Action *A) {
212  return A->getKind() == AnalyzeJobClass;
213  }
214 };
215 
216 class MigrateJobAction : public JobAction {
217  void anchor() override;
218 public:
219  MigrateJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
220 
221  static bool classof(const Action *A) {
222  return A->getKind() == MigrateJobClass;
223  }
224 };
225 
226 class CompileJobAction : public JobAction {
227  void anchor() override;
228 public:
229  CompileJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
230 
231  static bool classof(const Action *A) {
232  return A->getKind() == CompileJobClass;
233  }
234 };
235 
236 class BackendJobAction : public JobAction {
237  void anchor() override;
238 public:
239  BackendJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
240 
241  static bool classof(const Action *A) {
242  return A->getKind() == BackendJobClass;
243  }
244 };
245 
246 class AssembleJobAction : public JobAction {
247  void anchor() override;
248 public:
249  AssembleJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
250 
251  static bool classof(const Action *A) {
252  return A->getKind() == AssembleJobClass;
253  }
254 };
255 
256 class LinkJobAction : public JobAction {
257  void anchor() override;
258 public:
260 
261  static bool classof(const Action *A) {
262  return A->getKind() == LinkJobClass;
263  }
264 };
265 
266 class LipoJobAction : public JobAction {
267  void anchor() override;
268 public:
270 
271  static bool classof(const Action *A) {
272  return A->getKind() == LipoJobClass;
273  }
274 };
275 
276 class DsymutilJobAction : public JobAction {
277  void anchor() override;
278 public:
280 
281  static bool classof(const Action *A) {
282  return A->getKind() == DsymutilJobClass;
283  }
284 };
285 
286 class VerifyJobAction : public JobAction {
287  void anchor() override;
288 public:
289  VerifyJobAction(ActionClass Kind, std::unique_ptr<Action> Input,
290  types::ID Type);
291  VerifyJobAction(ActionClass Kind, ActionList &Inputs, types::ID Type);
292  static bool classof(const Action *A) {
293  return A->getKind() == VerifyDebugInfoJobClass ||
294  A->getKind() == VerifyPCHJobClass;
295  }
296 };
297 
299  void anchor() override;
300 public:
301  VerifyDebugInfoJobAction(std::unique_ptr<Action> Input, types::ID Type);
302  static bool classof(const Action *A) {
303  return A->getKind() == VerifyDebugInfoJobClass;
304  }
305 };
306 
308  void anchor() override;
309 public:
310  VerifyPCHJobAction(std::unique_ptr<Action> Input, types::ID Type);
311  static bool classof(const Action *A) {
312  return A->getKind() == VerifyPCHJobClass;
313  }
314 };
315 
316 } // end namespace driver
317 } // end namespace clang
318 
319 #endif
static bool classof(const Action *A)
Definition: Action.h:191
bool isAtTopLevel() const
Definition: Action.h:151
const char * getGpuArchName() const
Definition: Action.h:150
size_type size() const
Definition: Action.h:100
static bool classof(const Action *A)
Definition: Action.h:117
PrecompileJobAction(std::unique_ptr< Action > Input, types::ID OutputType)
Definition: Action.cpp:95
static bool classof(const Action *A)
Definition: Action.h:153
const ActionList & getDeviceActions() const
Definition: Action.h:168
static bool classof(const Action *A)
Definition: Action.h:231
LinkJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:131
Action(ActionClass Kind, types::ID Type)
Definition: Action.h:76
BackendJobAction(std::unique_ptr< Action > Input, types::ID OutputType)
Definition: Action.cpp:119
ActionList::iterator iterator
Definition: Action.h:38
iterator begin()
Definition: Action.h:102
InputAction(const llvm::opt::Arg &Input, types::ID Type)
Definition: Action.cpp:48
types::ID getType() const
Definition: Action.h:95
CudaHostAction(std::unique_ptr< Action > Input, const ActionList &DeviceActions)
Definition: Action.cpp:67
ActionList & getInputs()
Definition: Action.h:97
LipoJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:137
static bool classof(const Action *A)
Definition: Action.h:281
const_iterator end() const
Definition: Action.h:105
ActionClass getKind() const
Definition: Action.h:94
AssembleJobAction(std::unique_ptr< Action > Input, types::ID OutputType)
Definition: Action.cpp:125
static bool classof(const Action *A)
Definition: Action.h:180
ActionList & getDeviceActions()
Definition: Action.h:167
static bool classof(const Action *A)
Definition: Action.h:261
ActionList::size_type size_type
Definition: Action.h:37
DsymutilJobAction(ActionList &Inputs, types::ID Type)
Definition: Action.cpp:143
static bool classof(const Action *A)
Definition: Action.h:302
void setOwnsInputs(bool Value)
Definition: Action.h:92
VerifyPCHJobAction(std::unique_ptr< Action > Input, types::ID Type)
Definition: Action.cpp:171
Action(ActionClass Kind, std::unique_ptr< Action > Input, types::ID Type)
Definition: Action.h:78
static bool classof(const Action *A)
Definition: Action.h:201
JobAction(ActionClass Kind, std::unique_ptr< Action > Input, types::ID Type)
Definition: Action.cpp:79
virtual ~Action()
Definition: Action.cpp:16
PreprocessJobAction(std::unique_ptr< Action > Input, types::ID OutputType)
Definition: Action.cpp:89
VerifyJobAction(ActionClass Kind, std::unique_ptr< Action > Input, types::ID Type)
Definition: Action.cpp:149
static bool classof(const Action *A)
Definition: Action.h:241
static bool classof(const Action *A)
Definition: Action.h:311
const llvm::opt::Arg & getInputArg() const
Definition: Action.h:115
iterator end()
Definition: Action.h:103
ActionList::const_iterator const_iterator
Definition: Action.h:39
const ActionList & getInputs() const
Definition: Action.h:98
BindArchAction(std::unique_ptr< Action > Input, const char *ArchName)
Definition: Action.cpp:54
Kind
static bool classof(const Action *A)
Definition: Action.h:251
const char * getArchName() const
Definition: Action.h:131
bool getOwnsInputs()
Definition: Action.h:91
AnalyzeJobAction(std::unique_ptr< Action > Input, types::ID OutputType)
Definition: Action.cpp:101
static bool classof(const Action *A)
Definition: Action.h:271
const char * getClassName() const
Definition: Action.h:89
const_iterator begin() const
Definition: Action.h:104
Action(ActionClass Kind, const ActionList &Inputs, types::ID Type)
Definition: Action.h:84
MigrateJobAction(std::unique_ptr< Action > Input, types::ID OutputType)
Definition: Action.cpp:107
CudaDeviceAction(std::unique_ptr< Action > Input, const char *ArchName, bool AtTopLevel)
Definition: Action.cpp:60
static bool classof(const Action *A)
Definition: Action.h:211
const StringRef Input
Action(ActionClass Kind, std::unique_ptr< Action > Input)
Definition: Action.h:81
CompileJobAction(std::unique_ptr< Action > Input, types::ID OutputType)
Definition: Action.cpp:113
static bool classof(const Action *A)
Definition: Action.h:170
#define true
Definition: stdbool.h:32
static bool classof(const Action *A)
Definition: Action.h:221
static bool classof(const Action *A)
Definition: Action.h:133
VerifyDebugInfoJobAction(std::unique_ptr< Action > Input, types::ID Type)
Definition: Action.cpp:165
static bool classof(const Action *A)
Definition: Action.h:292