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   static bool classof(const Action *) { return true; }
     95 };
     96 
     97 class InputAction : public Action {
     98   virtual void anchor();
     99   const Arg &Input;
    100 public:
    101   InputAction(const Arg &_Input, types::ID _Type);
    102 
    103   const Arg &getInputArg() const { return Input; }
    104 
    105   static bool classof(const Action *A) {
    106     return A->getKind() == InputClass;
    107   }
    108   static bool classof(const InputAction *) { return true; }
    109 };
    110 
    111 class BindArchAction : public Action {
    112   virtual void anchor();
    113   /// The architecture to bind, or 0 if the default architecture
    114   /// should be bound.
    115   const char *ArchName;
    116 
    117 public:
    118   BindArchAction(Action *Input, const char *_ArchName);
    119 
    120   const char *getArchName() const { return ArchName; }
    121 
    122   static bool classof(const Action *A) {
    123     return A->getKind() == BindArchClass;
    124   }
    125   static bool classof(const BindArchAction *) { return true; }
    126 };
    127 
    128 class JobAction : public Action {
    129   virtual void anchor();
    130 protected:
    131   JobAction(ActionClass Kind, Action *Input, types::ID Type);
    132   JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type);
    133 
    134 public:
    135   static bool classof(const Action *A) {
    136     return (A->getKind() >= JobClassFirst &&
    137             A->getKind() <= JobClassLast);
    138   }
    139   static bool classof(const JobAction *) { return true; }
    140 };
    141 
    142 class PreprocessJobAction : public JobAction {
    143   virtual void anchor();
    144 public:
    145   PreprocessJobAction(Action *Input, types::ID OutputType);
    146 
    147   static bool classof(const Action *A) {
    148     return A->getKind() == PreprocessJobClass;
    149   }
    150   static bool classof(const PreprocessJobAction *) { return true; }
    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   static bool classof(const PrecompileJobAction *) { return true; }
    162 };
    163 
    164 class AnalyzeJobAction : public JobAction {
    165   virtual void anchor();
    166 public:
    167   AnalyzeJobAction(Action *Input, types::ID OutputType);
    168 
    169   static bool classof(const Action *A) {
    170     return A->getKind() == AnalyzeJobClass;
    171   }
    172   static bool classof(const AnalyzeJobAction *) { return true; }
    173 };
    174 
    175 class MigrateJobAction : public JobAction {
    176   virtual void anchor();
    177 public:
    178   MigrateJobAction(Action *Input, types::ID OutputType);
    179 
    180   static bool classof(const Action *A) {
    181     return A->getKind() == MigrateJobClass;
    182   }
    183   static bool classof(const MigrateJobAction *) { return true; }
    184 };
    185 
    186 class CompileJobAction : public JobAction {
    187   virtual void anchor();
    188 public:
    189   CompileJobAction(Action *Input, types::ID OutputType);
    190 
    191   static bool classof(const Action *A) {
    192     return A->getKind() == CompileJobClass;
    193   }
    194   static bool classof(const CompileJobAction *) { return true; }
    195 };
    196 
    197 class AssembleJobAction : public JobAction {
    198   virtual void anchor();
    199 public:
    200   AssembleJobAction(Action *Input, types::ID OutputType);
    201 
    202   static bool classof(const Action *A) {
    203     return A->getKind() == AssembleJobClass;
    204   }
    205   static bool classof(const AssembleJobAction *) { return true; }
    206 };
    207 
    208 class LinkJobAction : public JobAction {
    209   virtual void anchor();
    210 public:
    211   LinkJobAction(ActionList &Inputs, types::ID Type);
    212 
    213   static bool classof(const Action *A) {
    214     return A->getKind() == LinkJobClass;
    215   }
    216   static bool classof(const LinkJobAction *) { return true; }
    217 };
    218 
    219 class LipoJobAction : public JobAction {
    220   virtual void anchor();
    221 public:
    222   LipoJobAction(ActionList &Inputs, types::ID Type);
    223 
    224   static bool classof(const Action *A) {
    225     return A->getKind() == LipoJobClass;
    226   }
    227   static bool classof(const LipoJobAction *) { return true; }
    228 };
    229 
    230 class DsymutilJobAction : public JobAction {
    231   virtual void anchor();
    232 public:
    233   DsymutilJobAction(ActionList &Inputs, types::ID Type);
    234 
    235   static bool classof(const Action *A) {
    236     return A->getKind() == DsymutilJobClass;
    237   }
    238   static bool classof(const DsymutilJobAction *) { return true; }
    239 };
    240 
    241 class VerifyJobAction : public JobAction {
    242   virtual void anchor();
    243 public:
    244   VerifyJobAction(ActionList &Inputs, types::ID Type);
    245   static bool classof(const Action *A) {
    246     return A->getKind() == VerifyJobClass;
    247   }
    248   static bool classof(const VerifyJobAction *) { return true; }
    249 };
    250 
    251 } // end namespace driver
    252 } // end namespace clang
    253 
    254 #endif
    255