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"
16 #include "llvm/ADT/DenseMap.h"
30 /// Compilation - A set of tasks to perform for a single driver
33 /// The driver we were created by.
34 const Driver &TheDriver;
36 /// The default tool chain.
37 const ToolChain &DefaultToolChain;
39 /// The original (untranslated) input argument list.
42 /// The driver translated arguments. Note that toolchains may perform their
43 /// own argument translation.
44 DerivedArgList *TranslatedArgs;
46 /// The list of actions.
49 /// The root list of jobs.
52 /// Cache of translated arguments for a particular tool chain and bound
54 llvm::DenseMap<std::pair<const ToolChain*, const char*>,
55 DerivedArgList*> TCArgs;
57 /// Temporary files which should be removed on exit.
58 ArgStringList TempFiles;
60 /// Result files which should be removed on failure.
61 ArgStringList ResultFiles;
64 Compilation(const Driver &D, const ToolChain &DefaultToolChain,
65 InputArgList *Args, DerivedArgList *TranslatedArgs);
68 const Driver &getDriver() const { return TheDriver; }
70 const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
72 const InputArgList &getInputArgs() const { return *Args; }
74 const DerivedArgList &getArgs() const { return *TranslatedArgs; }
76 ActionList &getActions() { return Actions; }
77 const ActionList &getActions() const { return Actions; }
79 JobList &getJobs() { return Jobs; }
80 const JobList &getJobs() const { return Jobs; }
82 void addCommand(Command *C) { Jobs.addJob(C); }
84 const ArgStringList &getTempFiles() const { return TempFiles; }
86 const ArgStringList &getResultFiles() const { return ResultFiles; }
88 /// getArgsForToolChain - Return the derived argument list for the
89 /// tool chain \arg TC (or the default tool chain, if TC is not
92 /// \param BoundArch - The bound architecture name, or 0.
93 const DerivedArgList &getArgsForToolChain(const ToolChain *TC,
94 const char *BoundArch);
96 /// addTempFile - Add a file to remove on exit, and returns its
98 const char *addTempFile(const char *Name) {
99 TempFiles.push_back(Name);
103 /// addResultFile - Add a file to remove on failure, and returns its
105 const char *addResultFile(const char *Name) {
106 ResultFiles.push_back(Name);
110 /// CleanupFileList - Remove the files in the given list.
112 /// \param IssueErrors - Report failures as errors.
113 /// \return Whether all files were removed successfully.
114 bool CleanupFileList(const ArgStringList &Files,
115 bool IssueErrors=false) const;
117 /// PrintJob - Print one job in -### format.
119 /// \param OS - The stream to print on.
120 /// \param J - The job to print.
121 /// \param Terminator - A string to print at the end of the line.
122 /// \param Quote - Should separate arguments be quoted.
123 void PrintJob(llvm::raw_ostream &OS, const Job &J,
124 const char *Terminator, bool Quote) const;
126 /// ExecuteCommand - Execute an actual command.
128 /// \param FailingCommand - For non-zero results, this will be set to the
129 /// Command which failed, if any.
130 /// \return The result code of the subprocess.
131 int ExecuteCommand(const Command &C, const Command *&FailingCommand) const;
133 /// ExecuteJob - Execute a single job.
135 /// \param FailingCommand - For non-zero results, this will be set to the
136 /// Command which failed.
137 /// \return The accumulated result code of the job.
138 int ExecuteJob(const Job &J, const Command *&FailingCommand) const;
141 } // end namespace driver
142 } // end namespace clang