blob: 645a3ff11a8a2e88bd1808723ab3392d1500536a [file] [log] [blame]
Daniel Dunbar3ede8d02009-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 Dunbar1eb4e642009-03-03 05:55:11 +000010// This is the entry point to the clang driver; it is a thin wrapper
11// for functionality in the Driver clang library.
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Driver/Compilation.h"
16#include "clang/Driver/Driver.h"
Daniel Dunbar2c6f6f32009-03-04 08:33:23 +000017#include "clang/Driver/Option.h"
18#include "clang/Driver/Options.h"
19
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000020#include "clang/Frontend/TextDiagnosticPrinter.h"
21
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000022#include "llvm/ADT/OwningPtr.h"
Daniel Dunbardd98e2c2009-03-10 23:41:59 +000023#include "llvm/Config/config.h"
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000024#include "llvm/Support/raw_ostream.h"
Daniel Dunbar365c02f2009-03-10 20:52:46 +000025#include "llvm/System/Path.h"
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000026#include "llvm/System/Signals.h"
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000027using namespace clang;
Daniel Dunbar1b3bb6e2009-03-04 20:49:20 +000028using namespace clang::driver;
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000029
30int main(int argc, const char **argv) {
31 llvm::sys::PrintStackTraceOnErrorSignal();
32
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000033 llvm::OwningPtr<DiagnosticClient>
34 DiagClient(new TextDiagnosticPrinter(llvm::errs()));
35
36 Diagnostic Diags(DiagClient.get());
37
Daniel Dunbar365c02f2009-03-10 20:52:46 +000038 // FIXME: We should use GetMainExecutable here, probably, but we may
39 // want to handle symbolic links slightly differently. The problem
40 // is that the path derived from this will influence search paths.
41 llvm::sys::Path Path(argv[0]);
42
Daniel Dunbardd98e2c2009-03-10 23:41:59 +000043 // FIXME: Use the triple of the host, not the triple that we were
44 // compiled on.
Daniel Dunbar365c02f2009-03-10 20:52:46 +000045 llvm::OwningPtr<Driver> TheDriver(new Driver(Path.getBasename().c_str(),
Daniel Dunbardd98e2c2009-03-10 23:41:59 +000046 Path.getDirname().c_str(),
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000047 LLVM_HOSTTRIPLE,
48 Diags));
49
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000050 llvm::OwningPtr<Compilation> C(TheDriver->BuildCompilation(argc, argv));
51
Daniel Dunbar4ad4b3e2009-03-12 08:55:43 +000052 // If there were errors building the compilation, quit now.
53 if (Diags.getNumErrors())
54 return 1;
55
Daniel Dunbar3ede8d02009-03-02 19:59:07 +000056 return C->Execute();
57}