[cfe-commits] r68231 - /cfe/trunk/tools/driver/driver.cpp

Daniel Dunbar daniel at zuster.org
Wed Apr 1 12:08:47 PDT 2009


Author: ddunbar
Date: Wed Apr  1 14:08:46 2009
New Revision: 68231

URL: http://llvm.org/viewvc/llvm-project?rev=68231&view=rev
Log:
Support CCC_ADD_ARGS in new driver.

Modified:
    cfe/trunk/tools/driver/driver.cpp

Modified: cfe/trunk/tools/driver/driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/driver.cpp?rev=68231&r1=68230&r2=68231&view=diff

==============================================================================
--- cfe/trunk/tools/driver/driver.cpp (original)
+++ cfe/trunk/tools/driver/driver.cpp Wed Apr  1 14:08:46 2009
@@ -82,8 +82,43 @@
     TheDriver(new Driver(Path.getBasename().c_str(), Path.getDirname().c_str(),
                          llvm::sys::getHostTriple().c_str(),
                          "a.out", Diags));
-                                               
-  llvm::OwningPtr<Compilation> C(TheDriver->BuildCompilation(argc, argv));
+
+  llvm::OwningPtr<Compilation> C;
+
+  // Handle CCC_ADD_ARGS, a comma separated list of extra arguments.
+  if (const char *Cur = ::getenv("CCC_ADD_ARGS")) {
+    std::set<std::string> SavedStrings;
+    std::vector<const char*> StringPointers;
+
+    // FIXME: Driver shouldn't take extra initial argument.
+    StringPointers.push_back(argv[0]);
+
+    for (;;) {
+      const char *Next = strchr(Cur, ',');
+      
+      if (Next) {
+        if (Cur != Next) {
+          const char *P = 
+            SavedStrings.insert(std::string(Cur, Next)).first->c_str();
+          StringPointers.push_back(P);
+        }
+        Cur = Next + 1;
+      } else {
+        if (*Cur != '\0') {
+          const char *P = 
+            SavedStrings.insert(std::string(Cur)).first->c_str();
+          StringPointers.push_back(P);
+        }
+        break;
+      }
+    }
+
+    StringPointers.insert(StringPointers.end(), argv + 1, argv + argc);
+
+    C.reset(TheDriver->BuildCompilation(StringPointers.size(), 
+                                        &StringPointers[0]));
+  } else
+    C.reset(TheDriver->BuildCompilation(argc, argv));
 
   int Res = 0;
   if (C.get())





More information about the cfe-commits mailing list