2009-03-03 03:59:07 +08:00
|
|
|
//===-- driver.cpp - Clang GCC-Compatible Driver --------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2009-03-03 13:55:11 +08:00
|
|
|
// This is the entry point to the clang driver; it is a thin wrapper
|
|
|
|
// for functionality in the Driver clang library.
|
2009-03-03 03:59:07 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Driver/Compilation.h"
|
|
|
|
#include "clang/Driver/Driver.h"
|
2009-03-04 16:33:23 +08:00
|
|
|
#include "clang/Driver/Option.h"
|
2010-02-25 11:23:43 +08:00
|
|
|
#include "clang/Frontend/DiagnosticOptions.h"
|
|
|
|
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
2009-03-04 16:33:23 +08:00
|
|
|
|
2009-03-18 10:11:26 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2010-07-19 23:20:12 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2009-03-03 03:59:07 +08:00
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
2009-03-11 07:41:59 +08:00
|
|
|
#include "llvm/Config/config.h"
|
2010-07-19 23:20:12 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2010-12-22 00:45:57 +08:00
|
|
|
#include "llvm/Support/FileSystem.h"
|
2009-03-18 09:38:48 +08:00
|
|
|
#include "llvm/Support/ManagedStatic.h"
|
2010-07-19 23:20:12 +08:00
|
|
|
#include "llvm/Support/MemoryBuffer.h"
|
2009-03-18 09:38:48 +08:00
|
|
|
#include "llvm/Support/PrettyStackTrace.h"
|
2010-02-18 05:00:34 +08:00
|
|
|
#include "llvm/Support/Regex.h"
|
2010-03-30 13:39:52 +08:00
|
|
|
#include "llvm/Support/Timer.h"
|
2009-03-12 16:55:43 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2010-11-30 02:12:39 +08:00
|
|
|
#include "llvm/Support/Host.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
|
|
|
#include "llvm/Support/Program.h"
|
|
|
|
#include "llvm/Support/Signals.h"
|
2010-12-10 01:36:38 +08:00
|
|
|
#include "llvm/Support/system_error.h"
|
2011-01-18 03:15:43 +08:00
|
|
|
#include <cctype>
|
2009-03-12 16:55:43 +08:00
|
|
|
using namespace clang;
|
2009-03-05 04:49:20 +08:00
|
|
|
using namespace clang::driver;
|
2009-03-03 03:59:07 +08:00
|
|
|
|
2010-10-31 01:32:40 +08:00
|
|
|
llvm::sys::Path GetExecutablePath(const char *Argv0, bool CanonicalPrefixes) {
|
2009-12-05 03:31:58 +08:00
|
|
|
if (!CanonicalPrefixes)
|
|
|
|
return llvm::sys::Path(Argv0);
|
|
|
|
|
2009-03-19 04:25:53 +08:00
|
|
|
// This just needs to be some symbol in the binary; C++ doesn't
|
|
|
|
// allow taking the address of ::main however.
|
|
|
|
void *P = (void*) (intptr_t) GetExecutablePath;
|
|
|
|
return llvm::sys::Path::GetMainExecutable(Argv0, P);
|
|
|
|
}
|
|
|
|
|
2009-07-18 02:10:27 +08:00
|
|
|
static const char *SaveStringInSet(std::set<std::string> &SavedStrings,
|
2010-02-18 05:00:34 +08:00
|
|
|
llvm::StringRef S) {
|
2009-04-17 09:54:00 +08:00
|
|
|
return SavedStrings.insert(S).first->c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// ApplyQAOverride - Apply a list of edits to the input argument lists.
|
|
|
|
///
|
|
|
|
/// The input string is a space separate list of edits to perform,
|
|
|
|
/// they are applied in order to the input argument lists. Edits
|
|
|
|
/// should be one of the following forms:
|
|
|
|
///
|
2009-07-17 05:32:51 +08:00
|
|
|
/// '#': Silence information about the changes to the command line arguments.
|
|
|
|
///
|
2009-04-17 09:54:00 +08:00
|
|
|
/// '^': Add FOO as a new argument at the beginning of the command line.
|
|
|
|
///
|
|
|
|
/// '+': Add FOO as a new argument at the end of the command line.
|
|
|
|
///
|
2010-02-18 05:00:34 +08:00
|
|
|
/// 's/XXX/YYY/': Substitute the regular expression XXX with YYY in the command
|
|
|
|
/// line.
|
2009-04-17 09:54:00 +08:00
|
|
|
///
|
|
|
|
/// 'xOPTION': Removes all instances of the literal argument OPTION.
|
|
|
|
///
|
|
|
|
/// 'XOPTION': Removes all instances of the literal argument OPTION,
|
|
|
|
/// and the following argument.
|
|
|
|
///
|
|
|
|
/// 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
|
|
|
|
/// at the end of the command line.
|
2009-07-17 05:32:51 +08:00
|
|
|
///
|
|
|
|
/// \param OS - The stream to write edit information to.
|
|
|
|
/// \param Args - The vector of command line arguments.
|
|
|
|
/// \param Edit - The override command to perform.
|
|
|
|
/// \param SavedStrings - Set to use for storing string representations.
|
2010-03-30 13:39:52 +08:00
|
|
|
static void ApplyOneQAOverride(llvm::raw_ostream &OS,
|
2010-07-20 10:47:40 +08:00
|
|
|
llvm::SmallVectorImpl<const char*> &Args,
|
2010-03-30 13:39:52 +08:00
|
|
|
llvm::StringRef Edit,
|
|
|
|
std::set<std::string> &SavedStrings) {
|
2009-04-17 09:54:00 +08:00
|
|
|
// This does not need to be efficient.
|
|
|
|
|
2009-07-18 02:10:27 +08:00
|
|
|
if (Edit[0] == '^') {
|
|
|
|
const char *Str =
|
2010-02-18 05:00:34 +08:00
|
|
|
SaveStringInSet(SavedStrings, Edit.substr(1));
|
2009-07-18 02:10:27 +08:00
|
|
|
OS << "### Adding argument " << Str << " at beginning\n";
|
|
|
|
Args.insert(Args.begin() + 1, Str);
|
|
|
|
} else if (Edit[0] == '+') {
|
|
|
|
const char *Str =
|
2010-02-18 05:00:34 +08:00
|
|
|
SaveStringInSet(SavedStrings, Edit.substr(1));
|
2009-07-18 02:10:27 +08:00
|
|
|
OS << "### Adding argument " << Str << " at end\n";
|
|
|
|
Args.push_back(Str);
|
2010-02-18 05:00:34 +08:00
|
|
|
} else if (Edit[0] == 's' && Edit[1] == '/' && Edit.endswith("/") &&
|
|
|
|
Edit.slice(2, Edit.size()-1).find('/') != llvm::StringRef::npos) {
|
|
|
|
llvm::StringRef MatchPattern = Edit.substr(2).split('/').first;
|
|
|
|
llvm::StringRef ReplPattern = Edit.substr(2).split('/').second;
|
|
|
|
ReplPattern = ReplPattern.slice(0, ReplPattern.size()-1);
|
|
|
|
|
|
|
|
for (unsigned i = 1, e = Args.size(); i != e; ++i) {
|
|
|
|
std::string Repl = llvm::Regex(MatchPattern).sub(ReplPattern, Args[i]);
|
|
|
|
|
|
|
|
if (Repl != Args[i]) {
|
|
|
|
OS << "### Replacing '" << Args[i] << "' with '" << Repl << "'\n";
|
|
|
|
Args[i] = SaveStringInSet(SavedStrings, Repl);
|
|
|
|
}
|
|
|
|
}
|
2009-07-18 02:10:27 +08:00
|
|
|
} else if (Edit[0] == 'x' || Edit[0] == 'X') {
|
|
|
|
std::string Option = Edit.substr(1, std::string::npos);
|
|
|
|
for (unsigned i = 1; i < Args.size();) {
|
|
|
|
if (Option == Args[i]) {
|
|
|
|
OS << "### Deleting argument " << Args[i] << '\n';
|
|
|
|
Args.erase(Args.begin() + i);
|
|
|
|
if (Edit[0] == 'X') {
|
|
|
|
if (i < Args.size()) {
|
|
|
|
OS << "### Deleting argument " << Args[i] << '\n';
|
|
|
|
Args.erase(Args.begin() + i);
|
|
|
|
} else
|
|
|
|
OS << "### Invalid X edit, end of command line!\n";
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
} else if (Edit[0] == 'O') {
|
|
|
|
for (unsigned i = 1; i < Args.size();) {
|
|
|
|
const char *A = Args[i];
|
|
|
|
if (A[0] == '-' && A[1] == 'O' &&
|
|
|
|
(A[2] == '\0' ||
|
|
|
|
(A[3] == '\0' && (A[2] == 's' || A[2] == 'z' ||
|
|
|
|
('0' <= A[2] && A[2] <= '9'))))) {
|
|
|
|
OS << "### Deleting argument " << Args[i] << '\n';
|
|
|
|
Args.erase(Args.begin() + i);
|
|
|
|
} else
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
OS << "### Adding argument " << Edit << " at end\n";
|
2010-02-18 05:00:34 +08:00
|
|
|
Args.push_back(SaveStringInSet(SavedStrings, '-' + Edit.str()));
|
2009-07-18 02:10:27 +08:00
|
|
|
} else {
|
|
|
|
OS << "### Unrecognized edit: " << Edit << "\n";
|
|
|
|
}
|
2009-04-17 09:54:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// ApplyQAOverride - Apply a comma separate list of edits to the
|
|
|
|
/// input argument lists. See ApplyOneQAOverride.
|
2010-07-20 10:47:40 +08:00
|
|
|
static void ApplyQAOverride(llvm::SmallVectorImpl<const char*> &Args,
|
2010-03-30 13:39:52 +08:00
|
|
|
const char *OverrideStr,
|
|
|
|
std::set<std::string> &SavedStrings) {
|
2009-07-17 05:32:51 +08:00
|
|
|
llvm::raw_ostream *OS = &llvm::errs();
|
2009-07-18 02:10:27 +08:00
|
|
|
|
2009-07-17 05:32:51 +08:00
|
|
|
if (OverrideStr[0] == '#') {
|
|
|
|
++OverrideStr;
|
|
|
|
OS = &llvm::nulls();
|
|
|
|
}
|
|
|
|
|
|
|
|
*OS << "### QA_OVERRIDE_GCC3_OPTIONS: " << OverrideStr << "\n";
|
2009-04-17 09:54:00 +08:00
|
|
|
|
|
|
|
// This does not need to be efficient.
|
|
|
|
|
|
|
|
const char *S = OverrideStr;
|
|
|
|
while (*S) {
|
|
|
|
const char *End = ::strchr(S, ' ');
|
|
|
|
if (!End)
|
|
|
|
End = S + strlen(S);
|
|
|
|
if (End != S)
|
2009-07-17 05:32:51 +08:00
|
|
|
ApplyOneQAOverride(*OS, Args, std::string(S, End), SavedStrings);
|
2009-04-17 09:54:00 +08:00
|
|
|
S = End;
|
|
|
|
if (*S != '\0')
|
|
|
|
++S;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-30 15:18:13 +08:00
|
|
|
extern int cc1_main(const char **ArgBegin, const char **ArgEnd,
|
2009-11-30 04:58:32 +08:00
|
|
|
const char *Argv0, void *MainAddr);
|
2010-05-21 01:49:16 +08:00
|
|
|
extern int cc1as_main(const char **ArgBegin, const char **ArgEnd,
|
|
|
|
const char *Argv0, void *MainAddr);
|
2009-11-19 15:37:51 +08:00
|
|
|
|
2010-07-19 23:20:12 +08:00
|
|
|
static void ExpandArgsFromBuf(const char *Arg,
|
2010-07-20 10:47:40 +08:00
|
|
|
llvm::SmallVectorImpl<const char*> &ArgVector,
|
2010-07-19 23:20:12 +08:00
|
|
|
std::set<std::string> &SavedStrings) {
|
|
|
|
const char *FName = Arg + 1;
|
2010-12-16 11:28:14 +08:00
|
|
|
llvm::OwningPtr<llvm::MemoryBuffer> MemBuf;
|
|
|
|
if (llvm::MemoryBuffer::getFile(FName, MemBuf)) {
|
2010-07-19 23:20:12 +08:00
|
|
|
ArgVector.push_back(SaveStringInSet(SavedStrings, Arg));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *Buf = MemBuf->getBufferStart();
|
|
|
|
char InQuote = ' ';
|
|
|
|
std::string CurArg;
|
|
|
|
|
|
|
|
for (const char *P = Buf; ; ++P) {
|
|
|
|
if (*P == '\0' || (isspace(*P) && InQuote == ' ')) {
|
|
|
|
if (!CurArg.empty()) {
|
|
|
|
|
|
|
|
if (CurArg[0] != '@') {
|
|
|
|
ArgVector.push_back(SaveStringInSet(SavedStrings, CurArg));
|
|
|
|
} else {
|
|
|
|
ExpandArgsFromBuf(CurArg.c_str(), ArgVector, SavedStrings);
|
|
|
|
}
|
|
|
|
|
|
|
|
CurArg = "";
|
|
|
|
}
|
|
|
|
if (*P == '\0')
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isspace(*P)) {
|
|
|
|
if (InQuote != ' ')
|
|
|
|
CurArg.push_back(*P);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*P == '"' || *P == '\'') {
|
|
|
|
if (InQuote == *P)
|
|
|
|
InQuote = ' ';
|
|
|
|
else if (InQuote == ' ')
|
|
|
|
InQuote = *P;
|
|
|
|
else
|
|
|
|
CurArg.push_back(*P);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*P == '\\') {
|
|
|
|
++P;
|
|
|
|
if (*P != '\0')
|
|
|
|
CurArg.push_back(*P);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CurArg.push_back(*P);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ExpandArgv(int argc, const char **argv,
|
2010-07-20 10:47:40 +08:00
|
|
|
llvm::SmallVectorImpl<const char*> &ArgVector,
|
2010-07-19 23:20:12 +08:00
|
|
|
std::set<std::string> &SavedStrings) {
|
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
const char *Arg = argv[i];
|
|
|
|
if (Arg[0] != '@') {
|
|
|
|
ArgVector.push_back(SaveStringInSet(SavedStrings, std::string(Arg)));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpandArgsFromBuf(Arg, ArgVector, SavedStrings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc_, const char **argv_) {
|
2009-03-03 03:59:07 +08:00
|
|
|
llvm::sys::PrintStackTraceOnErrorSignal();
|
2010-07-19 23:20:12 +08:00
|
|
|
llvm::PrettyStackTraceProgram X(argc_, argv_);
|
|
|
|
|
|
|
|
std::set<std::string> SavedStrings;
|
2010-07-20 10:47:40 +08:00
|
|
|
llvm::SmallVector<const char*, 256> argv;
|
2010-07-19 23:20:12 +08:00
|
|
|
|
|
|
|
ExpandArgv(argc_, argv_, argv, SavedStrings);
|
2009-03-03 03:59:07 +08:00
|
|
|
|
2010-05-21 01:49:16 +08:00
|
|
|
// Handle -cc1 integrated tools.
|
2010-07-19 23:20:12 +08:00
|
|
|
if (argv.size() > 1 && llvm::StringRef(argv[1]).startswith("-cc1")) {
|
2010-05-21 01:49:16 +08:00
|
|
|
llvm::StringRef Tool = argv[1] + 4;
|
|
|
|
|
|
|
|
if (Tool == "")
|
2010-07-20 10:47:40 +08:00
|
|
|
return cc1_main(argv.data()+2, argv.data()+argv.size(), argv[0],
|
2010-05-21 01:49:16 +08:00
|
|
|
(void*) (intptr_t) GetExecutablePath);
|
|
|
|
if (Tool == "as")
|
2010-07-20 10:47:40 +08:00
|
|
|
return cc1as_main(argv.data()+2, argv.data()+argv.size(), argv[0],
|
2010-05-21 01:49:16 +08:00
|
|
|
(void*) (intptr_t) GetExecutablePath);
|
|
|
|
|
|
|
|
// Reject unknown tools.
|
|
|
|
llvm::errs() << "error: unknown integrated tool '" << Tool << "'\n";
|
|
|
|
return 1;
|
|
|
|
}
|
2009-11-30 15:18:13 +08:00
|
|
|
|
2009-12-05 03:31:58 +08:00
|
|
|
bool CanonicalPrefixes = true;
|
2010-07-19 23:20:12 +08:00
|
|
|
for (int i = 1, size = argv.size(); i < size; ++i) {
|
2009-12-05 03:31:58 +08:00
|
|
|
if (llvm::StringRef(argv[i]) == "-no-canonical-prefixes") {
|
|
|
|
CanonicalPrefixes = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
llvm::sys::Path Path = GetExecutablePath(argv[0], CanonicalPrefixes);
|
|
|
|
|
2010-08-19 06:29:43 +08:00
|
|
|
TextDiagnosticPrinter *DiagClient
|
|
|
|
= new TextDiagnosticPrinter(llvm::errs(), DiagnosticOptions());
|
2010-12-18 12:13:32 +08:00
|
|
|
DiagClient->setPrefix(llvm::sys::path::stem(Path.str()));
|
2010-11-19 04:06:41 +08:00
|
|
|
llvm::IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
|
|
|
|
Diagnostic Diags(DiagID, DiagClient);
|
2009-03-18 10:11:26 +08:00
|
|
|
|
2009-09-23 06:31:13 +08:00
|
|
|
#ifdef CLANG_IS_PRODUCTION
|
2010-03-09 02:33:04 +08:00
|
|
|
const bool IsProduction = true;
|
2010-04-02 02:21:41 +08:00
|
|
|
# ifdef CLANGXX_IS_PRODUCTION
|
|
|
|
const bool CXXIsProduction = true;
|
|
|
|
# else
|
|
|
|
const bool CXXIsProduction = false;
|
|
|
|
# endif
|
2009-09-23 06:31:13 +08:00
|
|
|
#else
|
2010-03-09 02:33:04 +08:00
|
|
|
const bool IsProduction = false;
|
2010-04-02 02:21:41 +08:00
|
|
|
const bool CXXIsProduction = false;
|
2009-09-23 06:31:13 +08:00
|
|
|
#endif
|
2010-07-19 08:44:04 +08:00
|
|
|
Driver TheDriver(Path.str(), llvm::sys::getHostTriple(),
|
2010-04-02 02:21:41 +08:00
|
|
|
"a.out", IsProduction, CXXIsProduction,
|
|
|
|
Diags);
|
2009-04-02 03:08:46 +08:00
|
|
|
|
2010-08-02 06:29:51 +08:00
|
|
|
// Attempt to find the original path used to invoke the driver, to determine
|
|
|
|
// the installed path. We do this manually, because we want to support that
|
|
|
|
// path being a symlink.
|
2010-12-22 00:45:57 +08:00
|
|
|
{
|
|
|
|
llvm::SmallString<128> InstalledPath(argv[0]);
|
|
|
|
|
|
|
|
// Do a PATH lookup, if there are no directory components.
|
|
|
|
if (llvm::sys::path::filename(InstalledPath) == InstalledPath) {
|
|
|
|
llvm::sys::Path Tmp = llvm::sys::Program::FindProgramByName(
|
|
|
|
llvm::sys::path::filename(InstalledPath.str()));
|
|
|
|
if (!Tmp.empty())
|
|
|
|
InstalledPath = Tmp.str();
|
|
|
|
}
|
|
|
|
llvm::sys::fs::make_absolute(InstalledPath);
|
|
|
|
InstalledPath = llvm::sys::path::parent_path(InstalledPath);
|
|
|
|
bool exists;
|
|
|
|
if (!llvm::sys::fs::exists(InstalledPath.str(), exists) && exists)
|
|
|
|
TheDriver.setInstalledDir(InstalledPath);
|
2010-08-02 06:29:51 +08:00
|
|
|
}
|
|
|
|
|
2009-11-11 02:47:41 +08:00
|
|
|
// Check for ".*++" or ".*++-[^-]*" to determine if we are a C++
|
|
|
|
// compiler. This matches things like "c++", "clang++", and "clang++-1.1".
|
|
|
|
//
|
|
|
|
// Note that we intentionally want to use argv[0] here, to support "clang++"
|
|
|
|
// being a symlink.
|
2009-11-20 19:49:06 +08:00
|
|
|
//
|
|
|
|
// We use *argv instead of argv[0] to work around a bogus g++ warning.
|
2010-07-19 23:20:12 +08:00
|
|
|
const char *progname = argv_[0];
|
2010-12-18 12:13:32 +08:00
|
|
|
std::string ProgName(llvm::sys::path::stem(progname));
|
2009-11-11 18:10:25 +08:00
|
|
|
if (llvm::StringRef(ProgName).endswith("++") ||
|
2009-12-26 04:21:23 +08:00
|
|
|
llvm::StringRef(ProgName).rsplit('-').first.endswith("++")) {
|
2009-11-11 02:47:41 +08:00
|
|
|
TheDriver.CCCIsCXX = true;
|
2009-12-26 04:21:23 +08:00
|
|
|
}
|
2009-11-11 02:47:41 +08:00
|
|
|
|
2010-03-20 16:01:59 +08:00
|
|
|
// Handle CC_PRINT_OPTIONS and CC_PRINT_OPTIONS_FILE.
|
|
|
|
TheDriver.CCPrintOptions = !!::getenv("CC_PRINT_OPTIONS");
|
|
|
|
if (TheDriver.CCPrintOptions)
|
|
|
|
TheDriver.CCPrintOptionsFilename = ::getenv("CC_PRINT_OPTIONS_FILE");
|
|
|
|
|
2009-04-17 09:54:00 +08:00
|
|
|
// Handle QA_OVERRIDE_GCC3_OPTIONS and CCC_ADD_ARGS, used for editing a
|
|
|
|
// command line behind the scenes.
|
|
|
|
if (const char *OverrideStr = ::getenv("QA_OVERRIDE_GCC3_OPTIONS")) {
|
|
|
|
// FIXME: Driver shouldn't take extra initial argument.
|
2010-07-19 23:20:12 +08:00
|
|
|
ApplyQAOverride(argv, OverrideStr, SavedStrings);
|
2009-04-17 09:54:00 +08:00
|
|
|
} else if (const char *Cur = ::getenv("CCC_ADD_ARGS")) {
|
2009-04-02 03:08:46 +08:00
|
|
|
// FIXME: Driver shouldn't take extra initial argument.
|
2010-07-19 23:20:12 +08:00
|
|
|
std::vector<const char*> ExtraArgs;
|
2009-04-02 03:08:46 +08:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
const char *Next = strchr(Cur, ',');
|
2009-07-18 02:10:27 +08:00
|
|
|
|
2009-04-02 03:08:46 +08:00
|
|
|
if (Next) {
|
2010-07-19 23:20:12 +08:00
|
|
|
ExtraArgs.push_back(SaveStringInSet(SavedStrings,
|
|
|
|
std::string(Cur, Next)));
|
2009-04-02 03:08:46 +08:00
|
|
|
Cur = Next + 1;
|
|
|
|
} else {
|
2009-04-17 09:54:00 +08:00
|
|
|
if (*Cur != '\0')
|
2010-07-19 23:20:12 +08:00
|
|
|
ExtraArgs.push_back(SaveStringInSet(SavedStrings, Cur));
|
2009-04-02 03:08:46 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-20 10:47:40 +08:00
|
|
|
argv.insert(&argv[1], ExtraArgs.begin(), ExtraArgs.end());
|
2010-07-19 06:03:55 +08:00
|
|
|
}
|
2009-03-03 03:59:07 +08:00
|
|
|
|
2010-08-02 06:29:47 +08:00
|
|
|
llvm::OwningPtr<Compilation> C(TheDriver.BuildCompilation(argv.size(),
|
|
|
|
&argv[0]));
|
2009-03-21 08:40:53 +08:00
|
|
|
int Res = 0;
|
|
|
|
if (C.get())
|
2009-07-02 04:03:04 +08:00
|
|
|
Res = TheDriver.ExecuteCompilation(*C);
|
2010-03-30 13:39:52 +08:00
|
|
|
|
|
|
|
// If any timers were active but haven't been destroyed yet, print their
|
|
|
|
// results now. This happens in -disable-free mode.
|
|
|
|
llvm::TimerGroup::printAll(llvm::errs());
|
|
|
|
|
2009-03-18 09:38:48 +08:00
|
|
|
llvm::llvm_shutdown();
|
|
|
|
|
2009-03-21 08:40:53 +08:00
|
|
|
return Res;
|
2009-03-03 03:59:07 +08:00
|
|
|
}
|