Home | History | Annotate | Download | only in Driver
      1 //===--- Job.h - Commands to Execute ----------------------------*- 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_JOB_H_
     11 #define CLANG_DRIVER_JOB_H_
     12 
     13 #include "clang/Driver/Util.h"
     14 #include "llvm/ADT/SmallVector.h"
     15 #include "clang/Basic/LLVM.h"
     16 
     17 namespace clang {
     18 namespace driver {
     19 class Command;
     20 class Tool;
     21 
     22 class Job {
     23 public:
     24   enum JobClass {
     25     CommandClass,
     26     JobListClass
     27   };
     28 
     29 private:
     30   JobClass Kind;
     31 
     32 protected:
     33   Job(JobClass _Kind) : Kind(_Kind) {}
     34 public:
     35   virtual ~Job();
     36 
     37   JobClass getKind() const { return Kind; }
     38 
     39   /// addCommand - Append a command to the current job, which must be
     40   /// either a piped job or a job list.
     41   void addCommand(Command *C);
     42 
     43   static bool classof(const Job *) { return true; }
     44 };
     45 
     46   /// Command - An executable path/name and argument vector to
     47   /// execute.
     48 class Command : public Job {
     49   virtual void anchor();
     50 
     51   /// Source - The action which caused the creation of this job.
     52   const Action &Source;
     53 
     54   /// Tool - The tool which caused the creation of this job.
     55   const Tool &Creator;
     56 
     57   /// The executable to run.
     58   const char *Executable;
     59 
     60   /// The list of program arguments (not including the implicit first
     61   /// argument, which will be the executable).
     62   ArgStringList Arguments;
     63 
     64 public:
     65   Command(const Action &_Source, const Tool &_Creator, const char *_Executable,
     66           const ArgStringList &_Arguments);
     67 
     68   /// getSource - Return the Action which caused the creation of this job.
     69   const Action &getSource() const { return Source; }
     70 
     71   /// getCreator - Return the Tool which caused the creation of this job.
     72   const Tool &getCreator() const { return Creator; }
     73 
     74   const char *getExecutable() const { return Executable; }
     75 
     76   const ArgStringList &getArguments() const { return Arguments; }
     77 
     78   static bool classof(const Job *J) {
     79     return J->getKind() == CommandClass;
     80   }
     81   static bool classof(const Command *) { return true; }
     82 };
     83 
     84   /// JobList - A sequence of jobs to perform.
     85 class JobList : public Job {
     86 public:
     87   typedef SmallVector<Job*, 4> list_type;
     88   typedef list_type::size_type size_type;
     89   typedef list_type::iterator iterator;
     90   typedef list_type::const_iterator const_iterator;
     91 
     92 private:
     93   list_type Jobs;
     94 
     95 public:
     96   JobList();
     97   virtual ~JobList();
     98 
     99   /// Add a job to the list (taking ownership).
    100   void addJob(Job *J) { Jobs.push_back(J); }
    101 
    102   /// Clear the job list.
    103   void clear();
    104 
    105   const list_type &getJobs() const { return Jobs; }
    106 
    107   size_type size() const { return Jobs.size(); }
    108   iterator begin() { return Jobs.begin(); }
    109   const_iterator begin() const { return Jobs.begin(); }
    110   iterator end() { return Jobs.end(); }
    111   const_iterator end() const { return Jobs.end(); }
    112 
    113   static bool classof(const Job *J) {
    114     return J->getKind() == JobListClass;
    115   }
    116   static bool classof(const JobList *) { return true; }
    117 };
    118 
    119 } // end namespace driver
    120 } // end namespace clang
    121 
    122 #endif
    123