1 //===--- Action.cpp - Abstract compilation steps --------------------------===//
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 #include "clang/Driver/Action.h"
11 #include "llvm/Support/ErrorHandling.h"
12 #include <cassert>
13 using namespace clang::driver;
14 using namespace llvm::opt;
15 
~Action()16 Action::~Action() {
17   if (OwnsInputs) {
18     for (iterator it = begin(), ie = end(); it != ie; ++it)
19       delete *it;
20   }
21 }
22 
getClassName(ActionClass AC)23 const char *Action::getClassName(ActionClass AC) {
24   switch (AC) {
25   case InputClass: return "input";
26   case BindArchClass: return "bind-arch";
27   case PreprocessJobClass: return "preprocessor";
28   case PrecompileJobClass: return "precompiler";
29   case AnalyzeJobClass: return "analyzer";
30   case MigrateJobClass: return "migrator";
31   case CompileJobClass: return "compiler";
32   case BackendJobClass: return "backend";
33   case AssembleJobClass: return "assembler";
34   case LinkJobClass: return "linker";
35   case LipoJobClass: return "lipo";
36   case DsymutilJobClass: return "dsymutil";
37   case VerifyDebugInfoJobClass: return "verify-debug-info";
38   case VerifyPCHJobClass: return "verify-pch";
39   }
40 
41   llvm_unreachable("invalid class");
42 }
43 
anchor()44 void InputAction::anchor() {}
45 
InputAction(const Arg & _Input,types::ID _Type)46 InputAction::InputAction(const Arg &_Input, types::ID _Type)
47   : Action(InputClass, _Type), Input(_Input) {
48 }
49 
anchor()50 void BindArchAction::anchor() {}
51 
BindArchAction(std::unique_ptr<Action> Input,const char * _ArchName)52 BindArchAction::BindArchAction(std::unique_ptr<Action> Input,
53                                const char *_ArchName)
54     : Action(BindArchClass, std::move(Input)), ArchName(_ArchName) {}
55 
anchor()56 void JobAction::anchor() {}
57 
JobAction(ActionClass Kind,std::unique_ptr<Action> Input,types::ID Type)58 JobAction::JobAction(ActionClass Kind, std::unique_ptr<Action> Input,
59                      types::ID Type)
60     : Action(Kind, std::move(Input), Type) {}
61 
JobAction(ActionClass Kind,const ActionList & Inputs,types::ID Type)62 JobAction::JobAction(ActionClass Kind, const ActionList &Inputs, types::ID Type)
63   : Action(Kind, Inputs, Type) {
64 }
65 
anchor()66 void PreprocessJobAction::anchor() {}
67 
PreprocessJobAction(std::unique_ptr<Action> Input,types::ID OutputType)68 PreprocessJobAction::PreprocessJobAction(std::unique_ptr<Action> Input,
69                                          types::ID OutputType)
70     : JobAction(PreprocessJobClass, std::move(Input), OutputType) {}
71 
anchor()72 void PrecompileJobAction::anchor() {}
73 
PrecompileJobAction(std::unique_ptr<Action> Input,types::ID OutputType)74 PrecompileJobAction::PrecompileJobAction(std::unique_ptr<Action> Input,
75                                          types::ID OutputType)
76     : JobAction(PrecompileJobClass, std::move(Input), OutputType) {}
77 
anchor()78 void AnalyzeJobAction::anchor() {}
79 
AnalyzeJobAction(std::unique_ptr<Action> Input,types::ID OutputType)80 AnalyzeJobAction::AnalyzeJobAction(std::unique_ptr<Action> Input,
81                                    types::ID OutputType)
82     : JobAction(AnalyzeJobClass, std::move(Input), OutputType) {}
83 
anchor()84 void MigrateJobAction::anchor() {}
85 
MigrateJobAction(std::unique_ptr<Action> Input,types::ID OutputType)86 MigrateJobAction::MigrateJobAction(std::unique_ptr<Action> Input,
87                                    types::ID OutputType)
88     : JobAction(MigrateJobClass, std::move(Input), OutputType) {}
89 
anchor()90 void CompileJobAction::anchor() {}
91 
CompileJobAction(std::unique_ptr<Action> Input,types::ID OutputType)92 CompileJobAction::CompileJobAction(std::unique_ptr<Action> Input,
93                                    types::ID OutputType)
94     : JobAction(CompileJobClass, std::move(Input), OutputType) {}
95 
anchor()96 void BackendJobAction::anchor() {}
97 
BackendJobAction(std::unique_ptr<Action> Input,types::ID OutputType)98 BackendJobAction::BackendJobAction(std::unique_ptr<Action> Input,
99                                    types::ID OutputType)
100     : JobAction(BackendJobClass, std::move(Input), OutputType) {}
101 
anchor()102 void AssembleJobAction::anchor() {}
103 
AssembleJobAction(std::unique_ptr<Action> Input,types::ID OutputType)104 AssembleJobAction::AssembleJobAction(std::unique_ptr<Action> Input,
105                                      types::ID OutputType)
106     : JobAction(AssembleJobClass, std::move(Input), OutputType) {}
107 
anchor()108 void LinkJobAction::anchor() {}
109 
LinkJobAction(ActionList & Inputs,types::ID Type)110 LinkJobAction::LinkJobAction(ActionList &Inputs, types::ID Type)
111   : JobAction(LinkJobClass, Inputs, Type) {
112 }
113 
anchor()114 void LipoJobAction::anchor() {}
115 
LipoJobAction(ActionList & Inputs,types::ID Type)116 LipoJobAction::LipoJobAction(ActionList &Inputs, types::ID Type)
117   : JobAction(LipoJobClass, Inputs, Type) {
118 }
119 
anchor()120 void DsymutilJobAction::anchor() {}
121 
DsymutilJobAction(ActionList & Inputs,types::ID Type)122 DsymutilJobAction::DsymutilJobAction(ActionList &Inputs, types::ID Type)
123   : JobAction(DsymutilJobClass, Inputs, Type) {
124 }
125 
anchor()126 void VerifyJobAction::anchor() {}
127 
VerifyJobAction(ActionClass Kind,std::unique_ptr<Action> Input,types::ID Type)128 VerifyJobAction::VerifyJobAction(ActionClass Kind,
129                                  std::unique_ptr<Action> Input, types::ID Type)
130     : JobAction(Kind, std::move(Input), Type) {
131   assert((Kind == VerifyDebugInfoJobClass || Kind == VerifyPCHJobClass) &&
132          "ActionClass is not a valid VerifyJobAction");
133 }
134 
VerifyJobAction(ActionClass Kind,ActionList & Inputs,types::ID Type)135 VerifyJobAction::VerifyJobAction(ActionClass Kind, ActionList &Inputs,
136                                  types::ID Type)
137     : JobAction(Kind, Inputs, Type) {
138   assert((Kind == VerifyDebugInfoJobClass || Kind == VerifyPCHJobClass) &&
139            "ActionClass is not a valid VerifyJobAction");
140 }
141 
anchor()142 void VerifyDebugInfoJobAction::anchor() {}
143 
VerifyDebugInfoJobAction(std::unique_ptr<Action> Input,types::ID Type)144 VerifyDebugInfoJobAction::VerifyDebugInfoJobAction(
145     std::unique_ptr<Action> Input, types::ID Type)
146     : VerifyJobAction(VerifyDebugInfoJobClass, std::move(Input), Type) {}
147 
anchor()148 void VerifyPCHJobAction::anchor() {}
149 
VerifyPCHJobAction(std::unique_ptr<Action> Input,types::ID Type)150 VerifyPCHJobAction::VerifyPCHJobAction(std::unique_ptr<Action> Input,
151                                        types::ID Type)
152     : VerifyJobAction(VerifyPCHJobClass, std::move(Input), Type) {}
153