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