Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 1 | //===-- 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 Dunbar | 16090d4 | 2009-03-03 05:55:11 +0000 | [diff] [blame] | 10 | // This is the entry point to the clang driver; it is a thin wrapper |
| 11 | // for functionality in the Driver clang library. |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "clang/Driver/Compilation.h" |
| 16 | #include "clang/Driver/Driver.h" |
Daniel Dunbar | a5aa4b0 | 2009-03-04 08:33:23 +0000 | [diff] [blame] | 17 | #include "clang/Driver/Option.h" |
| 18 | #include "clang/Driver/Options.h" |
| 19 | |
Daniel Dunbar | 9346849 | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 20 | #include "clang/Frontend/TextDiagnosticPrinter.h" |
| 21 | |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 22 | #include "llvm/ADT/OwningPtr.h" |
Daniel Dunbar | d25acaa | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 23 | #include "llvm/Config/config.h" |
Daniel Dunbar | 9346849 | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 24 | #include "llvm/Support/raw_ostream.h" |
Daniel Dunbar | b282ced | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 25 | #include "llvm/System/Path.h" |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 26 | #include "llvm/System/Signals.h" |
Daniel Dunbar | 9346849 | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 27 | using namespace clang; |
Daniel Dunbar | d6f0e37 | 2009-03-04 20:49:20 +0000 | [diff] [blame] | 28 | using namespace clang::driver; |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 29 | |
| 30 | int main(int argc, const char **argv) { |
| 31 | llvm::sys::PrintStackTraceOnErrorSignal(); |
| 32 | |
Daniel Dunbar | 9346849 | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 33 | llvm::OwningPtr<DiagnosticClient> |
| 34 | DiagClient(new TextDiagnosticPrinter(llvm::errs())); |
| 35 | |
| 36 | Diagnostic Diags(DiagClient.get()); |
| 37 | |
Daniel Dunbar | b282ced | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 38 | // 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 Dunbar | d25acaa | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 43 | // FIXME: Use the triple of the host, not the triple that we were |
| 44 | // compiled on. |
Daniel Dunbar | b282ced | 2009-03-10 20:52:46 +0000 | [diff] [blame] | 45 | llvm::OwningPtr<Driver> TheDriver(new Driver(Path.getBasename().c_str(), |
Daniel Dunbar | d25acaa | 2009-03-10 23:41:59 +0000 | [diff] [blame] | 46 | Path.getDirname().c_str(), |
Daniel Dunbar | 9346849 | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 47 | LLVM_HOSTTRIPLE, |
Daniel Dunbar | 7ce6add | 2009-03-16 06:56:51 +0000 | [diff] [blame] | 48 | "a.out", |
Daniel Dunbar | 9346849 | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 49 | Diags)); |
| 50 | |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 51 | llvm::OwningPtr<Compilation> C(TheDriver->BuildCompilation(argc, argv)); |
| 52 | |
Daniel Dunbar | 9346849 | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 53 | // If there were errors building the compilation, quit now. |
| 54 | if (Diags.getNumErrors()) |
| 55 | return 1; |
Daniel Dunbar | 88c9eae | 2009-03-13 17:24:34 +0000 | [diff] [blame] | 56 | if (!C.get()) |
| 57 | return 0; |
Daniel Dunbar | 9346849 | 2009-03-12 08:55:43 +0000 | [diff] [blame] | 58 | |
Daniel Dunbar | 63c4da9 | 2009-03-02 19:59:07 +0000 | [diff] [blame] | 59 | return C->Execute(); |
| 60 | } |