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