1 //===--- Action.h - Abstract compilation steps ------------------*- 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 LLVM_CLANG_DRIVER_ACTION_H
11 #define LLVM_CLANG_DRIVER_ACTION_H
13 #include "clang/Driver/Types.h"
14 #include "clang/Driver/Util.h"
15 #include "llvm/ADT/SmallVector.h"
26 /// Action - Represent an abstract compilation step to perform.
28 /// An action represents an edge in the compilation graph; typically
29 /// it is a job to transform an input using some tool.
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.
37 typedef ActionList::size_type size_type;
38 typedef ActionList::iterator iterator;
39 typedef ActionList::const_iterator const_iterator;
56 VerifyDebugInfoJobClass,
59 JobClassFirst=PreprocessJobClass,
60 JobClassLast=VerifyPCHJobClass
63 static const char *getClassName(ActionClass AC);
68 /// The output type of this action.
73 unsigned OwnsInputs : 1;
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) {
81 Action(ActionClass Kind, std::unique_ptr<Action> Input)
82 : Kind(Kind), Type(Input->getType()), Inputs(1, Input.release()),
84 Action(ActionClass Kind, const ActionList &Inputs, types::ID Type)
85 : Kind(Kind), Type(Type), Inputs(Inputs), OwnsInputs(true) {}
89 const char *getClassName() const { return Action::getClassName(getKind()); }
91 bool getOwnsInputs() { return OwnsInputs; }
92 void setOwnsInputs(bool Value) { OwnsInputs = Value; }
94 ActionClass getKind() const { return Kind; }
95 types::ID getType() const { return Type; }
97 ActionList &getInputs() { return Inputs; }
98 const ActionList &getInputs() const { return Inputs; }
100 size_type size() const { return Inputs.size(); }
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(); }
108 class InputAction : public Action {
109 virtual void anchor();
110 const llvm::opt::Arg &Input;
113 InputAction(const llvm::opt::Arg &Input, types::ID Type);
115 const llvm::opt::Arg &getInputArg() const { return Input; }
117 static bool classof(const Action *A) {
118 return A->getKind() == InputClass;
122 class BindArchAction : public Action {
123 virtual void anchor();
124 /// The architecture to bind, or 0 if the default architecture
126 const char *ArchName;
129 BindArchAction(std::unique_ptr<Action> Input, const char *ArchName);
131 const char *getArchName() const { return ArchName; }
133 static bool classof(const Action *A) {
134 return A->getKind() == BindArchClass;
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).
147 CudaDeviceAction(std::unique_ptr<Action> Input, const char *ArchName,
150 const char *getGpuArchName() const { return GpuArchName; }
151 bool isAtTopLevel() const { return AtTopLevel; }
153 static bool classof(const Action *A) {
154 return A->getKind() == CudaDeviceClass;
158 class CudaHostAction : public Action {
159 virtual void anchor();
160 ActionList DeviceActions;
163 CudaHostAction(std::unique_ptr<Action> Input,
164 const ActionList &DeviceActions);
165 ~CudaHostAction() override;
167 ActionList &getDeviceActions() { return DeviceActions; }
168 const ActionList &getDeviceActions() const { return DeviceActions; }
170 static bool classof(const Action *A) { return A->getKind() == CudaHostClass; }
173 class JobAction : public Action {
174 virtual void anchor();
176 JobAction(ActionClass Kind, std::unique_ptr<Action> Input, types::ID Type);
177 JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
180 static bool classof(const Action *A) {
181 return (A->getKind() >= JobClassFirst &&
182 A->getKind() <= JobClassLast);
186 class PreprocessJobAction : public JobAction {
187 void anchor() override;
189 PreprocessJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
191 static bool classof(const Action *A) {
192 return A->getKind() == PreprocessJobClass;
196 class PrecompileJobAction : public JobAction {
197 void anchor() override;
199 PrecompileJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
201 static bool classof(const Action *A) {
202 return A->getKind() == PrecompileJobClass;
206 class AnalyzeJobAction : public JobAction {
207 void anchor() override;
209 AnalyzeJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
211 static bool classof(const Action *A) {
212 return A->getKind() == AnalyzeJobClass;
216 class MigrateJobAction : public JobAction {
217 void anchor() override;
219 MigrateJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
221 static bool classof(const Action *A) {
222 return A->getKind() == MigrateJobClass;
226 class CompileJobAction : public JobAction {
227 void anchor() override;
229 CompileJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
231 static bool classof(const Action *A) {
232 return A->getKind() == CompileJobClass;
236 class BackendJobAction : public JobAction {
237 void anchor() override;
239 BackendJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
241 static bool classof(const Action *A) {
242 return A->getKind() == BackendJobClass;
246 class AssembleJobAction : public JobAction {
247 void anchor() override;
249 AssembleJobAction(std::unique_ptr<Action> Input, types::ID OutputType);
251 static bool classof(const Action *A) {
252 return A->getKind() == AssembleJobClass;
256 class LinkJobAction : public JobAction {
257 void anchor() override;
259 LinkJobAction(ActionList &Inputs, types::ID Type);
261 static bool classof(const Action *A) {
262 return A->getKind() == LinkJobClass;
266 class LipoJobAction : public JobAction {
267 void anchor() override;
269 LipoJobAction(ActionList &Inputs, types::ID Type);
271 static bool classof(const Action *A) {
272 return A->getKind() == LipoJobClass;
276 class DsymutilJobAction : public JobAction {
277 void anchor() override;
279 DsymutilJobAction(ActionList &Inputs, types::ID Type);
281 static bool classof(const Action *A) {
282 return A->getKind() == DsymutilJobClass;
286 class VerifyJobAction : public JobAction {
287 void anchor() override;
289 VerifyJobAction(ActionClass Kind, std::unique_ptr<Action> Input,
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;
298 class VerifyDebugInfoJobAction : public VerifyJobAction {
299 void anchor() override;
301 VerifyDebugInfoJobAction(std::unique_ptr<Action> Input, types::ID Type);
302 static bool classof(const Action *A) {
303 return A->getKind() == VerifyDebugInfoJobClass;
307 class VerifyPCHJobAction : public VerifyJobAction {
308 void anchor() override;
310 VerifyPCHJobAction(std::unique_ptr<Action> Input, types::ID Type);
311 static bool classof(const Action *A) {
312 return A->getKind() == VerifyPCHJobClass;
316 } // end namespace driver
317 } // end namespace clang