Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 1 | //===--- Compilation.cpp - Compilation Task Implementation --------------*-===// |
| 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 | #include "clang/Driver/Compilation.h" |
Daniel Dunbar | 9d625e1 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 11 | |
Daniel Dunbar | 73f7b8c | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 12 | #include "clang/Driver/Action.h" |
Daniel Dunbar | 9d625e1 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 13 | #include "clang/Driver/ArgList.h" |
| 14 | #include "clang/Driver/ToolChain.h" |
| 15 | |
Daniel Dunbar | 1b26597 | 2009-03-18 06:49:39 +0000 | [diff] [blame^] | 16 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | d6f0e37 | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 17 | using namespace clang::driver; |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 18 | |
Daniel Dunbar | 9d625e1 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 19 | Compilation::Compilation(ToolChain &_DefaultToolChain, |
| 20 | ArgList *_Args) |
| 21 | : DefaultToolChain(_DefaultToolChain), Args(_Args) { |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 22 | } |
| 23 | |
Daniel Dunbar | 9d625e1 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 24 | Compilation::~Compilation() { |
| 25 | delete Args; |
| 26 | |
| 27 | // Free any derived arg lists. |
| 28 | for (llvm::DenseMap<const ToolChain*, ArgList*>::iterator |
| 29 | it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) { |
| 30 | ArgList *A = it->second; |
| 31 | if (A != Args) |
| 32 | delete Args; |
| 33 | } |
Daniel Dunbar | 73f7b8c | 2009-03-18 02:55:38 +0000 | [diff] [blame] | 34 | |
| 35 | // Free the actions, if built. |
| 36 | for (ActionList::iterator it = Actions.begin(), ie = Actions.end(); |
| 37 | it != ie; ++it) |
| 38 | delete *it; |
Daniel Dunbar | 9d625e1 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | const ArgList &Compilation::getArgsForToolChain(const ToolChain *TC) { |
| 42 | if (!TC) |
| 43 | TC = &DefaultToolChain; |
| 44 | |
Daniel Dunbar | e564028 | 2009-03-18 05:58:45 +0000 | [diff] [blame] | 45 | ArgList *&Entry = TCArgs[TC]; |
| 46 | if (!Entry) |
| 47 | Entry = TC->TranslateArgs(*Args); |
Daniel Dunbar | 9d625e1 | 2009-03-16 06:42:30 +0000 | [diff] [blame] | 48 | |
Daniel Dunbar | e564028 | 2009-03-18 05:58:45 +0000 | [diff] [blame] | 49 | return *Entry; |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Daniel Dunbar | 1b26597 | 2009-03-18 06:49:39 +0000 | [diff] [blame^] | 52 | void Compilation::PrintJob(llvm::raw_ostream &OS, const Job *J, |
| 53 | const char *Terminator) const { |
| 54 | if (const Command *C = dyn_cast<Command>(J)) { |
| 55 | OS << " \"" << C->getExecutable() << '"'; |
| 56 | for (ArgStringList::const_iterator it = C->getArguments().begin(), |
| 57 | ie = C->getArguments().end(); it != ie; ++it) |
| 58 | OS << " \"" << *it << '"'; |
| 59 | OS << Terminator; |
| 60 | } else if (const PipedJob *PJ = dyn_cast<PipedJob>(J)) { |
| 61 | for (PipedJob::const_iterator |
| 62 | it = PJ->begin(), ie = PJ->end(); it != ie; ++it) |
| 63 | PrintJob(OS, *it, (it + 1 != PJ->end()) ? " |\n" : "\n"); |
| 64 | } else { |
| 65 | const JobList *Jobs = cast<JobList>(J); |
| 66 | for (JobList::const_iterator |
| 67 | it = Jobs->begin(), ie = Jobs->end(); it != ie; ++it) |
| 68 | PrintJob(OS, *it, Terminator); |
| 69 | } |
| 70 | } |
| 71 | |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 72 | int Compilation::Execute() const { |
Daniel Dunbar | 1b26597 | 2009-03-18 06:49:39 +0000 | [diff] [blame^] | 73 | // Just print if -### was present. |
| 74 | if (getArgs().hasArg(options::OPT__HASH_HASH_HASH)) { |
| 75 | PrintJob(llvm::errs(), &Jobs, "\n"); |
| 76 | return 0; |
| 77 | } |
| 78 | |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 79 | return 0; |
| 80 | } |