]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/clang/include/clang/Driver/Compilation.h
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / clang / include / clang / Driver / Compilation.h
1 //===--- Compilation.h - Compilation Task Data Structure --------*- 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_COMPILATION_H_
11 #define CLANG_DRIVER_COMPILATION_H_
12
13 #include "clang/Driver/Job.h"
14 #include "clang/Driver/Util.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/Support/Path.h"
17
18 namespace llvm {
19 namespace opt {
20   class DerivedArgList;
21   class InputArgList;
22 }
23 }
24
25 namespace clang {
26 namespace driver {
27   class Driver;
28   class JobAction;
29   class JobList;
30   class ToolChain;
31
32 /// Compilation - A set of tasks to perform for a single driver
33 /// invocation.
34 class Compilation {
35   /// The driver we were created by.
36   const Driver &TheDriver;
37
38   /// The default tool chain.
39   const ToolChain &DefaultToolChain;
40
41   /// The original (untranslated) input argument list.
42   llvm::opt::InputArgList *Args;
43
44   /// The driver translated arguments. Note that toolchains may perform their
45   /// own argument translation.
46   llvm::opt::DerivedArgList *TranslatedArgs;
47
48   /// The list of actions.
49   ActionList Actions;
50
51   /// The root list of jobs.
52   JobList Jobs;
53
54   /// Cache of translated arguments for a particular tool chain and bound
55   /// architecture.
56   llvm::DenseMap<std::pair<const ToolChain *, const char *>,
57                  llvm::opt::DerivedArgList *> TCArgs;
58
59   /// Temporary files which should be removed on exit.
60   llvm::opt::ArgStringList TempFiles;
61
62   /// Result files which should be removed on failure.
63   ArgStringMap ResultFiles;
64
65   /// Result files which are generated correctly on failure, and which should
66   /// only be removed if we crash.
67   ArgStringMap FailureResultFiles;
68
69   /// Redirection for stdout, stderr, etc.
70   const StringRef **Redirects;
71
72 public:
73   Compilation(const Driver &D, const ToolChain &DefaultToolChain,
74               llvm::opt::InputArgList *Args,
75               llvm::opt::DerivedArgList *TranslatedArgs);
76   ~Compilation();
77
78   const Driver &getDriver() const { return TheDriver; }
79
80   const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
81
82   const llvm::opt::InputArgList &getInputArgs() const { return *Args; }
83
84   const llvm::opt::DerivedArgList &getArgs() const { return *TranslatedArgs; }
85
86   llvm::opt::DerivedArgList &getArgs() { return *TranslatedArgs; }
87
88   ActionList &getActions() { return Actions; }
89   const ActionList &getActions() const { return Actions; }
90
91   JobList &getJobs() { return Jobs; }
92   const JobList &getJobs() const { return Jobs; }
93
94   void addCommand(Command *C) { Jobs.addJob(C); }
95
96   const llvm::opt::ArgStringList &getTempFiles() const { return TempFiles; }
97
98   const ArgStringMap &getResultFiles() const { return ResultFiles; }
99
100   const ArgStringMap &getFailureResultFiles() const {
101     return FailureResultFiles;
102   }
103
104   /// Returns the sysroot path.
105   StringRef getSysRoot() const;
106
107   /// getArgsForToolChain - Return the derived argument list for the
108   /// tool chain \p TC (or the default tool chain, if TC is not specified).
109   ///
110   /// \param BoundArch - The bound architecture name, or 0.
111   const llvm::opt::DerivedArgList &getArgsForToolChain(const ToolChain *TC,
112                                                        const char *BoundArch);
113
114   /// addTempFile - Add a file to remove on exit, and returns its
115   /// argument.
116   const char *addTempFile(const char *Name) {
117     TempFiles.push_back(Name);
118     return Name;
119   }
120
121   /// addResultFile - Add a file to remove on failure, and returns its
122   /// argument.
123   const char *addResultFile(const char *Name, const JobAction *JA) {
124     ResultFiles[JA] = Name;
125     return Name;
126   }
127
128   /// addFailureResultFile - Add a file to remove if we crash, and returns its
129   /// argument.
130   const char *addFailureResultFile(const char *Name, const JobAction *JA) {
131     FailureResultFiles[JA] = Name;
132     return Name;
133   }
134
135   /// CleanupFile - Delete a given file.
136   ///
137   /// \param IssueErrors - Report failures as errors.
138   /// \return Whether the file was removed successfully.
139   bool CleanupFile(const char *File, bool IssueErrors = false) const;
140
141   /// CleanupFileList - Remove the files in the given list.
142   ///
143   /// \param IssueErrors - Report failures as errors.
144   /// \return Whether all files were removed successfully.
145   bool CleanupFileList(const llvm::opt::ArgStringList &Files,
146                        bool IssueErrors = false) const;
147
148   /// CleanupFileMap - Remove the files in the given map.
149   ///
150   /// \param JA - If specified, only delete the files associated with this
151   /// JobAction.  Otherwise, delete all files in the map.
152   /// \param IssueErrors - Report failures as errors.
153   /// \return Whether all files were removed successfully.
154   bool CleanupFileMap(const ArgStringMap &Files,
155                       const JobAction *JA,
156                       bool IssueErrors = false) const;
157
158   /// ExecuteCommand - Execute an actual command.
159   ///
160   /// \param FailingCommand - For non-zero results, this will be set to the
161   /// Command which failed, if any.
162   /// \return The result code of the subprocess.
163   int ExecuteCommand(const Command &C, const Command *&FailingCommand) const;
164
165   /// ExecuteJob - Execute a single job.
166   ///
167   /// \param FailingCommands - For non-zero results, this will be a vector of
168   /// failing commands and their associated result code.
169   void ExecuteJob(const Job &J,
170      SmallVectorImpl< std::pair<int, const Command *> > &FailingCommands) const;
171
172   /// initCompilationForDiagnostics - Remove stale state and suppress output
173   /// so compilation can be reexecuted to generate additional diagnostic
174   /// information (e.g., preprocessed source(s)).
175   void initCompilationForDiagnostics();
176 };
177
178 } // end namespace driver
179 } // end namespace clang
180
181 #endif