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"
26 /// Compilation - A set of tasks to perform for a single driver
29 /// The driver we were created by.
30 const Driver &TheDriver;
32 /// The default tool chain.
33 const ToolChain &DefaultToolChain;
35 /// The original (untranslated) input argument list.
38 /// The driver translated arguments. Note that toolchains may perform their
39 /// own argument translation.
40 DerivedArgList *TranslatedArgs;
42 /// The list of actions.
45 /// The root list of jobs.
48 /// Cache of translated arguments for a particular tool chain and bound
50 llvm::DenseMap<std::pair<const ToolChain*, const char*>,
51 DerivedArgList*> TCArgs;
53 /// Temporary files which should be removed on exit.
54 ArgStringList TempFiles;
56 /// Result files which should be removed on failure.
57 ArgStringList ResultFiles;
59 /// Result files which are generated correctly on failure, and which should
60 /// only be removed if we crash.
61 ArgStringList FailureResultFiles;
63 /// Redirection for stdout, stderr, etc.
64 const llvm::sys::Path **Redirects;
67 Compilation(const Driver &D, const ToolChain &DefaultToolChain,
68 InputArgList *Args, DerivedArgList *TranslatedArgs);
71 const Driver &getDriver() const { return TheDriver; }
73 const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
75 const InputArgList &getInputArgs() const { return *Args; }
77 const DerivedArgList &getArgs() const { return *TranslatedArgs; }
79 ActionList &getActions() { return Actions; }
80 const ActionList &getActions() const { return Actions; }
82 JobList &getJobs() { return Jobs; }
83 const JobList &getJobs() const { return Jobs; }
85 void addCommand(Command *C) { Jobs.addJob(C); }
87 const ArgStringList &getTempFiles() const { return TempFiles; }
89 const ArgStringList &getResultFiles() const { return ResultFiles; }
91 const ArgStringList &getFailureResultFiles() const {
92 return FailureResultFiles;
95 /// Returns the sysroot path.
96 StringRef getSysRoot() const;
98 /// getArgsForToolChain - Return the derived argument list for the
99 /// tool chain \arg TC (or the default tool chain, if TC is not
102 /// \param BoundArch - The bound architecture name, or 0.
103 const DerivedArgList &getArgsForToolChain(const ToolChain *TC,
104 const char *BoundArch);
106 /// addTempFile - Add a file to remove on exit, and returns its
108 const char *addTempFile(const char *Name) {
109 TempFiles.push_back(Name);
113 /// addResultFile - Add a file to remove on failure, and returns its
115 const char *addResultFile(const char *Name) {
116 ResultFiles.push_back(Name);
120 /// addFailureResultFile - Add a file to remove if we crash, and returns its
122 const char *addFailureResultFile(const char *Name) {
123 FailureResultFiles.push_back(Name);
127 /// CleanupFileList - Remove the files in the given list.
129 /// \param IssueErrors - Report failures as errors.
130 /// \return Whether all files were removed successfully.
131 bool CleanupFileList(const ArgStringList &Files,
132 bool IssueErrors=false) const;
134 /// PrintJob - Print one job in -### format.
136 /// \param OS - The stream to print on.
137 /// \param J - The job to print.
138 /// \param Terminator - A string to print at the end of the line.
139 /// \param Quote - Should separate arguments be quoted.
140 void PrintJob(raw_ostream &OS, const Job &J,
141 const char *Terminator, bool Quote) const;
143 /// ExecuteCommand - Execute an actual command.
145 /// \param FailingCommand - For non-zero results, this will be set to the
146 /// Command which failed, if any.
147 /// \return The result code of the subprocess.
148 int ExecuteCommand(const Command &C, const Command *&FailingCommand) const;
150 /// ExecuteJob - Execute a single job.
152 /// \param FailingCommand - For non-zero results, this will be set to the
153 /// Command which failed.
154 /// \return The accumulated result code of the job.
155 int ExecuteJob(const Job &J, const Command *&FailingCommand) const;
157 /// initCompilationForDiagnostics - Remove stale state and suppress output
158 /// so compilation can be reexecuted to generate additional diagnostic
159 /// information (e.g., preprocessed source(s)).
160 void initCompilationForDiagnostics();
163 } // end namespace driver
164 } // end namespace clang