clang API Documentation

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