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