]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Driver/Compilation.h
MFC r234353:
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / include / clang / Driver / Compilation.h
1 //===--- Compilation.h - Compilation Task Data Structure --------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9
10 #ifndef CLANG_DRIVER_COMPILATION_H_
11 #define CLANG_DRIVER_COMPILATION_H_
12
13 #include "clang/Driver/Job.h"
14 #include "clang/Driver/Util.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/Support/Path.h"
17
18 namespace clang {
19 namespace driver {
20   class DerivedArgList;
21   class Driver;
22   class InputArgList;
23   class JobList;
24   class ToolChain;
25
26 /// Compilation - A set of tasks to perform for a single driver
27 /// invocation.
28 class Compilation {
29   /// The driver we were created by.
30   const Driver &TheDriver;
31
32   /// The default tool chain.
33   const ToolChain &DefaultToolChain;
34
35   /// The original (untranslated) input argument list.
36   InputArgList *Args;
37
38   /// The driver translated arguments. Note that toolchains may perform their
39   /// own argument translation.
40   DerivedArgList *TranslatedArgs;
41
42   /// The list of actions.
43   ActionList Actions;
44
45   /// The root list of jobs.
46   JobList Jobs;
47
48   /// Cache of translated arguments for a particular tool chain and bound
49   /// architecture.
50   llvm::DenseMap<std::pair<const ToolChain*, const char*>,
51                  DerivedArgList*> TCArgs;
52
53   /// Temporary files which should be removed on exit.
54   ArgStringList TempFiles;
55
56   /// Result files which should be removed on failure.
57   ArgStringList ResultFiles;
58
59   /// Result files which are generated correctly on failure, and which should
60   /// only be removed if we crash.
61   ArgStringList FailureResultFiles;
62
63   /// Redirection for stdout, stderr, etc.
64   const llvm::sys::Path **Redirects;
65
66 public:
67   Compilation(const Driver &D, const ToolChain &DefaultToolChain,
68               InputArgList *Args, DerivedArgList *TranslatedArgs);
69   ~Compilation();
70
71   const Driver &getDriver() const { return TheDriver; }
72
73   const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
74
75   const InputArgList &getInputArgs() const { return *Args; }
76
77   const DerivedArgList &getArgs() const { return *TranslatedArgs; }
78
79   ActionList &getActions() { return Actions; }
80   const ActionList &getActions() const { return Actions; }
81
82   JobList &getJobs() { return Jobs; }
83   const JobList &getJobs() const { return Jobs; }
84
85   void addCommand(Command *C) { Jobs.addJob(C); }
86
87   const ArgStringList &getTempFiles() const { return TempFiles; }
88
89   const ArgStringList &getResultFiles() const { return ResultFiles; }
90
91   const ArgStringList &getFailureResultFiles() const {
92     return FailureResultFiles;
93   }
94
95   /// Returns the sysroot path.
96   StringRef getSysRoot() const;
97
98   /// getArgsForToolChain - Return the derived argument list for the
99   /// tool chain \arg TC (or the default tool chain, if TC is not
100   /// specified).
101   ///
102   /// \param BoundArch - The bound architecture name, or 0.
103   const DerivedArgList &getArgsForToolChain(const ToolChain *TC,
104                                             const char *BoundArch);
105
106   /// addTempFile - Add a file to remove on exit, and returns its
107   /// argument.
108   const char *addTempFile(const char *Name) {
109     TempFiles.push_back(Name);
110     return Name;
111   }
112
113   /// addResultFile - Add a file to remove on failure, and returns its
114   /// argument.
115   const char *addResultFile(const char *Name) {
116     ResultFiles.push_back(Name);
117     return Name;
118   }
119
120   /// addFailureResultFile - Add a file to remove if we crash, and returns its
121   /// argument.
122   const char *addFailureResultFile(const char *Name) {
123     FailureResultFiles.push_back(Name);
124     return Name;
125   }
126
127   /// CleanupFileList - Remove the files in the given list.
128   ///
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;
133
134   /// PrintJob - Print one job in -### format.
135   ///
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;
142
143   /// ExecuteCommand - Execute an actual command.
144   ///
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;
149
150   /// ExecuteJob - Execute a single job.
151   ///
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;
156
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();
161 };
162
163 } // end namespace driver
164 } // end namespace clang
165
166 #endif