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