Action.h revision b43d87b0646aa04951056c7e0d1ab9a58eb09f66
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 17namespace clang { 18namespace 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. 30class Action { 31public: 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 MigrateJobClass, 43 CompileJobClass, 44 AssembleJobClass, 45 LinkJobClass, 46 LipoJobClass, 47 DsymutilJobClass, 48 VerifyJobClass, 49 50 JobClassFirst=PreprocessJobClass, 51 JobClassLast=VerifyJobClass 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 95class InputAction : public Action { 96 virtual void anchor(); 97 const Arg &Input; 98public: 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}; 107 108class BindArchAction : public Action { 109 virtual void anchor(); 110 /// The architecture to bind, or 0 if the default architecture 111 /// should be bound. 112 const char *ArchName; 113 114public: 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}; 123 124class JobAction : public Action { 125 virtual void anchor(); 126protected: 127 JobAction(ActionClass Kind, Action *Input, types::ID Type); 128 JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type); 129 130public: 131 static bool classof(const Action *A) { 132 return (A->getKind() >= JobClassFirst && 133 A->getKind() <= JobClassLast); 134 } 135}; 136 137class PreprocessJobAction : public JobAction { 138 virtual void anchor(); 139public: 140 PreprocessJobAction(Action *Input, types::ID OutputType); 141 142 static bool classof(const Action *A) { 143 return A->getKind() == PreprocessJobClass; 144 } 145}; 146 147class PrecompileJobAction : public JobAction { 148 virtual void anchor(); 149public: 150 PrecompileJobAction(Action *Input, types::ID OutputType); 151 152 static bool classof(const Action *A) { 153 return A->getKind() == PrecompileJobClass; 154 } 155}; 156 157class AnalyzeJobAction : public JobAction { 158 virtual void anchor(); 159public: 160 AnalyzeJobAction(Action *Input, types::ID OutputType); 161 162 static bool classof(const Action *A) { 163 return A->getKind() == AnalyzeJobClass; 164 } 165}; 166 167class MigrateJobAction : public JobAction { 168 virtual void anchor(); 169public: 170 MigrateJobAction(Action *Input, types::ID OutputType); 171 172 static bool classof(const Action *A) { 173 return A->getKind() == MigrateJobClass; 174 } 175}; 176 177class CompileJobAction : public JobAction { 178 virtual void anchor(); 179public: 180 CompileJobAction(Action *Input, types::ID OutputType); 181 182 static bool classof(const Action *A) { 183 return A->getKind() == CompileJobClass; 184 } 185}; 186 187class AssembleJobAction : public JobAction { 188 virtual void anchor(); 189public: 190 AssembleJobAction(Action *Input, types::ID OutputType); 191 192 static bool classof(const Action *A) { 193 return A->getKind() == AssembleJobClass; 194 } 195}; 196 197class LinkJobAction : public JobAction { 198 virtual void anchor(); 199public: 200 LinkJobAction(ActionList &Inputs, types::ID Type); 201 202 static bool classof(const Action *A) { 203 return A->getKind() == LinkJobClass; 204 } 205}; 206 207class LipoJobAction : public JobAction { 208 virtual void anchor(); 209public: 210 LipoJobAction(ActionList &Inputs, types::ID Type); 211 212 static bool classof(const Action *A) { 213 return A->getKind() == LipoJobClass; 214 } 215}; 216 217class DsymutilJobAction : public JobAction { 218 virtual void anchor(); 219public: 220 DsymutilJobAction(ActionList &Inputs, types::ID Type); 221 222 static bool classof(const Action *A) { 223 return A->getKind() == DsymutilJobClass; 224 } 225}; 226 227class VerifyJobAction : public JobAction { 228 virtual void anchor(); 229public: 230 VerifyJobAction(ActionList &Inputs, types::ID Type); 231 static bool classof(const Action *A) { 232 return A->getKind() == VerifyJobClass; 233 } 234}; 235 236} // end namespace driver 237} // end namespace clang 238 239#endif 240