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 CLANG_DRIVER_ACTION_H_
11 #define CLANG_DRIVER_ACTION_H_
13 #include "llvm/ADT/SmallVector.h"
15 #include "clang/Driver/Types.h"
16 #include "clang/Driver/Util.h"
18 #include "llvm/Support/Casting.h"
21 using llvm::cast_or_null;
23 using llvm::dyn_cast_or_null;
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.
40 typedef ActionList::size_type size_type;
41 typedef ActionList::iterator iterator;
42 typedef ActionList::const_iterator const_iterator;
56 JobClassFirst=PreprocessJobClass,
57 JobClassLast=DsymutilJobClass
60 static const char *getClassName(ActionClass AC);
65 /// The output type of this action.
70 unsigned OwnsInputs : 1;
73 Action(ActionClass _Kind, types::ID _Type)
74 : Kind(_Kind), Type(_Type), OwnsInputs(true) {}
75 Action(ActionClass _Kind, Action *Input, types::ID _Type)
76 : Kind(_Kind), Type(_Type), Inputs(&Input, &Input + 1), OwnsInputs(true) {}
77 Action(ActionClass _Kind, const ActionList &_Inputs, types::ID _Type)
78 : Kind(_Kind), Type(_Type), Inputs(_Inputs), OwnsInputs(true) {}
82 const char *getClassName() const { return Action::getClassName(getKind()); }
84 bool getOwnsInputs() { return OwnsInputs; }
85 void setOwnsInputs(bool Value) { OwnsInputs = Value; }
87 ActionClass getKind() const { return Kind; }
88 types::ID getType() const { return Type; }
90 ActionList &getInputs() { return Inputs; }
91 const ActionList &getInputs() const { return Inputs; }
93 size_type size() const { return Inputs.size(); }
95 iterator begin() { return Inputs.begin(); }
96 iterator end() { return Inputs.end(); }
97 const_iterator begin() const { return Inputs.begin(); }
98 const_iterator end() const { return Inputs.end(); }
100 static bool classof(const Action *) { return true; }
103 class InputAction : public Action {
106 InputAction(const Arg &_Input, types::ID _Type);
108 const Arg &getInputArg() const { return Input; }
110 static bool classof(const Action *A) {
111 return A->getKind() == InputClass;
113 static bool classof(const InputAction *) { return true; }
116 class BindArchAction : public Action {
117 /// The architecture to bind, or 0 if the default architecture
119 const char *ArchName;
122 BindArchAction(Action *Input, const char *_ArchName);
124 const char *getArchName() const { return ArchName; }
126 static bool classof(const Action *A) {
127 return A->getKind() == BindArchClass;
129 static bool classof(const BindArchAction *) { return true; }
132 class JobAction : public Action {
134 JobAction(ActionClass Kind, Action *Input, types::ID Type);
135 JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
138 static bool classof(const Action *A) {
139 return (A->getKind() >= JobClassFirst &&
140 A->getKind() <= JobClassLast);
142 static bool classof(const JobAction *) { return true; }
145 class PreprocessJobAction : public JobAction {
147 PreprocessJobAction(Action *Input, types::ID OutputType);
149 static bool classof(const Action *A) {
150 return A->getKind() == PreprocessJobClass;
152 static bool classof(const PreprocessJobAction *) { return true; }
155 class PrecompileJobAction : public JobAction {
157 PrecompileJobAction(Action *Input, types::ID OutputType);
159 static bool classof(const Action *A) {
160 return A->getKind() == PrecompileJobClass;
162 static bool classof(const PrecompileJobAction *) { return true; }
165 class AnalyzeJobAction : public JobAction {
167 AnalyzeJobAction(Action *Input, types::ID OutputType);
169 static bool classof(const Action *A) {
170 return A->getKind() == AnalyzeJobClass;
172 static bool classof(const AnalyzeJobAction *) { return true; }
175 class CompileJobAction : public JobAction {
177 CompileJobAction(Action *Input, types::ID OutputType);
179 static bool classof(const Action *A) {
180 return A->getKind() == CompileJobClass;
182 static bool classof(const CompileJobAction *) { return true; }
185 class AssembleJobAction : public JobAction {
187 AssembleJobAction(Action *Input, types::ID OutputType);
189 static bool classof(const Action *A) {
190 return A->getKind() == AssembleJobClass;
192 static bool classof(const AssembleJobAction *) { return true; }
195 class LinkJobAction : public JobAction {
197 LinkJobAction(ActionList &Inputs, types::ID Type);
199 static bool classof(const Action *A) {
200 return A->getKind() == LinkJobClass;
202 static bool classof(const LinkJobAction *) { return true; }
205 class LipoJobAction : public JobAction {
207 LipoJobAction(ActionList &Inputs, types::ID Type);
209 static bool classof(const Action *A) {
210 return A->getKind() == LipoJobClass;
212 static bool classof(const LipoJobAction *) { return true; }
215 class DsymutilJobAction : public JobAction {
217 DsymutilJobAction(ActionList &Inputs, types::ID Type);
219 static bool classof(const Action *A) {
220 return A->getKind() == DsymutilJobClass;
222 static bool classof(const DsymutilJobAction *) { return true; }
225 } // end namespace driver
226 } // end namespace clang