]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Driver/Action.h
Merge ^/head r286858 through r287489.
[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 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 {
42     InputClass = 0,
43     BindArchClass,
44     CudaDeviceClass,
45     CudaHostClass,
46     PreprocessJobClass,
47     PrecompileJobClass,
48     AnalyzeJobClass,
49     MigrateJobClass,
50     CompileJobClass,
51     BackendJobClass,
52     AssembleJobClass,
53     LinkJobClass,
54     LipoJobClass,
55     DsymutilJobClass,
56     VerifyDebugInfoJobClass,
57     VerifyPCHJobClass,
58
59     JobClassFirst=PreprocessJobClass,
60     JobClassLast=VerifyPCHJobClass
61   };
62
63   static const char *getClassName(ActionClass AC);
64
65 private:
66   ActionClass Kind;
67
68   /// The output type of this action.
69   types::ID Type;
70
71   ActionList Inputs;
72
73   unsigned OwnsInputs : 1;
74
75 protected:
76   Action(ActionClass Kind, types::ID Type)
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) {}
84   Action(ActionClass Kind, const ActionList &Inputs, types::ID Type)
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
186 class PreprocessJobAction : public JobAction {
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
196 class PrecompileJobAction : public JobAction {
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:
259   LinkJobAction(ActionList &Inputs, types::ID Type);
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:
269   LipoJobAction(ActionList &Inputs, types::ID Type);
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:
279   DsymutilJobAction(ActionList &Inputs, types::ID Type);
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
298 class VerifyDebugInfoJobAction : public VerifyJobAction {
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
307 class VerifyPCHJobAction : public VerifyJobAction {
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