clang API Documentation
00001 //===--- Action.h - Abstract compilation steps ------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef CLANG_DRIVER_ACTION_H_ 00011 #define CLANG_DRIVER_ACTION_H_ 00012 00013 #include "clang/Driver/Types.h" 00014 #include "clang/Driver/Util.h" 00015 #include "llvm/ADT/SmallVector.h" 00016 00017 namespace clang { 00018 namespace driver { 00019 class Arg; 00020 00021 /// Action - Represent an abstract compilation step to perform. 00022 /// 00023 /// An action represents an edge in the compilation graph; typically 00024 /// it is a job to transform an input using some tool. 00025 /// 00026 /// The current driver is hard wired to expect actions which produce a 00027 /// single primary output, at least in terms of controlling the 00028 /// compilation. Actions can produce auxiliary files, but can only 00029 /// produce a single output to feed into subsequent actions. 00030 class Action { 00031 public: 00032 typedef ActionList::size_type size_type; 00033 typedef ActionList::iterator iterator; 00034 typedef ActionList::const_iterator const_iterator; 00035 00036 enum ActionClass { 00037 InputClass = 0, 00038 BindArchClass, 00039 PreprocessJobClass, 00040 PrecompileJobClass, 00041 AnalyzeJobClass, 00042 MigrateJobClass, 00043 CompileJobClass, 00044 AssembleJobClass, 00045 LinkJobClass, 00046 LipoJobClass, 00047 DsymutilJobClass, 00048 VerifyJobClass, 00049 00050 JobClassFirst=PreprocessJobClass, 00051 JobClassLast=VerifyJobClass 00052 }; 00053 00054 static const char *getClassName(ActionClass AC); 00055 00056 private: 00057 ActionClass Kind; 00058 00059 /// The output type of this action. 00060 types::ID Type; 00061 00062 ActionList Inputs; 00063 00064 unsigned OwnsInputs : 1; 00065 00066 protected: 00067 Action(ActionClass _Kind, types::ID _Type) 00068 : Kind(_Kind), Type(_Type), OwnsInputs(true) {} 00069 Action(ActionClass _Kind, Action *Input, types::ID _Type) 00070 : Kind(_Kind), Type(_Type), Inputs(&Input, &Input + 1), OwnsInputs(true) {} 00071 Action(ActionClass _Kind, const ActionList &_Inputs, types::ID _Type) 00072 : Kind(_Kind), Type(_Type), Inputs(_Inputs), OwnsInputs(true) {} 00073 public: 00074 virtual ~Action(); 00075 00076 const char *getClassName() const { return Action::getClassName(getKind()); } 00077 00078 bool getOwnsInputs() { return OwnsInputs; } 00079 void setOwnsInputs(bool Value) { OwnsInputs = Value; } 00080 00081 ActionClass getKind() const { return Kind; } 00082 types::ID getType() const { return Type; } 00083 00084 ActionList &getInputs() { return Inputs; } 00085 const ActionList &getInputs() const { return Inputs; } 00086 00087 size_type size() const { return Inputs.size(); } 00088 00089 iterator begin() { return Inputs.begin(); } 00090 iterator end() { return Inputs.end(); } 00091 const_iterator begin() const { return Inputs.begin(); } 00092 const_iterator end() const { return Inputs.end(); } 00093 00094 static bool classof(const Action *) { return true; } 00095 }; 00096 00097 class InputAction : public Action { 00098 virtual void anchor(); 00099 const Arg &Input; 00100 public: 00101 InputAction(const Arg &_Input, types::ID _Type); 00102 00103 const Arg &getInputArg() const { return Input; } 00104 00105 static bool classof(const Action *A) { 00106 return A->getKind() == InputClass; 00107 } 00108 static bool classof(const InputAction *) { return true; } 00109 }; 00110 00111 class BindArchAction : public Action { 00112 virtual void anchor(); 00113 /// The architecture to bind, or 0 if the default architecture 00114 /// should be bound. 00115 const char *ArchName; 00116 00117 public: 00118 BindArchAction(Action *Input, const char *_ArchName); 00119 00120 const char *getArchName() const { return ArchName; } 00121 00122 static bool classof(const Action *A) { 00123 return A->getKind() == BindArchClass; 00124 } 00125 static bool classof(const BindArchAction *) { return true; } 00126 }; 00127 00128 class JobAction : public Action { 00129 virtual void anchor(); 00130 protected: 00131 JobAction(ActionClass Kind, Action *Input, types::ID Type); 00132 JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type); 00133 00134 public: 00135 static bool classof(const Action *A) { 00136 return (A->getKind() >= JobClassFirst && 00137 A->getKind() <= JobClassLast); 00138 } 00139 static bool classof(const JobAction *) { return true; } 00140 }; 00141 00142 class PreprocessJobAction : public JobAction { 00143 virtual void anchor(); 00144 public: 00145 PreprocessJobAction(Action *Input, types::ID OutputType); 00146 00147 static bool classof(const Action *A) { 00148 return A->getKind() == PreprocessJobClass; 00149 } 00150 static bool classof(const PreprocessJobAction *) { return true; } 00151 }; 00152 00153 class PrecompileJobAction : public JobAction { 00154 virtual void anchor(); 00155 public: 00156 PrecompileJobAction(Action *Input, types::ID OutputType); 00157 00158 static bool classof(const Action *A) { 00159 return A->getKind() == PrecompileJobClass; 00160 } 00161 static bool classof(const PrecompileJobAction *) { return true; } 00162 }; 00163 00164 class AnalyzeJobAction : public JobAction { 00165 virtual void anchor(); 00166 public: 00167 AnalyzeJobAction(Action *Input, types::ID OutputType); 00168 00169 static bool classof(const Action *A) { 00170 return A->getKind() == AnalyzeJobClass; 00171 } 00172 static bool classof(const AnalyzeJobAction *) { return true; } 00173 }; 00174 00175 class MigrateJobAction : public JobAction { 00176 virtual void anchor(); 00177 public: 00178 MigrateJobAction(Action *Input, types::ID OutputType); 00179 00180 static bool classof(const Action *A) { 00181 return A->getKind() == MigrateJobClass; 00182 } 00183 static bool classof(const MigrateJobAction *) { return true; } 00184 }; 00185 00186 class CompileJobAction : public JobAction { 00187 virtual void anchor(); 00188 public: 00189 CompileJobAction(Action *Input, types::ID OutputType); 00190 00191 static bool classof(const Action *A) { 00192 return A->getKind() == CompileJobClass; 00193 } 00194 static bool classof(const CompileJobAction *) { return true; } 00195 }; 00196 00197 class AssembleJobAction : public JobAction { 00198 virtual void anchor(); 00199 public: 00200 AssembleJobAction(Action *Input, types::ID OutputType); 00201 00202 static bool classof(const Action *A) { 00203 return A->getKind() == AssembleJobClass; 00204 } 00205 static bool classof(const AssembleJobAction *) { return true; } 00206 }; 00207 00208 class LinkJobAction : public JobAction { 00209 virtual void anchor(); 00210 public: 00211 LinkJobAction(ActionList &Inputs, types::ID Type); 00212 00213 static bool classof(const Action *A) { 00214 return A->getKind() == LinkJobClass; 00215 } 00216 static bool classof(const LinkJobAction *) { return true; } 00217 }; 00218 00219 class LipoJobAction : public JobAction { 00220 virtual void anchor(); 00221 public: 00222 LipoJobAction(ActionList &Inputs, types::ID Type); 00223 00224 static bool classof(const Action *A) { 00225 return A->getKind() == LipoJobClass; 00226 } 00227 static bool classof(const LipoJobAction *) { return true; } 00228 }; 00229 00230 class DsymutilJobAction : public JobAction { 00231 virtual void anchor(); 00232 public: 00233 DsymutilJobAction(ActionList &Inputs, types::ID Type); 00234 00235 static bool classof(const Action *A) { 00236 return A->getKind() == DsymutilJobClass; 00237 } 00238 static bool classof(const DsymutilJobAction *) { return true; } 00239 }; 00240 00241 class VerifyJobAction : public JobAction { 00242 virtual void anchor(); 00243 public: 00244 VerifyJobAction(ActionList &Inputs, types::ID Type); 00245 static bool classof(const Action *A) { 00246 return A->getKind() == VerifyJobClass; 00247 } 00248 static bool classof(const VerifyJobAction *) { return true; } 00249 }; 00250 00251 } // end namespace driver 00252 } // end namespace clang 00253 00254 #endif