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 /// Redirection for stdout, stderr, etc.
60 const llvm::sys::Path **Redirects;
63 Compilation(const Driver &D, const ToolChain &DefaultToolChain,
64 InputArgList *Args, DerivedArgList *TranslatedArgs);
67 const Driver &getDriver() const { return TheDriver; }
69 const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
71 const InputArgList &getInputArgs() const { return *Args; }
73 const DerivedArgList &getArgs() const { return *TranslatedArgs; }
75 ActionList &getActions() { return Actions; }
76 const ActionList &getActions() const { return Actions; }
78 JobList &getJobs() { return Jobs; }
79 const JobList &getJobs() const { return Jobs; }
81 void addCommand(Command *C) { Jobs.addJob(C); }
83 const ArgStringList &getTempFiles() const { return TempFiles; }
85 const ArgStringList &getResultFiles() const { return ResultFiles; }
87 /// getArgsForToolChain - Return the derived argument list for the
88 /// tool chain \arg TC (or the default tool chain, if TC is not
91 /// \param BoundArch - The bound architecture name, or 0.
92 const DerivedArgList &getArgsForToolChain(const ToolChain *TC,
93 const char *BoundArch);
95 /// addTempFile - Add a file to remove on exit, and returns its
97 const char *addTempFile(const char *Name) {
98 TempFiles.push_back(Name);
102 /// addResultFile - Add a file to remove on failure, and returns its
104 const char *addResultFile(const char *Name) {
105 ResultFiles.push_back(Name);
109 /// CleanupFileList - Remove the files in the given list.
111 /// \param IssueErrors - Report failures as errors.
112 /// \return Whether all files were removed successfully.
113 bool CleanupFileList(const ArgStringList &Files,
114 bool IssueErrors=false) const;
116 /// PrintJob - Print one job in -### format.
118 /// \param OS - The stream to print on.
119 /// \param J - The job to print.
120 /// \param Terminator - A string to print at the end of the line.
121 /// \param Quote - Should separate arguments be quoted.
122 void PrintJob(raw_ostream &OS, const Job &J,
123 const char *Terminator, bool Quote) const;
125 /// ExecuteCommand - Execute an actual command.
127 /// \param FailingCommand - For non-zero results, this will be set to the
128 /// Command which failed, if any.
129 /// \return The result code of the subprocess.
130 int ExecuteCommand(const Command &C, const Command *&FailingCommand) const;
132 /// ExecuteJob - Execute a single job.
134 /// \param FailingCommand - For non-zero results, this will be set to the
135 /// Command which failed.
136 /// \return The accumulated result code of the job.
137 int ExecuteJob(const Job &J, const Command *&FailingCommand) const;
139 /// initCompilationForDiagnostics - Remove stale state and suppress output
140 /// so compilation can be reexecuted to generate additional diagnostic
141 /// information (e.g., preprocessed source(s)).
142 void initCompilationForDiagnostics();
145 } // end namespace driver
146 } // end namespace clang