blob: feed61f89f1156f5d37fc2b3958e2bf50d813621 [file] [log] [blame]
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +00001//===--- llvmcc.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open
6// Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This tool provides a single point of access to the LLVM
11// compilation tools. It has many options. To discover the options
12// supported please refer to the tools' manual page or run the tool
13// with the --help option.
14//
15//===----------------------------------------------------------------------===//
16
Mikhail Glushenkovb90cd832008-05-06 16:34:12 +000017#include "CompilationGraph.h"
18#include "Tool.h"
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000019
20#include "llvm/System/Path.h"
21#include "llvm/Support/CommandLine.h"
22
23#include <iostream>
24#include <stdexcept>
25#include <string>
26
Mikhail Glushenkovb90cd832008-05-06 16:34:12 +000027namespace cl = llvm::cl;
28namespace sys = llvm::sys;
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000029using namespace llvmcc;
30
Mikhail Glushenkovb90cd832008-05-06 16:34:12 +000031// External linkage here is intentional.
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000032cl::list<std::string> InputFilenames(cl::Positional,
33 cl::desc("<input file>"), cl::OneOrMore);
34cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),
35 cl::value_desc("file"));
36cl::opt<bool> VerboseMode("v", cl::desc("Enable verbose mode"));
37
38
39namespace {
40 int BuildTargets(const CompilationGraph& graph) {
41 int ret;
42 sys::Path tempDir(sys::Path::GetTemporaryDirectory());
43
44 try {
45 ret = graph.Build(tempDir);
46 }
47 catch(...) {
48 tempDir.eraseFromDisk(true);
49 throw;
50 }
51
52 tempDir.eraseFromDisk(true);
53 return ret;
54 }
55}
56
57int main(int argc, char** argv) {
58 try {
59 CompilationGraph graph;
60
61 cl::ParseCommandLineOptions(argc, argv,
62 "LLVM Compiler Driver(Work In Progress)");
63 PopulateCompilationGraph(graph);
64 return BuildTargets(graph);
65 }
66 catch(const std::exception& ex) {
67 std::cerr << ex.what() << '\n';
68 }
69 catch(...) {
70 std::cerr << "Unknown error!\n";
71 }
72}