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 clang {
     18 namespace 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.
     30 class Action {
     31 public:
     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 
     56 private:
     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 
     66 protected:
     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) {}
     73 public:
     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 
     95 class InputAction : public Action {
     96   virtual void anchor();
     97   const Arg &Input;
     98 public:
     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 
    108 class 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 
    114 public:
    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 
    124 class JobAction : public Action {
    125   virtual void anchor();
    126 protected:
    127   JobAction(ActionClass Kind, Action *Input, types::ID Type);
    128   JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
    129 
    130 public:
    131   static bool classof(const Action *A) {
    132     return (A->getKind() >= JobClassFirst &&
    133             A->getKind() <= JobClassLast);
    134   }
    135 };
    136 
    137 class PreprocessJobAction : public JobAction {
    138   virtual void anchor();
    139 public:
    140   PreprocessJobAction(Action *Input, types::ID OutputType);
    141 
    142   static bool classof(const Action *A) {
    143     return A->getKind() == PreprocessJobClass;
    144   }
    145 };
    146 
    147 class PrecompileJobAction : public JobAction {
    148   virtual void anchor();
    149 public:
    150   PrecompileJobAction(Action *Input, types::ID OutputType);
    151 
    152   static bool classof(const Action *A) {
    153     return A->getKind() == PrecompileJobClass;
    154   }
    155 };
    156 
    157 class AnalyzeJobAction : public JobAction {
    158   virtual void anchor();
    159 public:
    160   AnalyzeJobAction(Action *Input, types::ID OutputType);
    161 
    162   static bool classof(const Action *A) {
    163     return A->getKind() == AnalyzeJobClass;
    164   }
    165 };
    166 
    167 class MigrateJobAction : public JobAction {
    168   virtual void anchor();
    169 public:
    170   MigrateJobAction(Action *Input, types::ID OutputType);
    171 
    172   static bool classof(const Action *A) {
    173     return A->getKind() == MigrateJobClass;
    174   }
    175 };
    176 
    177 class CompileJobAction : public JobAction {
    178   virtual void anchor();
    179 public:
    180   CompileJobAction(Action *Input, types::ID OutputType);
    181 
    182   static bool classof(const Action *A) {
    183     return A->getKind() == CompileJobClass;
    184   }
    185 };
    186 
    187 class AssembleJobAction : public JobAction {
    188   virtual void anchor();
    189 public:
    190   AssembleJobAction(Action *Input, types::ID OutputType);
    191 
    192   static bool classof(const Action *A) {
    193     return A->getKind() == AssembleJobClass;
    194   }
    195 };
    196 
    197 class LinkJobAction : public JobAction {
    198   virtual void anchor();
    199 public:
    200   LinkJobAction(ActionList &Inputs, types::ID Type);
    201 
    202   static bool classof(const Action *A) {
    203     return A->getKind() == LinkJobClass;
    204   }
    205 };
    206 
    207 class LipoJobAction : public JobAction {
    208   virtual void anchor();
    209 public:
    210   LipoJobAction(ActionList &Inputs, types::ID Type);
    211 
    212   static bool classof(const Action *A) {
    213     return A->getKind() == LipoJobClass;
    214   }
    215 };
    216 
    217 class DsymutilJobAction : public JobAction {
    218   virtual void anchor();
    219 public:
    220   DsymutilJobAction(ActionList &Inputs, types::ID Type);
    221 
    222   static bool classof(const Action *A) {
    223     return A->getKind() == DsymutilJobClass;
    224   }
    225 };
    226 
    227 class VerifyJobAction : public JobAction {
    228   virtual void anchor();
    229 public:
    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