]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/tools/clang/include/clang/Driver/Action.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.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 "clang/Driver/Types.h"
14 #include "clang/Driver/Util.h"
15 #include "llvm/ADT/SmallVector.h"
16
17 namespace clang {
18 namespace driver {
19   class Arg;
20
21 /// Action - Represent an abstract compilation step to perform.
22 ///
23 /// An action represents an edge in the compilation graph; typically
24 /// it is a job to transform an input using some tool.
25 ///
26 /// The current driver is hard wired to expect actions which produce a
27 /// single primary output, at least in terms of controlling the
28 /// compilation. Actions can produce auxiliary files, but can only
29 /// produce a single output to feed into subsequent actions.
30 class Action {
31 public:
32   typedef ActionList::size_type size_type;
33   typedef ActionList::iterator iterator;
34   typedef ActionList::const_iterator const_iterator;
35
36   enum ActionClass {
37     InputClass = 0,
38     BindArchClass,
39     PreprocessJobClass,
40     PrecompileJobClass,
41     AnalyzeJobClass,
42     CompileJobClass,
43     AssembleJobClass,
44     LinkJobClass,
45     LipoJobClass,
46     DsymutilJobClass,
47     VerifyJobClass,
48
49     JobClassFirst=PreprocessJobClass,
50     JobClassLast=VerifyJobClass
51   };
52
53   static const char *getClassName(ActionClass AC);
54
55 private:
56   ActionClass Kind;
57
58   /// The output type of this action.
59   types::ID Type;
60
61   ActionList Inputs;
62
63   unsigned OwnsInputs : 1;
64
65 protected:
66   Action(ActionClass _Kind, types::ID _Type)
67     : Kind(_Kind), Type(_Type), OwnsInputs(true)  {}
68   Action(ActionClass _Kind, Action *Input, types::ID _Type)
69     : Kind(_Kind), Type(_Type), Inputs(&Input, &Input + 1), OwnsInputs(true) {}
70   Action(ActionClass _Kind, const ActionList &_Inputs, types::ID _Type)
71     : Kind(_Kind), Type(_Type), Inputs(_Inputs), OwnsInputs(true) {}
72 public:
73   virtual ~Action();
74
75   const char *getClassName() const { return Action::getClassName(getKind()); }
76
77   bool getOwnsInputs() { return OwnsInputs; }
78   void setOwnsInputs(bool Value) { OwnsInputs = Value; }
79
80   ActionClass getKind() const { return Kind; }
81   types::ID getType() const { return Type; }
82
83   ActionList &getInputs() { return Inputs; }
84   const ActionList &getInputs() const { return Inputs; }
85
86   size_type size() const { return Inputs.size(); }
87
88   iterator begin() { return Inputs.begin(); }
89   iterator end() { return Inputs.end(); }
90   const_iterator begin() const { return Inputs.begin(); }
91   const_iterator end() const { return Inputs.end(); }
92
93   static bool classof(const Action *) { return true; }
94 };
95
96 class InputAction : public Action {
97   const Arg &Input;
98 public:
99   InputAction(const Arg &_Input, types::ID _Type);
100
101   const Arg &getInputArg() const { return Input; }
102
103   static bool classof(const Action *A) {
104     return A->getKind() == InputClass;
105   }
106   static bool classof(const InputAction *) { return true; }
107 };
108
109 class BindArchAction : public Action {
110   /// The architecture to bind, or 0 if the default architecture
111   /// should be bound.
112   const char *ArchName;
113
114 public:
115   BindArchAction(Action *Input, const char *_ArchName);
116
117   const char *getArchName() const { return ArchName; }
118
119   static bool classof(const Action *A) {
120     return A->getKind() == BindArchClass;
121   }
122   static bool classof(const BindArchAction *) { return true; }
123 };
124
125 class JobAction : public Action {
126 protected:
127   JobAction(ActionClass Kind, Action *Input, types::ID Type);
128   JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
129
130 public:
131   static bool classof(const Action *A) {
132     return (A->getKind() >= JobClassFirst &&
133             A->getKind() <= JobClassLast);
134   }
135   static bool classof(const JobAction *) { return true; }
136 };
137
138 class PreprocessJobAction : public JobAction {
139 public:
140   PreprocessJobAction(Action *Input, types::ID OutputType);
141
142   static bool classof(const Action *A) {
143     return A->getKind() == PreprocessJobClass;
144   }
145   static bool classof(const PreprocessJobAction *) { return true; }
146 };
147
148 class PrecompileJobAction : public JobAction {
149 public:
150   PrecompileJobAction(Action *Input, types::ID OutputType);
151
152   static bool classof(const Action *A) {
153     return A->getKind() == PrecompileJobClass;
154   }
155   static bool classof(const PrecompileJobAction *) { return true; }
156 };
157
158 class AnalyzeJobAction : public JobAction {
159 public:
160   AnalyzeJobAction(Action *Input, types::ID OutputType);
161
162   static bool classof(const Action *A) {
163     return A->getKind() == AnalyzeJobClass;
164   }
165   static bool classof(const AnalyzeJobAction *) { return true; }
166 };
167
168 class CompileJobAction : public JobAction {
169 public:
170   CompileJobAction(Action *Input, types::ID OutputType);
171
172   static bool classof(const Action *A) {
173     return A->getKind() == CompileJobClass;
174   }
175   static bool classof(const CompileJobAction *) { return true; }
176 };
177
178 class AssembleJobAction : public JobAction {
179 public:
180   AssembleJobAction(Action *Input, types::ID OutputType);
181
182   static bool classof(const Action *A) {
183     return A->getKind() == AssembleJobClass;
184   }
185   static bool classof(const AssembleJobAction *) { return true; }
186 };
187
188 class LinkJobAction : public JobAction {
189 public:
190   LinkJobAction(ActionList &Inputs, types::ID Type);
191
192   static bool classof(const Action *A) {
193     return A->getKind() == LinkJobClass;
194   }
195   static bool classof(const LinkJobAction *) { return true; }
196 };
197
198 class LipoJobAction : public JobAction {
199 public:
200   LipoJobAction(ActionList &Inputs, types::ID Type);
201
202   static bool classof(const Action *A) {
203     return A->getKind() == LipoJobClass;
204   }
205   static bool classof(const LipoJobAction *) { return true; }
206 };
207
208 class DsymutilJobAction : public JobAction {
209 public:
210   DsymutilJobAction(ActionList &Inputs, types::ID Type);
211
212   static bool classof(const Action *A) {
213     return A->getKind() == DsymutilJobClass;
214   }
215   static bool classof(const DsymutilJobAction *) { return true; }
216 };
217
218 class VerifyJobAction : public JobAction {
219 public:
220   VerifyJobAction(ActionList &Inputs, types::ID Type);
221   static bool classof(const Action *A) {
222     return A->getKind() == VerifyJobClass;
223   }
224   static bool classof(const VerifyJobAction *) { return true; }
225 };
226
227 } // end namespace driver
228 } // end namespace clang
229
230 #endif