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