clang API Documentation
00001 //===--- Compilation.h - Compilation Task Data Structure --------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 00010 #ifndef CLANG_DRIVER_COMPILATION_H_ 00011 #define CLANG_DRIVER_COMPILATION_H_ 00012 00013 #include "clang/Driver/Job.h" 00014 #include "clang/Driver/Util.h" 00015 #include "llvm/ADT/DenseMap.h" 00016 #include "llvm/Support/Path.h" 00017 00018 namespace clang { 00019 namespace driver { 00020 class DerivedArgList; 00021 class Driver; 00022 class InputArgList; 00023 class JobList; 00024 class ToolChain; 00025 00026 /// Compilation - A set of tasks to perform for a single driver 00027 /// invocation. 00028 class Compilation { 00029 /// The driver we were created by. 00030 const Driver &TheDriver; 00031 00032 /// The default tool chain. 00033 const ToolChain &DefaultToolChain; 00034 00035 /// The original (untranslated) input argument list. 00036 InputArgList *Args; 00037 00038 /// The driver translated arguments. Note that toolchains may perform their 00039 /// own argument translation. 00040 DerivedArgList *TranslatedArgs; 00041 00042 /// The list of actions. 00043 ActionList Actions; 00044 00045 /// The root list of jobs. 00046 JobList Jobs; 00047 00048 /// Cache of translated arguments for a particular tool chain and bound 00049 /// architecture. 00050 llvm::DenseMap<std::pair<const ToolChain*, const char*>, 00051 DerivedArgList*> TCArgs; 00052 00053 /// Temporary files which should be removed on exit. 00054 ArgStringList TempFiles; 00055 00056 /// Result files which should be removed on failure. 00057 ArgStringList ResultFiles; 00058 00059 /// Result files which are generated correctly on failure, and which should 00060 /// only be removed if we crash. 00061 ArgStringList FailureResultFiles; 00062 00063 /// Redirection for stdout, stderr, etc. 00064 const llvm::sys::Path **Redirects; 00065 00066 public: 00067 Compilation(const Driver &D, const ToolChain &DefaultToolChain, 00068 InputArgList *Args, DerivedArgList *TranslatedArgs); 00069 ~Compilation(); 00070 00071 const Driver &getDriver() const { return TheDriver; } 00072 00073 const ToolChain &getDefaultToolChain() const { return DefaultToolChain; } 00074 00075 const InputArgList &getInputArgs() const { return *Args; } 00076 00077 const DerivedArgList &getArgs() const { return *TranslatedArgs; } 00078 00079 ActionList &getActions() { return Actions; } 00080 const ActionList &getActions() const { return Actions; } 00081 00082 JobList &getJobs() { return Jobs; } 00083 const JobList &getJobs() const { return Jobs; } 00084 00085 void addCommand(Command *C) { Jobs.addJob(C); } 00086 00087 const ArgStringList &getTempFiles() const { return TempFiles; } 00088 00089 const ArgStringList &getResultFiles() const { return ResultFiles; } 00090 00091 const ArgStringList &getFailureResultFiles() const { 00092 return FailureResultFiles; 00093 } 00094 00095 /// Returns the sysroot path. 00096 StringRef getSysRoot() const; 00097 00098 /// getArgsForToolChain - Return the derived argument list for the 00099 /// tool chain \arg TC (or the default tool chain, if TC is not 00100 /// specified). 00101 /// 00102 /// \param BoundArch - The bound architecture name, or 0. 00103 const DerivedArgList &getArgsForToolChain(const ToolChain *TC, 00104 const char *BoundArch); 00105 00106 /// addTempFile - Add a file to remove on exit, and returns its 00107 /// argument. 00108 const char *addTempFile(const char *Name) { 00109 TempFiles.push_back(Name); 00110 return Name; 00111 } 00112 00113 /// addResultFile - Add a file to remove on failure, and returns its 00114 /// argument. 00115 const char *addResultFile(const char *Name) { 00116 ResultFiles.push_back(Name); 00117 return Name; 00118 } 00119 00120 /// addFailureResultFile - Add a file to remove if we crash, and returns its 00121 /// argument. 00122 const char *addFailureResultFile(const char *Name) { 00123 FailureResultFiles.push_back(Name); 00124 return Name; 00125 } 00126 00127 /// CleanupFileList - Remove the files in the given list. 00128 /// 00129 /// \param IssueErrors - Report failures as errors. 00130 /// \return Whether all files were removed successfully. 00131 bool CleanupFileList(const ArgStringList &Files, 00132 bool IssueErrors=false) const; 00133 00134 /// PrintJob - Print one job in -### format. 00135 /// 00136 /// \param OS - The stream to print on. 00137 /// \param J - The job to print. 00138 /// \param Terminator - A string to print at the end of the line. 00139 /// \param Quote - Should separate arguments be quoted. 00140 void PrintJob(raw_ostream &OS, const Job &J, 00141 const char *Terminator, bool Quote) const; 00142 00143 /// ExecuteCommand - Execute an actual command. 00144 /// 00145 /// \param FailingCommand - For non-zero results, this will be set to the 00146 /// Command which failed, if any. 00147 /// \return The result code of the subprocess. 00148 int ExecuteCommand(const Command &C, const Command *&FailingCommand) const; 00149 00150 /// ExecuteJob - Execute a single job. 00151 /// 00152 /// \param FailingCommand - For non-zero results, this will be set to the 00153 /// Command which failed. 00154 /// \return The accumulated result code of the job. 00155 int ExecuteJob(const Job &J, const Command *&FailingCommand) const; 00156 00157 /// initCompilationForDiagnostics - Remove stale state and suppress output 00158 /// so compilation can be reexecuted to generate additional diagnostic 00159 /// information (e.g., preprocessed source(s)). 00160 void initCompilationForDiagnostics(); 00161 }; 00162 00163 } // end namespace driver 00164 } // end namespace clang 00165 00166 #endif