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