aboutsummaryrefslogtreecommitdiff
path: root/lib/Driver/Driver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Driver/Driver.cpp')
-rw-r--r--lib/Driver/Driver.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index d3c959499a..541a6d8eeb 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -12,7 +12,10 @@
#include "clang/Driver/Arg.h"
#include "clang/Driver/ArgList.h"
#include "clang/Driver/Compilation.h"
+#include "clang/Driver/Option.h"
#include "clang/Driver/Options.h"
+
+#include "llvm/Support/raw_ostream.h"
using namespace clang::driver;
Driver::Driver() : Opts(new OptTable()) {
@@ -23,6 +26,42 @@ Driver::~Driver() {
delete Opts;
}
+ArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) {
+ ArgList *Args = new ArgList(ArgBegin, ArgEnd);
+
+ unsigned Index = 0, End = ArgEnd - ArgBegin;
+ while (Index < End) {
+ unsigned Prev = Index;
+ Arg *A = getOpts().ParseOneArg(*Args, Index, End);
+ if (A)
+ Args->append(A);
+
+ assert(Index > Prev && "Parser failed to consume argument.");
+ }
+
+ return Args;
+}
+
Compilation *Driver::BuildCompilation(int argc, const char **argv) {
+ ArgList *Args = ParseArgStrings(argv + 1, argv + argc);
+
+ // Hard coded to print-options behavior.
+ unsigned i = 0;
+ for (ArgList::iterator it = Args->begin(), ie = Args->end();
+ it != ie; ++it, ++i) {
+ Arg *A = *it;
+ llvm::errs() << "Option " << i << " - "
+ << "Name: \"" << A->getOption().getName() << "\", "
+ << "Values: {";
+ for (unsigned j = 0; j < A->getNumValues(); ++j) {
+ if (j)
+ llvm::errs() << ", ";
+ llvm::errs() << '"' << A->getValue(*Args, j) << '"';
+ }
+ llvm::errs() << "}\n";
+
+ llvm::errs().flush(); // FIXME
+ }
+
return new Compilation();
}