summaryrefslogtreecommitdiff
path: root/tools/driver/driver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/driver/driver.cpp')
-rw-r--r--tools/driver/driver.cpp126
1 files changed, 73 insertions, 53 deletions
diff --git a/tools/driver/driver.cpp b/tools/driver/driver.cpp
index 323283e653b4d..9d204ce6c0c23 100644
--- a/tools/driver/driver.cpp
+++ b/tools/driver/driver.cpp
@@ -34,7 +34,7 @@ class DriverDiagnosticPrinter : public DiagnosticClient {
llvm::raw_ostream &OS;
public:
- DriverDiagnosticPrinter(const std::string _ProgName,
+ DriverDiagnosticPrinter(const std::string _ProgName,
llvm::raw_ostream &_OS)
: ProgName(_ProgName),
OS(_OS) {}
@@ -54,7 +54,7 @@ void DriverDiagnosticPrinter::HandleDiagnostic(Diagnostic::Level Level,
case Diagnostic::Error: OS << "error: "; break;
case Diagnostic::Fatal: OS << "fatal error: "; break;
}
-
+
llvm::SmallString<100> OutStr;
Info.FormatDiagnostic(OutStr);
OS.write(OutStr.begin(), OutStr.size());
@@ -68,7 +68,7 @@ llvm::sys::Path GetExecutablePath(const char *Argv0) {
return llvm::sys::Path::GetMainExecutable(Argv0, P);
}
-static const char *SaveStringInSet(std::set<std::string> &SavedStrings,
+static const char *SaveStringInSet(std::set<std::string> &SavedStrings,
const std::string &S) {
return SavedStrings.insert(S).first->c_str();
}
@@ -79,6 +79,8 @@ static const char *SaveStringInSet(std::set<std::string> &SavedStrings,
/// they are applied in order to the input argument lists. Edits
/// should be one of the following forms:
///
+/// '#': Silence information about the changes to the command line arguments.
+///
/// '^': 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.
@@ -93,61 +95,74 @@ static const char *SaveStringInSet(std::set<std::string> &SavedStrings,
///
/// 'Ox': Removes all flags matching 'O' or 'O[sz0-9]' and adds 'Ox'
/// at the end of the command line.
-void ApplyOneQAOverride(std::vector<const char*> &Args,
+///
+/// \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.
+void ApplyOneQAOverride(llvm::raw_ostream &OS,
+ std::vector<const char*> &Args,
const std::string &Edit,
std::set<std::string> &SavedStrings) {
// This does not need to be efficient.
- if (Edit[0] == '^') {
- const char *Str =
- SaveStringInSet(SavedStrings, Edit.substr(1, std::string::npos));
- llvm::errs() << "### Adding argument " << Str << " at beginning\n";
- Args.insert(Args.begin() + 1, Str);
- } else if (Edit[0] == '+') {
- const char *Str =
- SaveStringInSet(SavedStrings, Edit.substr(1, std::string::npos));
- llvm::errs() << "### Adding argument " << Str << " at end\n";
- Args.push_back(Str);
- } 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]) {
- llvm::errs() << "### Deleting argument " << Args[i] << '\n';
- Args.erase(Args.begin() + i);
- if (Edit[0] == 'X') {
- if (i < Args.size()) {
- llvm::errs() << "### Deleting argument " << Args[i] << '\n';
- Args.erase(Args.begin() + i);
- } else
- llvm::errs() << "### 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'))))) {
- llvm::errs() << "### Deleting argument " << Args[i] << '\n';
- Args.erase(Args.begin() + i);
- } else
- ++i;
- }
- llvm::errs() << "### Adding argument " << Edit << " at end\n";
- Args.push_back(SaveStringInSet(SavedStrings, '-' + Edit));
- } else {
- llvm::errs() << "### Unrecognized edit: " << Edit << "\n";
- }
+ if (Edit[0] == '^') {
+ const char *Str =
+ SaveStringInSet(SavedStrings, Edit.substr(1, std::string::npos));
+ OS << "### Adding argument " << Str << " at beginning\n";
+ Args.insert(Args.begin() + 1, Str);
+ } else if (Edit[0] == '+') {
+ const char *Str =
+ SaveStringInSet(SavedStrings, Edit.substr(1, std::string::npos));
+ OS << "### Adding argument " << Str << " at end\n";
+ Args.push_back(Str);
+ } 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";
+ Args.push_back(SaveStringInSet(SavedStrings, '-' + Edit));
+ } else {
+ OS << "### Unrecognized edit: " << Edit << "\n";
+ }
}
/// ApplyQAOverride - Apply a comma separate list of edits to the
/// input argument lists. See ApplyOneQAOverride.
void ApplyQAOverride(std::vector<const char*> &Args, const char *OverrideStr,
std::set<std::string> &SavedStrings) {
- llvm::errs() << "### QA_OVERRIDE_GCC3_OPTIONS: " << OverrideStr << "\n";
+ llvm::raw_ostream *OS = &llvm::errs();
+
+ if (OverrideStr[0] == '#') {
+ ++OverrideStr;
+ OS = &llvm::nulls();
+ }
+
+ *OS << "### QA_OVERRIDE_GCC3_OPTIONS: " << OverrideStr << "\n";
// This does not need to be efficient.
@@ -157,7 +172,7 @@ void ApplyQAOverride(std::vector<const char*> &Args, const char *OverrideStr,
if (!End)
End = S + strlen(S);
if (End != S)
- ApplyOneQAOverride(Args, std::string(S, End), SavedStrings);
+ ApplyOneQAOverride(*OS, Args, std::string(S, End), SavedStrings);
S = End;
if (*S != '\0')
++S;
@@ -173,9 +188,14 @@ int main(int argc, const char **argv) {
Diagnostic Diags(&DiagClient);
+#ifdef CLANG_IS_PRODUCTION
+ bool IsProduction = true;
+#else
+ bool IsProduction = false;
+#endif
Driver TheDriver(Path.getBasename().c_str(), Path.getDirname().c_str(),
llvm::sys::getHostTriple().c_str(),
- "a.out", Diags);
+ "a.out", IsProduction, Diags);
llvm::OwningPtr<Compilation> C;
@@ -188,7 +208,7 @@ int main(int argc, const char **argv) {
ApplyQAOverride(StringPointers, OverrideStr, SavedStrings);
- C.reset(TheDriver.BuildCompilation(StringPointers.size(),
+ C.reset(TheDriver.BuildCompilation(StringPointers.size(),
&StringPointers[0]));
} else if (const char *Cur = ::getenv("CCC_ADD_ARGS")) {
std::vector<const char*> StringPointers;
@@ -198,7 +218,7 @@ int main(int argc, const char **argv) {
for (;;) {
const char *Next = strchr(Cur, ',');
-
+
if (Next) {
StringPointers.push_back(SaveStringInSet(SavedStrings,
std::string(Cur, Next)));
@@ -212,7 +232,7 @@ int main(int argc, const char **argv) {
StringPointers.insert(StringPointers.end(), argv + 1, argv + argc);
- C.reset(TheDriver.BuildCompilation(StringPointers.size(),
+ C.reset(TheDriver.BuildCompilation(StringPointers.size(),
&StringPointers[0]));
} else
C.reset(TheDriver.BuildCompilation(argc, argv));