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"
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;
73 Compilation(const Driver &D, const ToolChain &DefaultToolChain,
74 llvm::opt::InputArgList *Args,
75 llvm::opt::DerivedArgList *TranslatedArgs);
78 const Driver &getDriver() const { return TheDriver; }
80 const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
82 const llvm::opt::InputArgList &getInputArgs() const { return *Args; }
84 const llvm::opt::DerivedArgList &getArgs() const { return *TranslatedArgs; }
86 llvm::opt::DerivedArgList &getArgs() { return *TranslatedArgs; }
88 ActionList &getActions() { return Actions; }
89 const ActionList &getActions() const { return Actions; }
91 JobList &getJobs() { return Jobs; }
92 const JobList &getJobs() const { return Jobs; }
94 void addCommand(Command *C) { Jobs.addJob(C); }
96 const llvm::opt::ArgStringList &getTempFiles() const { return TempFiles; }
98 const ArgStringMap &getResultFiles() const { return ResultFiles; }
100 const ArgStringMap &getFailureResultFiles() const {
101 return FailureResultFiles;
104 /// Returns the sysroot path.
105 StringRef getSysRoot() const;
107 /// getArgsForToolChain - Return the derived argument list for the
108 /// tool chain \p TC (or the default tool chain, if TC is not specified).
110 /// \param BoundArch - The bound architecture name, or 0.
111 const llvm::opt::DerivedArgList &getArgsForToolChain(const ToolChain *TC,
112 const char *BoundArch);
114 /// addTempFile - Add a file to remove on exit, and returns its
116 const char *addTempFile(const char *Name) {
117 TempFiles.push_back(Name);
121 /// addResultFile - Add a file to remove on failure, and returns its
123 const char *addResultFile(const char *Name, const JobAction *JA) {
124 ResultFiles[JA] = Name;
128 /// addFailureResultFile - Add a file to remove if we crash, and returns its
130 const char *addFailureResultFile(const char *Name, const JobAction *JA) {
131 FailureResultFiles[JA] = Name;
135 /// CleanupFile - Delete a given file.
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;
141 /// CleanupFileList - Remove the files in the given list.
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;
148 /// CleanupFileMap - Remove the files in the given map.
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,
156 bool IssueErrors = false) const;
158 /// ExecuteCommand - Execute an actual command.
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;
165 /// ExecuteJob - Execute a single job.
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;
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();
178 } // end namespace driver
179 } // end namespace clang