blob: 541a6d8eebae29d60688a353347277041aac00ab [file] [log] [blame]
Daniel Dunbar63c4da92009-03-02 19:59:07 +00001//===--- Driver.cpp - Clang GCC Compatible Driver -----------------------*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
Daniel Dunbar63c4da92009-03-02 19:59:07 +000010#include "clang/Driver/Driver.h"
Daniel Dunbar63c4da92009-03-02 19:59:07 +000011
Daniel Dunbard6f0e372009-03-04 20:49:20 +000012#include "clang/Driver/Arg.h"
13#include "clang/Driver/ArgList.h"
14#include "clang/Driver/Compilation.h"
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000015#include "clang/Driver/Option.h"
Daniel Dunbard6f0e372009-03-04 20:49:20 +000016#include "clang/Driver/Options.h"
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000017
18#include "llvm/Support/raw_ostream.h"
Daniel Dunbard6f0e372009-03-04 20:49:20 +000019using namespace clang::driver;
20
21Driver::Driver() : Opts(new OptTable()) {
22
Daniel Dunbar63c4da92009-03-02 19:59:07 +000023}
24
25Driver::~Driver() {
Daniel Dunbard6f0e372009-03-04 20:49:20 +000026 delete Opts;
Daniel Dunbar63c4da92009-03-02 19:59:07 +000027}
28
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000029ArgList *Driver::ParseArgStrings(const char **ArgBegin, const char **ArgEnd) {
30 ArgList *Args = new ArgList(ArgBegin, ArgEnd);
31
32 unsigned Index = 0, End = ArgEnd - ArgBegin;
33 while (Index < End) {
34 unsigned Prev = Index;
35 Arg *A = getOpts().ParseOneArg(*Args, Index, End);
36 if (A)
37 Args->append(A);
38
39 assert(Index > Prev && "Parser failed to consume argument.");
40 }
41
42 return Args;
43}
44
Daniel Dunbar63c4da92009-03-02 19:59:07 +000045Compilation *Driver::BuildCompilation(int argc, const char **argv) {
Daniel Dunbar7dc2a042009-03-05 06:38:47 +000046 ArgList *Args = ParseArgStrings(argv + 1, argv + argc);
47
48 // Hard coded to print-options behavior.
49 unsigned i = 0;
50 for (ArgList::iterator it = Args->begin(), ie = Args->end();
51 it != ie; ++it, ++i) {
52 Arg *A = *it;
53 llvm::errs() << "Option " << i << " - "
54 << "Name: \"" << A->getOption().getName() << "\", "
55 << "Values: {";
56 for (unsigned j = 0; j < A->getNumValues(); ++j) {
57 if (j)
58 llvm::errs() << ", ";
59 llvm::errs() << '"' << A->getValue(*Args, j) << '"';
60 }
61 llvm::errs() << "}\n";
62
63 llvm::errs().flush(); // FIXME
64 }
65
Daniel Dunbar63c4da92009-03-02 19:59:07 +000066 return new Compilation();
67}