Job.h revision 1eb4433ac451dc16f4133a88af2d002ac26c58ef
1789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar//===--- Job.h - Commands to Execute ----------------------------*- C++ -*-===// 2789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar// 3789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar// The LLVM Compiler Infrastructure 4789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar// 5789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar// This file is distributed under the University of Illinois Open Source 6789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar// License. See LICENSE.TXT for details. 7789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar// 8789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar//===----------------------------------------------------------------------===// 9789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 10789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar#ifndef CLANG_DRIVER_JOB_H_ 11789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar#define CLANG_DRIVER_JOB_H_ 12789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 13789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar#include "clang/Driver/Util.h" 14789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar#include "llvm/ADT/SmallVector.h" 15789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 16a1ead48a4e9961c7eb22592310c7e9c30cb56794Daniel Dunbar#include "llvm/Support/Casting.h" 17a1ead48a4e9961c7eb22592310c7e9c30cb56794Daniel Dunbarusing llvm::isa; 18a1ead48a4e9961c7eb22592310c7e9c30cb56794Daniel Dunbarusing llvm::cast; 19a1ead48a4e9961c7eb22592310c7e9c30cb56794Daniel Dunbarusing llvm::cast_or_null; 20a1ead48a4e9961c7eb22592310c7e9c30cb56794Daniel Dunbarusing llvm::dyn_cast; 21a1ead48a4e9961c7eb22592310c7e9c30cb56794Daniel Dunbarusing llvm::dyn_cast_or_null; 22a1ead48a4e9961c7eb22592310c7e9c30cb56794Daniel Dunbar 23789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarnamespace clang { 24789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarnamespace driver { 25871adcf4e41285e3f4c3b62eaa1b2e05b60b92daDaniel Dunbar class Command; 26789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 27789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarclass Job { 28789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarpublic: 29789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar enum JobClass { 30789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar CommandClass, 31789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar PipedJobClass, 32789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar JobListClass 33789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar }; 34789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 35789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarprivate: 36789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar JobClass Kind; 37789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 38789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarprotected: 39789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar Job(JobClass _Kind) : Kind(_Kind) {} 40789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarpublic: 41789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar virtual ~Job(); 42789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 43789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar JobClass getKind() const { return Kind; } 44789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 45871adcf4e41285e3f4c3b62eaa1b2e05b60b92daDaniel Dunbar /// addCommand - Append a command to the current job, which must be 46871adcf4e41285e3f4c3b62eaa1b2e05b60b92daDaniel Dunbar /// either a piped job or a job list. 47871adcf4e41285e3f4c3b62eaa1b2e05b60b92daDaniel Dunbar void addCommand(Command *C); 48871adcf4e41285e3f4c3b62eaa1b2e05b60b92daDaniel Dunbar 491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Job *) { return true; } 50789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar}; 51789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 52789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar /// Command - An executable path/name and argument vector to 53789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar /// execute. 54789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarclass Command : public Job { 55cae087e164e94e4286c11bf694dd0ff88f295302Daniel Dunbar /// Source - The action which caused the creation of this job. 56cae087e164e94e4286c11bf694dd0ff88f295302Daniel Dunbar const Action &Source; 57cae087e164e94e4286c11bf694dd0ff88f295302Daniel Dunbar 58d57ac5990d22592665a67a28fc5d39f1155424d3Daniel Dunbar /// The executable to run. 59789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar const char *Executable; 60d57ac5990d22592665a67a28fc5d39f1155424d3Daniel Dunbar 61d57ac5990d22592665a67a28fc5d39f1155424d3Daniel Dunbar /// The list of program arguments (not including the implicit first 62d57ac5990d22592665a67a28fc5d39f1155424d3Daniel Dunbar /// argument, which will be the executable). 63d57ac5990d22592665a67a28fc5d39f1155424d3Daniel Dunbar ArgStringList Arguments; 64789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 65789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarpublic: 661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Command(const Action &_Source, const char *_Executable, 67cae087e164e94e4286c11bf694dd0ff88f295302Daniel Dunbar const ArgStringList &_Arguments); 68cae087e164e94e4286c11bf694dd0ff88f295302Daniel Dunbar 69cae087e164e94e4286c11bf694dd0ff88f295302Daniel Dunbar /// getSource - Return the Action which caused the creation of this job. 70cae087e164e94e4286c11bf694dd0ff88f295302Daniel Dunbar const Action &getSource() const { return Source; } 71789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 72789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar const char *getExecutable() const { return Executable; } 73cae087e164e94e4286c11bf694dd0ff88f295302Daniel Dunbar 74d57ac5990d22592665a67a28fc5d39f1155424d3Daniel Dunbar const ArgStringList &getArguments() const { return Arguments; } 75789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Job *J) { 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return J->getKind() == CommandClass; 78789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar } 79789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar static bool classof(const Command *) { return true; } 80789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar}; 81789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 82789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar /// PipedJob - A list of Commands which should be executed together 83789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar /// with their standard inputs and outputs connected. 84789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarclass PipedJob : public Job { 85789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarpublic: 86789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar typedef llvm::SmallVector<Command*, 4> list_type; 87cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar typedef list_type::size_type size_type; 88cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar typedef list_type::iterator iterator; 89cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar typedef list_type::const_iterator const_iterator; 90789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 91789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarprivate: 92789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar list_type Commands; 93789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 94789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarpublic: 95789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar PipedJob(); 96789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 97789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar void addCommand(Command *C) { Commands.push_back(C); } 98789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 99789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar const list_type &getCommands() const { return Commands; } 1001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar size_type size() const { return Commands.size(); } 102cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar iterator begin() { return Commands.begin(); } 103cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar const_iterator begin() const { return Commands.begin(); } 104cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar iterator end() { return Commands.end(); } 105cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar const_iterator end() const { return Commands.end(); } 106789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 1071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Job *J) { 1081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return J->getKind() == PipedJobClass; 109789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar } 110789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar static bool classof(const PipedJob *) { return true; } 111789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar}; 112789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 113789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar /// JobList - A sequence of jobs to perform. 114789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarclass JobList : public Job { 115789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarpublic: 116789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar typedef llvm::SmallVector<Job*, 4> list_type; 117cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar typedef list_type::size_type size_type; 118cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar typedef list_type::iterator iterator; 119cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar typedef list_type::const_iterator const_iterator; 120789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 121789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarprivate: 122789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar list_type Jobs; 123789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 124789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbarpublic: 125789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar JobList(); 126789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 127789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar void addJob(Job *J) { Jobs.push_back(J); } 128789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 129789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar const list_type &getJobs() const { return Jobs; } 130789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 131cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar size_type size() const { return Jobs.size(); } 132cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar iterator begin() { return Jobs.begin(); } 133cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar const_iterator begin() const { return Jobs.begin(); } 134cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar iterator end() { return Jobs.end(); } 135cfcb96f610d6354234e8c33f3a25e340f6cd3a80Daniel Dunbar const_iterator end() const { return Jobs.end(); } 1361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump static bool classof(const Job *J) { 1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return J->getKind() == JobListClass; 139789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar } 140789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar static bool classof(const JobList *) { return true; } 141789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar}; 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 143789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar} // end namespace driver 144789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar} // end namespace clang 145789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar 146789e220d481371d52bd6265b5c414c5fe277f76bDaniel Dunbar#endif 147