• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
getDriver()71   const Driver &getDriver() const { return TheDriver; }
72 
getDefaultToolChain()73   const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
74 
getInputArgs()75   const InputArgList &getInputArgs() const { return *Args; }
76 
getArgs()77   const DerivedArgList &getArgs() const { return *TranslatedArgs; }
78 
getArgs()79   DerivedArgList &getArgs() { return *TranslatedArgs; }
80 
getActions()81   ActionList &getActions() { return Actions; }
getActions()82   const ActionList &getActions() const { return Actions; }
83 
getJobs()84   JobList &getJobs() { return Jobs; }
getJobs()85   const JobList &getJobs() const { return Jobs; }
86 
addCommand(Command * C)87   void addCommand(Command *C) { Jobs.addJob(C); }
88 
getTempFiles()89   const ArgStringList &getTempFiles() const { return TempFiles; }
90 
getResultFiles()91   const ArgStringList &getResultFiles() const { return ResultFiles; }
92 
getFailureResultFiles()93   const ArgStringList &getFailureResultFiles() const {
94     return FailureResultFiles;
95   }
96 
97   /// Returns the sysroot path.
98   StringRef getSysRoot() const;
99 
100   /// getArgsForToolChain - Return the derived argument list for the
101   /// tool chain \arg TC (or the default tool chain, if TC is not
102   /// specified).
103   ///
104   /// \param BoundArch - The bound architecture name, or 0.
105   const DerivedArgList &getArgsForToolChain(const ToolChain *TC,
106                                             const char *BoundArch);
107 
108   /// addTempFile - Add a file to remove on exit, and returns its
109   /// argument.
addTempFile(const char * Name)110   const char *addTempFile(const char *Name) {
111     TempFiles.push_back(Name);
112     return Name;
113   }
114 
115   /// addResultFile - Add a file to remove on failure, and returns its
116   /// argument.
addResultFile(const char * Name)117   const char *addResultFile(const char *Name) {
118     ResultFiles.push_back(Name);
119     return Name;
120   }
121 
122   /// addFailureResultFile - Add a file to remove if we crash, and returns its
123   /// argument.
addFailureResultFile(const char * Name)124   const char *addFailureResultFile(const char *Name) {
125     FailureResultFiles.push_back(Name);
126     return Name;
127   }
128 
129   /// CleanupFileList - Remove the files in the given list.
130   ///
131   /// \param IssueErrors - Report failures as errors.
132   /// \return Whether all files were removed successfully.
133   bool CleanupFileList(const ArgStringList &Files,
134                        bool IssueErrors=false) const;
135 
136   /// PrintJob - Print one job in -### format.
137   ///
138   /// \param OS - The stream to print on.
139   /// \param J - The job to print.
140   /// \param Terminator - A string to print at the end of the line.
141   /// \param Quote - Should separate arguments be quoted.
142   void PrintJob(raw_ostream &OS, const Job &J,
143                 const char *Terminator, bool Quote) const;
144 
145   /// ExecuteCommand - Execute an actual command.
146   ///
147   /// \param FailingCommand - For non-zero results, this will be set to the
148   /// Command which failed, if any.
149   /// \return The result code of the subprocess.
150   int ExecuteCommand(const Command &C, const Command *&FailingCommand) const;
151 
152   /// ExecuteJob - Execute a single job.
153   ///
154   /// \param FailingCommand - For non-zero results, this will be set to the
155   /// Command which failed.
156   /// \return The accumulated result code of the job.
157   int ExecuteJob(const Job &J, const Command *&FailingCommand) const;
158 
159   /// initCompilationForDiagnostics - Remove stale state and suppress output
160   /// so compilation can be reexecuted to generate additional diagnostic
161   /// information (e.g., preprocessed source(s)).
162   void initCompilationForDiagnostics();
163 };
164 
165 } // end namespace driver
166 } // end namespace clang
167 
168 #endif
169