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 LLVM_CLANG_DRIVER_COMPILATION_H
11 #define LLVM_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"
32 /// Compilation - A set of tasks to perform for a single driver
35 /// The driver we were created by.
36 const Driver &TheDriver;
38 /// The default tool chain.
39 const ToolChain &DefaultToolChain;
41 /// The original (untranslated) input argument list.
42 llvm::opt::InputArgList *Args;
44 /// The driver translated arguments. Note that toolchains may perform their
45 /// own argument translation.
46 llvm::opt::DerivedArgList *TranslatedArgs;
48 /// The list of actions.
51 /// The root list of jobs.
54 /// Cache of translated arguments for a particular tool chain and bound
56 llvm::DenseMap<std::pair<const ToolChain *, const char *>,
57 llvm::opt::DerivedArgList *> TCArgs;
59 /// Temporary files which should be removed on exit.
60 llvm::opt::ArgStringList TempFiles;
62 /// Result files which should be removed on failure.
63 ArgStringMap ResultFiles;
65 /// Result files which are generated correctly on failure, and which should
66 /// only be removed if we crash.
67 ArgStringMap FailureResultFiles;
69 /// Redirection for stdout, stderr, etc.
70 const StringRef **Redirects;
72 /// Whether we're compiling for diagnostic purposes.
76 Compilation(const Driver &D, const ToolChain &DefaultToolChain,
77 llvm::opt::InputArgList *Args,
78 llvm::opt::DerivedArgList *TranslatedArgs);
81 const Driver &getDriver() const { return TheDriver; }
83 const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
85 const llvm::opt::InputArgList &getInputArgs() const { return *Args; }
87 const llvm::opt::DerivedArgList &getArgs() const { return *TranslatedArgs; }
89 llvm::opt::DerivedArgList &getArgs() { return *TranslatedArgs; }
91 ActionList &getActions() { return Actions; }
92 const ActionList &getActions() const { return Actions; }
94 JobList &getJobs() { return Jobs; }
95 const JobList &getJobs() const { return Jobs; }
97 void addCommand(std::unique_ptr<Command> C) { Jobs.addJob(std::move(C)); }
99 const llvm::opt::ArgStringList &getTempFiles() const { return TempFiles; }
101 const ArgStringMap &getResultFiles() const { return ResultFiles; }
103 const ArgStringMap &getFailureResultFiles() const {
104 return FailureResultFiles;
107 /// Returns the sysroot path.
108 StringRef getSysRoot() const;
110 /// getArgsForToolChain - Return the derived argument list for the
111 /// tool chain \p TC (or the default tool chain, if TC is not specified).
113 /// \param BoundArch - The bound architecture name, or 0.
114 const llvm::opt::DerivedArgList &getArgsForToolChain(const ToolChain *TC,
115 const char *BoundArch);
117 /// addTempFile - Add a file to remove on exit, and returns its
119 const char *addTempFile(const char *Name) {
120 TempFiles.push_back(Name);
124 /// addResultFile - Add a file to remove on failure, and returns its
126 const char *addResultFile(const char *Name, const JobAction *JA) {
127 ResultFiles[JA] = Name;
131 /// addFailureResultFile - Add a file to remove if we crash, and returns its
133 const char *addFailureResultFile(const char *Name, const JobAction *JA) {
134 FailureResultFiles[JA] = Name;
138 /// CleanupFile - Delete a given file.
140 /// \param IssueErrors - Report failures as errors.
141 /// \return Whether the file was removed successfully.
142 bool CleanupFile(const char *File, bool IssueErrors = false) const;
144 /// CleanupFileList - Remove the files in the given list.
146 /// \param IssueErrors - Report failures as errors.
147 /// \return Whether all files were removed successfully.
148 bool CleanupFileList(const llvm::opt::ArgStringList &Files,
149 bool IssueErrors = false) const;
151 /// CleanupFileMap - Remove the files in the given map.
153 /// \param JA - If specified, only delete the files associated with this
154 /// JobAction. Otherwise, delete all files in the map.
155 /// \param IssueErrors - Report failures as errors.
156 /// \return Whether all files were removed successfully.
157 bool CleanupFileMap(const ArgStringMap &Files,
159 bool IssueErrors = false) const;
161 /// ExecuteCommand - Execute an actual command.
163 /// \param FailingCommand - For non-zero results, this will be set to the
164 /// Command which failed, if any.
165 /// \return The result code of the subprocess.
166 int ExecuteCommand(const Command &C, const Command *&FailingCommand) const;
168 /// ExecuteJob - Execute a single job.
170 /// \param FailingCommands - For non-zero results, this will be a vector of
171 /// failing commands and their associated result code.
174 SmallVectorImpl<std::pair<int, const Command *>> &FailingCommands) const;
176 /// initCompilationForDiagnostics - Remove stale state and suppress output
177 /// so compilation can be reexecuted to generate additional diagnostic
178 /// information (e.g., preprocessed source(s)).
179 void initCompilationForDiagnostics();
181 /// Return true if we're compiling for diagnostics.
182 bool isForDiagnostics() { return ForDiagnostics; }
185 } // end namespace driver
186 } // end namespace clang