2009-03-02 19:59:07 +00:00
|
|
|
//===--- Compilation.cpp - Compilation Task Implementation --------------*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Driver/Compilation.h"
|
2009-03-16 06:42:30 +00:00
|
|
|
|
2009-03-18 02:55:38 +00:00
|
|
|
#include "clang/Driver/Action.h"
|
2009-03-16 06:42:30 +00:00
|
|
|
#include "clang/Driver/ArgList.h"
|
|
|
|
#include "clang/Driver/ToolChain.h"
|
|
|
|
|
2009-03-18 06:49:39 +00:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2009-03-04 20:49:20 +00:00
|
|
|
using namespace clang::driver;
|
2009-03-02 19:59:07 +00:00
|
|
|
|
2009-03-16 06:42:30 +00:00
|
|
|
Compilation::Compilation(ToolChain &_DefaultToolChain,
|
|
|
|
ArgList *_Args)
|
|
|
|
: DefaultToolChain(_DefaultToolChain), Args(_Args) {
|
|
|
|
}
|
|
|
|
|
|
|
|
Compilation::~Compilation() {
|
|
|
|
delete Args;
|
|
|
|
|
|
|
|
// Free any derived arg lists.
|
|
|
|
for (llvm::DenseMap<const ToolChain*, ArgList*>::iterator
|
|
|
|
it = TCArgs.begin(), ie = TCArgs.end(); it != ie; ++it) {
|
|
|
|
ArgList *A = it->second;
|
|
|
|
if (A != Args)
|
|
|
|
delete Args;
|
|
|
|
}
|
2009-03-18 02:55:38 +00:00
|
|
|
|
|
|
|
// Free the actions, if built.
|
|
|
|
for (ActionList::iterator it = Actions.begin(), ie = Actions.end();
|
|
|
|
it != ie; ++it)
|
|
|
|
delete *it;
|
2009-03-02 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
2009-03-16 06:42:30 +00:00
|
|
|
const ArgList &Compilation::getArgsForToolChain(const ToolChain *TC) {
|
|
|
|
if (!TC)
|
|
|
|
TC = &DefaultToolChain;
|
|
|
|
|
2009-03-18 05:58:45 +00:00
|
|
|
ArgList *&Entry = TCArgs[TC];
|
|
|
|
if (!Entry)
|
|
|
|
Entry = TC->TranslateArgs(*Args);
|
2009-03-16 06:42:30 +00:00
|
|
|
|
2009-03-18 05:58:45 +00:00
|
|
|
return *Entry;
|
2009-03-02 19:59:07 +00:00
|
|
|
}
|
|
|
|
|
2009-03-18 06:49:39 +00:00
|
|
|
void Compilation::PrintJob(llvm::raw_ostream &OS, const Job *J,
|
|
|
|
const char *Terminator) const {
|
|
|
|
if (const Command *C = dyn_cast<Command>(J)) {
|
|
|
|
OS << " \"" << C->getExecutable() << '"';
|
|
|
|
for (ArgStringList::const_iterator it = C->getArguments().begin(),
|
|
|
|
ie = C->getArguments().end(); it != ie; ++it)
|
|
|
|
OS << " \"" << *it << '"';
|
|
|
|
OS << Terminator;
|
|
|
|
} else if (const PipedJob *PJ = dyn_cast<PipedJob>(J)) {
|
|
|
|
for (PipedJob::const_iterator
|
|
|
|
it = PJ->begin(), ie = PJ->end(); it != ie; ++it)
|
|
|
|
PrintJob(OS, *it, (it + 1 != PJ->end()) ? " |\n" : "\n");
|
|
|
|
} else {
|
|
|
|
const JobList *Jobs = cast<JobList>(J);
|
|
|
|
for (JobList::const_iterator
|
|
|
|
it = Jobs->begin(), ie = Jobs->end(); it != ie; ++it)
|
|
|
|
PrintJob(OS, *it, Terminator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-02 19:59:07 +00:00
|
|
|
int Compilation::Execute() const {
|
2009-03-18 06:49:39 +00:00
|
|
|
// Just print if -### was present.
|
|
|
|
if (getArgs().hasArg(options::OPT__HASH_HASH_HASH)) {
|
|
|
|
PrintJob(llvm::errs(), &Jobs, "\n");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-03-02 19:59:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|