Action.h revision 9594675cc1eb52a054de13c4a21e466643847480
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
19namespace clang {
20namespace 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.
32class Action {
33public:
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
56private:
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
66protected:
67  Action(ActionClass _Kind, types::ID _Type)
68    : Kind(_Kind), Type(_Type), OwnsInputs(true)  {}
69  Action(ActionClass _Kind, Action *Input, types::ID _Type)
70    : Kind(_Kind), Type(_Type), Inputs(&Input, &Input + 1), OwnsInputs(true) {}
71  Action(ActionClass _Kind, const ActionList &_Inputs, types::ID _Type)
72    : Kind(_Kind), Type(_Type), Inputs(_Inputs), OwnsInputs(true) {}
73public:
74  virtual ~Action();
75
76  const char *getClassName() const { return Action::getClassName(getKind()); }
77
78  bool getOwnsInputs() { return OwnsInputs; }
79  void setOwnsInputs(bool Value) { OwnsInputs = Value; }
80
81  ActionClass getKind() const { return Kind; }
82  types::ID getType() const { return Type; }
83
84  ActionList &getInputs() { return Inputs; }
85  const ActionList &getInputs() const { return Inputs; }
86
87  size_type size() const { return Inputs.size(); }
88
89  iterator begin() { return Inputs.begin(); }
90  iterator end() { return Inputs.end(); }
91  const_iterator begin() const { return Inputs.begin(); }
92  const_iterator end() const { return Inputs.end(); }
93
94  static bool classof(const Action *) { return true; }
95};
96
97class InputAction : public Action {
98  const Arg &Input;
99public:
100  InputAction(const Arg &_Input, types::ID _Type);
101
102  const Arg &getInputArg() const { return Input; }
103
104  static bool classof(const Action *A) {
105    return A->getKind() == InputClass;
106  }
107  static bool classof(const InputAction *) { return true; }
108};
109
110class BindArchAction : public Action {
111  /// The architecture to bind, or 0 if the default architecture
112  /// should be bound.
113  const char *ArchName;
114
115public:
116  BindArchAction(Action *Input, const char *_ArchName);
117
118  const char *getArchName() const { return ArchName; }
119
120  static bool classof(const Action *A) {
121    return A->getKind() == BindArchClass;
122  }
123  static bool classof(const BindArchAction *) { return true; }
124};
125
126class JobAction : public Action {
127protected:
128  JobAction(ActionClass Kind, Action *Input, types::ID Type);
129  JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
130
131public:
132  static bool classof(const Action *A) {
133    return (A->getKind() >= JobClassFirst &&
134            A->getKind() <= JobClassLast);
135  }
136  static bool classof(const JobAction *) { return true; }
137};
138
139class PreprocessJobAction : public JobAction {
140public:
141  PreprocessJobAction(Action *Input, types::ID OutputType);
142
143  static bool classof(const Action *A) {
144    return A->getKind() == PreprocessJobClass;
145  }
146  static bool classof(const PreprocessJobAction *) { return true; }
147};
148
149class PrecompileJobAction : public JobAction {
150public:
151  PrecompileJobAction(Action *Input, types::ID OutputType);
152
153  static bool classof(const Action *A) {
154    return A->getKind() == PrecompileJobClass;
155  }
156  static bool classof(const PrecompileJobAction *) { return true; }
157};
158
159class AnalyzeJobAction : public JobAction {
160public:
161  AnalyzeJobAction(Action *Input, types::ID OutputType);
162
163  static bool classof(const Action *A) {
164    return A->getKind() == AnalyzeJobClass;
165  }
166  static bool classof(const AnalyzeJobAction *) { return true; }
167};
168
169class CompileJobAction : public JobAction {
170public:
171  CompileJobAction(Action *Input, types::ID OutputType);
172
173  static bool classof(const Action *A) {
174    return A->getKind() == CompileJobClass;
175  }
176  static bool classof(const CompileJobAction *) { return true; }
177};
178
179class AssembleJobAction : public JobAction {
180public:
181  AssembleJobAction(Action *Input, types::ID OutputType);
182
183  static bool classof(const Action *A) {
184    return A->getKind() == AssembleJobClass;
185  }
186  static bool classof(const AssembleJobAction *) { return true; }
187};
188
189class LinkJobAction : public JobAction {
190public:
191  LinkJobAction(ActionList &Inputs, types::ID Type);
192
193  static bool classof(const Action *A) {
194    return A->getKind() == LinkJobClass;
195  }
196  static bool classof(const LinkJobAction *) { return true; }
197};
198
199class LipoJobAction : public JobAction {
200public:
201  LipoJobAction(ActionList &Inputs, types::ID Type);
202
203  static bool classof(const Action *A) {
204    return A->getKind() == LipoJobClass;
205  }
206  static bool classof(const LipoJobAction *) { return true; }
207};
208
209class DsymutilJobAction : public JobAction {
210public:
211  DsymutilJobAction(ActionList &Inputs, types::ID Type);
212
213  static bool classof(const Action *A) {
214    return A->getKind() == DsymutilJobClass;
215  }
216  static bool classof(const DsymutilJobAction *) { return true; }
217};
218
219} // end namespace driver
220} // end namespace clang
221
222#endif
223