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