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"
29 /// Action - Represent an abstract compilation step to perform.
31 /// An action represents an edge in the compilation graph; typically
32 /// it is a job to transform an input using some tool.
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.
39 /// Actions are usually owned by a Compilation, which creates new
40 /// actions via MakeAction().
43 typedef ActionList::size_type size_type;
44 typedef ActionList::iterator iterator;
45 typedef ActionList::const_iterator const_iterator;
62 VerifyDebugInfoJobClass,
65 JobClassFirst=PreprocessJobClass,
66 JobClassLast=VerifyPCHJobClass
69 static const char *getClassName(ActionClass AC);
74 /// The output type of this action.
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) {}
91 const char *getClassName() const { return Action::getClassName(getKind()); }
93 ActionClass getKind() const { return Kind; }
94 types::ID getType() const { return Type; }
96 ActionList &getInputs() { return Inputs; }
97 const ActionList &getInputs() const { return Inputs; }
99 size_type size() const { return Inputs.size(); }
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(); }
107 class InputAction : public Action {
108 virtual void anchor();
109 const llvm::opt::Arg &Input;
112 InputAction(const llvm::opt::Arg &Input, types::ID Type);
114 const llvm::opt::Arg &getInputArg() const { return Input; }
116 static bool classof(const Action *A) {
117 return A->getKind() == InputClass;
121 class BindArchAction : public Action {
122 virtual void anchor();
123 /// The architecture to bind, or 0 if the default architecture
125 const char *ArchName;
128 BindArchAction(Action *Input, const char *ArchName);
130 const char *getArchName() const { return ArchName; }
132 static bool classof(const Action *A) {
133 return A->getKind() == BindArchClass;
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).
146 CudaDeviceAction(Action *Input, const char *ArchName, bool AtTopLevel);
148 const char *getGpuArchName() const { return GpuArchName; }
150 /// Gets the compute_XX that corresponds to getGpuArchName().
151 const char *getComputeArchName() const;
153 bool isAtTopLevel() const { return AtTopLevel; }
155 static bool IsValidGpuArchName(llvm::StringRef ArchName);
157 static bool classof(const Action *A) {
158 return A->getKind() == CudaDeviceClass;
162 class CudaHostAction : public Action {
163 virtual void anchor();
164 ActionList DeviceActions;
167 CudaHostAction(Action *Input, const ActionList &DeviceActions);
169 const ActionList &getDeviceActions() const { return DeviceActions; }
171 static bool classof(const Action *A) { return A->getKind() == CudaHostClass; }
174 class JobAction : public Action {
175 virtual void anchor();
177 JobAction(ActionClass Kind, Action *Input, types::ID Type);
178 JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
181 static bool classof(const Action *A) {
182 return (A->getKind() >= JobClassFirst &&
183 A->getKind() <= JobClassLast);
187 class PreprocessJobAction : public JobAction {
188 void anchor() override;
190 PreprocessJobAction(Action *Input, types::ID OutputType);
192 static bool classof(const Action *A) {
193 return A->getKind() == PreprocessJobClass;
197 class PrecompileJobAction : public JobAction {
198 void anchor() override;
200 PrecompileJobAction(Action *Input, types::ID OutputType);
202 static bool classof(const Action *A) {
203 return A->getKind() == PrecompileJobClass;
207 class AnalyzeJobAction : public JobAction {
208 void anchor() override;
210 AnalyzeJobAction(Action *Input, types::ID OutputType);
212 static bool classof(const Action *A) {
213 return A->getKind() == AnalyzeJobClass;
217 class MigrateJobAction : public JobAction {
218 void anchor() override;
220 MigrateJobAction(Action *Input, types::ID OutputType);
222 static bool classof(const Action *A) {
223 return A->getKind() == MigrateJobClass;
227 class CompileJobAction : public JobAction {
228 void anchor() override;
230 CompileJobAction(Action *Input, types::ID OutputType);
232 static bool classof(const Action *A) {
233 return A->getKind() == CompileJobClass;
237 class BackendJobAction : public JobAction {
238 void anchor() override;
240 BackendJobAction(Action *Input, types::ID OutputType);
242 static bool classof(const Action *A) {
243 return A->getKind() == BackendJobClass;
247 class AssembleJobAction : public JobAction {
248 void anchor() override;
250 AssembleJobAction(Action *Input, types::ID OutputType);
252 static bool classof(const Action *A) {
253 return A->getKind() == AssembleJobClass;
257 class LinkJobAction : public JobAction {
258 void anchor() override;
260 LinkJobAction(ActionList &Inputs, types::ID Type);
262 static bool classof(const Action *A) {
263 return A->getKind() == LinkJobClass;
267 class LipoJobAction : public JobAction {
268 void anchor() override;
270 LipoJobAction(ActionList &Inputs, types::ID Type);
272 static bool classof(const Action *A) {
273 return A->getKind() == LipoJobClass;
277 class DsymutilJobAction : public JobAction {
278 void anchor() override;
280 DsymutilJobAction(ActionList &Inputs, types::ID Type);
282 static bool classof(const Action *A) {
283 return A->getKind() == DsymutilJobClass;
287 class VerifyJobAction : public JobAction {
288 void anchor() override;
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;
297 class VerifyDebugInfoJobAction : public VerifyJobAction {
298 void anchor() override;
300 VerifyDebugInfoJobAction(Action *Input, types::ID Type);
301 static bool classof(const Action *A) {
302 return A->getKind() == VerifyDebugInfoJobClass;
306 class VerifyPCHJobAction : public VerifyJobAction {
307 void anchor() override;
309 VerifyPCHJobAction(Action *Input, types::ID Type);
310 static bool classof(const Action *A) {
311 return A->getKind() == VerifyPCHJobClass;
315 } // end namespace driver
316 } // end namespace clang