]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - include/clang/Driver/Compilation.h
Import Clang, at r72732.
[FreeBSD/FreeBSD.git] / 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
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/SmallVector.h"
18
19 namespace llvm {
20   class raw_ostream;
21 }
22
23 namespace clang {
24 namespace driver {
25   class DerivedArgList;
26   class Driver;
27   class InputArgList;
28   class JobList;
29   class ToolChain;
30
31 /// Compilation - A set of tasks to perform for a single driver
32 /// invocation.
33 class Compilation {
34   /// The driver we were created by.
35   Driver &TheDriver;
36
37   /// The default tool chain.
38   ToolChain &DefaultToolChain;
39
40   /// The original (untranslated) input argument list.
41   InputArgList *Args;
42
43   /// The list of actions.
44   ActionList Actions;
45
46   /// The root list of jobs.
47   JobList Jobs;
48
49   /// Cache of translated arguments for a particular tool chain.
50   llvm::DenseMap<const ToolChain*, DerivedArgList*> TCArgs;
51
52   /// Temporary files which should be removed on exit.
53   ArgStringList TempFiles;
54
55   /// Result files which should be removed on failure.
56   ArgStringList ResultFiles;
57
58 public:
59   Compilation(Driver &D, ToolChain &DefaultToolChain, InputArgList *Args);
60   ~Compilation();
61
62   const Driver &getDriver() const { return TheDriver; }
63
64   const ToolChain &getDefaultToolChain() const { return DefaultToolChain; }
65
66   const InputArgList &getArgs() const { return *Args; }
67
68   ActionList &getActions() { return Actions; }
69   const ActionList &getActions() const { return Actions; }
70
71   JobList &getJobs() { return Jobs; }
72
73   /// getArgsForToolChain - Return the derived argument list for the
74   /// tool chain \arg TC (or the default tool chain, if TC is not
75   /// specified).
76   const DerivedArgList &getArgsForToolChain(const ToolChain *TC = 0);
77
78   /// addTempFile - Add a file to remove on exit, and returns its
79   /// argument.
80   const char *addTempFile(const char *Name) { 
81     TempFiles.push_back(Name); 
82     return Name;
83   }
84
85   /// addResultFile - Add a file to remove on failure, and returns its
86   /// argument.
87   const char *addResultFile(const char *Name) {
88     ResultFiles.push_back(Name);
89     return Name;
90   }
91
92   /// Execute - Execute the compilation jobs and return an
93   /// appropriate exit code.
94   int Execute() const;
95
96 private:
97   /// CleanupFileList - Remove the files in the given list.
98   ///
99   /// \param IssueErrors - Report failures as errors.
100   /// \return Whether all files were removed successfully.
101   bool CleanupFileList(const ArgStringList &Files, 
102                        bool IssueErrors=false) const;
103
104   /// PrintJob - Print one job in -### format.
105   ///
106   /// OS - The stream to print on.
107   /// J - The job to print.
108   /// Terminator - A string to print at the end of the line.
109   /// Quote - Should separate arguments be quoted.
110   void PrintJob(llvm::raw_ostream &OS, const Job &J, 
111                 const char *Terminator, bool Quote) const;
112
113   /// ExecuteCommand - Execute an actual command.
114   ///
115   /// \return The result code of the subprocess.
116   int ExecuteCommand(const Command &C) const;
117
118   /// ExecuteJob - Execute a single job.
119   ///
120   /// \return The accumulated result code of the job.
121   int ExecuteJob(const Job &J) const;
122 };
123
124 } // end namespace driver
125 } // end namespace clang
126
127 #endif