]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Driver/Action.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.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 CLANG_DRIVER_ACTION_H_
11 #define CLANG_DRIVER_ACTION_H_
12
13 #include "llvm/ADT/SmallVector.h"
14
15 #include "clang/Driver/Types.h"
16 #include "clang/Driver/Util.h"
17
18 #include "llvm/Support/Casting.h"
19 using llvm::isa;
20 using llvm::cast;
21 using llvm::cast_or_null;
22 using llvm::dyn_cast;
23 using llvm::dyn_cast_or_null;
24
25 namespace clang {
26 namespace driver {
27   class Arg;
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 class Action {
39 public:
40   typedef ActionList::size_type size_type;
41   typedef ActionList::iterator iterator;
42   typedef ActionList::const_iterator const_iterator;
43
44   enum ActionClass {
45     InputClass = 0,
46     BindArchClass,
47     PreprocessJobClass,
48     PrecompileJobClass,
49     AnalyzeJobClass,
50     CompileJobClass,
51     AssembleJobClass,
52     LinkJobClass,
53     LipoJobClass,
54     DsymutilJobClass,
55
56     JobClassFirst=PreprocessJobClass,
57     JobClassLast=DsymutilJobClass
58   };
59
60   static const char *getClassName(ActionClass AC);
61
62 private:
63   ActionClass Kind;
64
65   /// The output type of this action.
66   types::ID Type;
67
68   ActionList Inputs;
69
70   unsigned OwnsInputs : 1;
71
72 protected:
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) {}
79 public:
80   virtual ~Action();
81
82   const char *getClassName() const { return Action::getClassName(getKind()); }
83
84   bool getOwnsInputs() { return OwnsInputs; }
85   void setOwnsInputs(bool Value) { OwnsInputs = Value; }
86
87   ActionClass getKind() const { return Kind; }
88   types::ID getType() const { return Type; }
89
90   ActionList &getInputs() { return Inputs; }
91   const ActionList &getInputs() const { return Inputs; }
92
93   size_type size() const { return Inputs.size(); }
94
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(); }
99
100   static bool classof(const Action *) { return true; }
101 };
102
103 class InputAction : public Action {
104   const Arg &Input;
105 public:
106   InputAction(const Arg &_Input, types::ID _Type);
107
108   const Arg &getInputArg() const { return Input; }
109
110   static bool classof(const Action *A) {
111     return A->getKind() == InputClass;
112   }
113   static bool classof(const InputAction *) { return true; }
114 };
115
116 class BindArchAction : public Action {
117   /// The architecture to bind, or 0 if the default architecture
118   /// should be bound.
119   const char *ArchName;
120
121 public:
122   BindArchAction(Action *Input, const char *_ArchName);
123
124   const char *getArchName() const { return ArchName; }
125
126   static bool classof(const Action *A) {
127     return A->getKind() == BindArchClass;
128   }
129   static bool classof(const BindArchAction *) { return true; }
130 };
131
132 class JobAction : public Action {
133 protected:
134   JobAction(ActionClass Kind, Action *Input, types::ID Type);
135   JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
136
137 public:
138   static bool classof(const Action *A) {
139     return (A->getKind() >= JobClassFirst &&
140             A->getKind() <= JobClassLast);
141   }
142   static bool classof(const JobAction *) { return true; }
143 };
144
145 class PreprocessJobAction : public JobAction {
146 public:
147   PreprocessJobAction(Action *Input, types::ID OutputType);
148
149   static bool classof(const Action *A) {
150     return A->getKind() == PreprocessJobClass;
151   }
152   static bool classof(const PreprocessJobAction *) { return true; }
153 };
154
155 class PrecompileJobAction : public JobAction {
156 public:
157   PrecompileJobAction(Action *Input, types::ID OutputType);
158
159   static bool classof(const Action *A) {
160     return A->getKind() == PrecompileJobClass;
161   }
162   static bool classof(const PrecompileJobAction *) { return true; }
163 };
164
165 class AnalyzeJobAction : public JobAction {
166 public:
167   AnalyzeJobAction(Action *Input, types::ID OutputType);
168
169   static bool classof(const Action *A) {
170     return A->getKind() == AnalyzeJobClass;
171   }
172   static bool classof(const AnalyzeJobAction *) { return true; }
173 };
174
175 class CompileJobAction : public JobAction {
176 public:
177   CompileJobAction(Action *Input, types::ID OutputType);
178
179   static bool classof(const Action *A) {
180     return A->getKind() == CompileJobClass;
181   }
182   static bool classof(const CompileJobAction *) { return true; }
183 };
184
185 class AssembleJobAction : public JobAction {
186 public:
187   AssembleJobAction(Action *Input, types::ID OutputType);
188
189   static bool classof(const Action *A) {
190     return A->getKind() == AssembleJobClass;
191   }
192   static bool classof(const AssembleJobAction *) { return true; }
193 };
194
195 class LinkJobAction : public JobAction {
196 public:
197   LinkJobAction(ActionList &Inputs, types::ID Type);
198
199   static bool classof(const Action *A) {
200     return A->getKind() == LinkJobClass;
201   }
202   static bool classof(const LinkJobAction *) { return true; }
203 };
204
205 class LipoJobAction : public JobAction {
206 public:
207   LipoJobAction(ActionList &Inputs, types::ID Type);
208
209   static bool classof(const Action *A) {
210     return A->getKind() == LipoJobClass;
211   }
212   static bool classof(const LipoJobAction *) { return true; }
213 };
214
215 class DsymutilJobAction : public JobAction {
216 public:
217   DsymutilJobAction(ActionList &Inputs, types::ID Type);
218
219   static bool classof(const Action *A) {
220     return A->getKind() == DsymutilJobClass;
221   }
222   static bool classof(const DsymutilJobAction *) { return true; }
223 };
224
225 } // end namespace driver
226 } // end namespace clang
227
228 #endif