1 //===--- llvmc.cpp - The LLVM Compiler Driver ------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open
6 // Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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.
15 //===----------------------------------------------------------------------===//
17 #include "CompilationGraph.h"
21 #include "llvm/System/Path.h"
22 #include "llvm/Support/CommandLine.h"
28 namespace cl = llvm::cl;
29 namespace sys = llvm::sys;
30 using namespace llvmc;
32 // Built-in command-line options.
33 // External linkage here is intentional.
35 cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input file>"),
37 cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),
38 cl::value_desc("file"));
39 cl::list<std::string> Languages("x",
40 cl::desc("Specify the language of the following input files"),
42 cl::opt<bool> VerboseMode("v",
43 cl::desc("Enable verbose mode"));
44 cl::opt<bool> WriteGraph("write-graph",
45 cl::desc("Write compilation-graph.dot file"),
47 cl::opt<bool> ViewGraph("view-graph",
48 cl::desc("Show compilation graph in GhostView"),
52 /// BuildTargets - A small wrapper for CompilationGraph::Build.
53 int BuildTargets(CompilationGraph& graph) {
55 sys::Path tempDir(sys::Path::GetTemporaryDirectory());
58 ret = graph.Build(tempDir);
61 tempDir.eraseFromDisk(true);
65 tempDir.eraseFromDisk(true);
70 int main(int argc, char** argv) {
72 CompilationGraph graph;
74 cl::ParseCommandLineOptions
75 (argc, argv, "LLVM Compiler Driver (Work In Progress)", true);
76 PopulateCompilationGraph(graph);
89 if (InputFilenames.empty()) {
90 std::cerr << "No input files.\n";
94 return BuildTargets(graph);
96 catch(llvmc::error_code& ec) {
99 catch(const std::exception& ex) {
100 std::cerr << ex.what() << '\n';
103 std::cerr << "Unknown error!\n";