blob: 0724fbd08ce1575359a1bbd2f7d33e27e181e2c0 [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 Dunbar16090d42009-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 Dunbar63c4da92009-03-02 19:59:07 +000012//
13//===----------------------------------------------------------------------===//
14
15#include "clang/Driver/Compilation.h"
16#include "clang/Driver/Driver.h"
Daniel Dunbara5aa4b02009-03-04 08:33:23 +000017#include "clang/Driver/Option.h"
18#include "clang/Driver/Options.h"
19
Daniel Dunbar93468492009-03-12 08:55:43 +000020#include "clang/Frontend/TextDiagnosticPrinter.h"
21
Daniel Dunbar63c4da92009-03-02 19:59:07 +000022#include "llvm/ADT/OwningPtr.h"
Daniel Dunbard25acaa2009-03-10 23:41:59 +000023#include "llvm/Config/config.h"
Daniel Dunbar16e04ff2009-03-18 01:38:48 +000024#include "llvm/Support/ManagedStatic.h"
25#include "llvm/Support/PrettyStackTrace.h"
Daniel Dunbar93468492009-03-12 08:55:43 +000026#include "llvm/Support/raw_ostream.h"
Daniel Dunbarb282ced2009-03-10 20:52:46 +000027#include "llvm/System/Path.h"
Daniel Dunbar63c4da92009-03-02 19:59:07 +000028#include "llvm/System/Signals.h"
Daniel Dunbar93468492009-03-12 08:55:43 +000029using namespace clang;
Daniel Dunbard6f0e372009-03-04 20:49:20 +000030using namespace clang::driver;
Daniel Dunbar63c4da92009-03-02 19:59:07 +000031
32int main(int argc, const char **argv) {
33 llvm::sys::PrintStackTraceOnErrorSignal();
Daniel Dunbar16e04ff2009-03-18 01:38:48 +000034 llvm::PrettyStackTraceProgram X(argc, argv);
Daniel Dunbar63c4da92009-03-02 19:59:07 +000035
Daniel Dunbar93468492009-03-12 08:55:43 +000036 llvm::OwningPtr<DiagnosticClient>
37 DiagClient(new TextDiagnosticPrinter(llvm::errs()));
38
39 Diagnostic Diags(DiagClient.get());
40
Daniel Dunbarb282ced2009-03-10 20:52:46 +000041 // FIXME: We should use GetMainExecutable here, probably, but we may
42 // want to handle symbolic links slightly differently. The problem
43 // is that the path derived from this will influence search paths.
44 llvm::sys::Path Path(argv[0]);
45
Daniel Dunbard25acaa2009-03-10 23:41:59 +000046 // FIXME: Use the triple of the host, not the triple that we were
47 // compiled on.
Daniel Dunbarb282ced2009-03-10 20:52:46 +000048 llvm::OwningPtr<Driver> TheDriver(new Driver(Path.getBasename().c_str(),
Daniel Dunbard25acaa2009-03-10 23:41:59 +000049 Path.getDirname().c_str(),
Daniel Dunbar93468492009-03-12 08:55:43 +000050 LLVM_HOSTTRIPLE,
Daniel Dunbar7ce6add2009-03-16 06:56:51 +000051 "a.out",
Daniel Dunbar93468492009-03-12 08:55:43 +000052 Diags));
53
Daniel Dunbar63c4da92009-03-02 19:59:07 +000054 llvm::OwningPtr<Compilation> C(TheDriver->BuildCompilation(argc, argv));
55
Daniel Dunbar93468492009-03-12 08:55:43 +000056 // If there were errors building the compilation, quit now.
57 if (Diags.getNumErrors())
58 return 1;
Daniel Dunbar88c9eae2009-03-13 17:24:34 +000059 if (!C.get())
60 return 0;
Daniel Dunbar93468492009-03-12 08:55:43 +000061
Daniel Dunbar16e04ff2009-03-18 01:38:48 +000062 int res = C->Execute();
63
64 llvm::llvm_shutdown();
65
66 return res;
Daniel Dunbar63c4da92009-03-02 19:59:07 +000067}