1 //===--- Compilation.h - Compilation Task Data Structure --------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef CLANG_DRIVER_COMPILATION_H_
11 #define CLANG_DRIVER_COMPILATION_H_
13 #include "clang/Driver/Job.h"
14 #include "clang/Driver/Util.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/Support/Path.h"
27 /// Compilation - A set of tasks to perform for a single driver
30 /// The driver we were created by.
31 const Driver &TheDriver;
33 /// The default tool chain.
34 const ToolChain &DefaultToolChain;
36 /// The original (untranslated) input argument list.
39 /// The driver translated arguments. Note that toolchains may perform their
40 /// own argument translation.
41 DerivedArgList *TranslatedArgs;
43 /// The list of actions.
46 /// The root list of jobs.
49 /// Cache of translated arguments for a particular tool chain and bound
51 llvm::DenseMap<std::pair<const ToolChain*, const char*>,
52 DerivedArgList*> TCArgs;
54 /// Temporary files which should be removed on exit.
55 ArgStringList TempFiles;
57 /// Result files which should be removed on failure.
58 ArgStringMap ResultFiles;
60 /// Result files which are generated correctly on failure, and which should
61 /// only be removed if we crash.
62 ArgStringMap FailureResultFiles;
64 /// Redirection for stdout, stderr, etc.
65 const llvm::sys::Path **Redirects;
68 Compilation(const Driver &D, const ToolChain &DefaultToolChain,
69 InputArgList *Args, DerivedArgList *TranslatedArgs);
72 const Driver &getDriver() const { return TheDriver; }
74 const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
76 const InputArgList &getInputArgs() const { return *Args; }
78 const DerivedArgList &getArgs() const { return *TranslatedArgs; }
80 DerivedArgList &getArgs() { return *TranslatedArgs; }
82 ActionList &getActions() { return Actions; }
83 const ActionList &getActions() const { return Actions; }
85 JobList &getJobs() { return Jobs; }
86 const JobList &getJobs() const { return Jobs; }
88 void addCommand(Command *C) { Jobs.addJob(C); }
90 const ArgStringList &getTempFiles() const { return TempFiles; }
92 const ArgStringMap &getResultFiles() const { return ResultFiles; }
94 const ArgStringMap &getFailureResultFiles() const {
95 return FailureResultFiles;
98 /// Returns the sysroot path.
99 StringRef getSysRoot() const;
101 /// getArgsForToolChain - Return the derived argument list for the
102 /// tool chain \p TC (or the default tool chain, if TC is not specified).
104 /// \param BoundArch - The bound architecture name, or 0.
105 const DerivedArgList &getArgsForToolChain(const ToolChain *TC,
106 const char *BoundArch);
108 /// addTempFile - Add a file to remove on exit, and returns its
110 const char *addTempFile(const char *Name) {
111 TempFiles.push_back(Name);
115 /// addResultFile - Add a file to remove on failure, and returns its
117 const char *addResultFile(const char *Name, const JobAction *JA) {
118 ResultFiles[JA] = Name;
122 /// addFailureResultFile - Add a file to remove if we crash, and returns its
124 const char *addFailureResultFile(const char *Name, const JobAction *JA) {
125 FailureResultFiles[JA] = Name;
129 /// CleanupFile - Delete a given file.
131 /// \param IssueErrors - Report failures as errors.
132 /// \return Whether the file was removed successfully.
133 bool CleanupFile(const char *File, bool IssueErrors = false) const;
135 /// CleanupFileList - Remove the files in the given list.
137 /// \param IssueErrors - Report failures as errors.
138 /// \return Whether all files were removed successfully.
139 bool CleanupFileList(const ArgStringList &Files,
140 bool IssueErrors = false) const;
142 /// CleanupFileMap - Remove the files in the given map.
144 /// \param JA - If specified, only delete the files associated with this
145 /// JobAction. Otherwise, delete all files in the map.
146 /// \param IssueErrors - Report failures as errors.
147 /// \return Whether all files were removed successfully.
148 bool CleanupFileMap(const ArgStringMap &Files,
150 bool IssueErrors = false) const;
152 /// PrintJob - Print one job in -### format.
154 /// \param OS - The stream to print on.
155 /// \param J - The job to print.
156 /// \param Terminator - A string to print at the end of the line.
157 /// \param Quote - Should separate arguments be quoted.
158 void PrintJob(raw_ostream &OS, const Job &J,
159 const char *Terminator, bool Quote) const;
161 /// PrintDiagnosticJob - Print one job in -### format, but with the
162 /// superfluous options removed, which are not necessary for
163 /// reproducing the crash.
165 /// \param OS - The stream to print on.
166 /// \param J - The job to print.
167 void PrintDiagnosticJob(raw_ostream &OS, const Job &J) const;
169 /// ExecuteCommand - Execute an actual command.
171 /// \param FailingCommand - For non-zero results, this will be set to the
172 /// Command which failed, if any.
173 /// \return The result code of the subprocess.
174 int ExecuteCommand(const Command &C, const Command *&FailingCommand) const;
176 /// ExecuteJob - Execute a single job.
178 /// \param FailingCommands - For non-zero results, this will be a vector of
179 /// failing commands and their associated result code.
180 void ExecuteJob(const Job &J,
181 SmallVectorImpl< std::pair<int, const Command *> > &FailingCommands) const;
183 /// initCompilationForDiagnostics - Remove stale state and suppress output
184 /// so compilation can be reexecuted to generate additional diagnostic
185 /// information (e.g., preprocessed source(s)).
186 void initCompilationForDiagnostics();
189 } // end namespace driver
190 } // end namespace clang