blob: 65f5e114551bed4ae2ab89847fba347cfb1fc43b [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 Glushenkov0d08db02008-05-06 16:35:25 +000031// Built-in command-line options.
Mikhail Glushenkovb90cd832008-05-06 16:34:12 +000032// External linkage here is intentional.
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +000033
34cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input file>"),
35 cl::OneOrMore);
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000036cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),
37 cl::value_desc("file"));
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +000038cl::opt<bool> VerboseMode("v",
39 cl::desc("Enable verbose mode"));
40cl::opt<bool> WriteGraph("write-graph",
41 cl::desc("Write CompilationGraph.dot file"),
42 cl::Hidden);
43cl::opt<bool> ViewGraph("view-graph",
44 cl::desc("Show compilation graph in GhostView"),
45 cl::Hidden);
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000046
47namespace {
48 int BuildTargets(const CompilationGraph& graph) {
49 int ret;
50 sys::Path tempDir(sys::Path::GetTemporaryDirectory());
51
52 try {
53 ret = graph.Build(tempDir);
54 }
55 catch(...) {
56 tempDir.eraseFromDisk(true);
57 throw;
58 }
59
60 tempDir.eraseFromDisk(true);
61 return ret;
62 }
63}
64
65int main(int argc, char** argv) {
66 try {
67 CompilationGraph graph;
68
69 cl::ParseCommandLineOptions(argc, argv,
70 "LLVM Compiler Driver(Work In Progress)");
71 PopulateCompilationGraph(graph);
Mikhail Glushenkov0d08db02008-05-06 16:35:25 +000072
73 if(WriteGraph)
74 graph.writeGraph();
75 if(ViewGraph)
76 graph.viewGraph();
77
Anton Korobeynikovac67b7e2008-03-23 08:57:20 +000078 return BuildTargets(graph);
79 }
80 catch(const std::exception& ex) {
81 std::cerr << ex.what() << '\n';
82 }
83 catch(...) {
84 std::cerr << "Unknown error!\n";
85 }
86}