1 //===--- Main.inc - 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.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
20 #define LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC
22 #include "llvm/CompilerDriver/CompilationGraph.h"
23 #include "llvm/CompilerDriver/Error.h"
24 #include "llvm/CompilerDriver/Plugin.h"
26 #include "llvm/System/Path.h"
27 #include "llvm/Support/CommandLine.h"
28 #include "llvm/Support/PluginLoader.h"
34 namespace cl = llvm::cl;
35 namespace sys = llvm::sys;
36 using namespace llvmc;
38 // Built-in command-line options.
39 // External linkage here is intentional.
41 cl::list<std::string> InputFilenames(cl::Positional, cl::desc("<input file>"),
43 cl::opt<std::string> OutputFilename("o", cl::desc("Output file name"),
44 cl::value_desc("file"), cl::Prefix);
45 cl::list<std::string> Languages("x",
46 cl::desc("Specify the language of the following input files"),
48 cl::opt<bool> DryRun("dry-run",
49 cl::desc("Only pretend to run commands"));
50 cl::opt<bool> VerboseMode("v",
51 cl::desc("Enable verbose mode"));
53 cl::opt<bool> CheckGraph("check-graph",
54 cl::desc("Check the compilation graph for errors"),
56 cl::opt<bool> WriteGraph("write-graph",
57 cl::desc("Write compilation-graph.dot file"),
59 cl::opt<bool> ViewGraph("view-graph",
60 cl::desc("Show compilation graph in GhostView"),
62 cl::opt<bool> SaveTemps("save-temps",
63 cl::desc("Keep temporary files"),
67 /// BuildTargets - A small wrapper for CompilationGraph::Build.
68 int BuildTargets(CompilationGraph& graph, const LanguageMap& langMap) {
70 const sys::Path& tempDir = SaveTemps
72 : sys::Path(sys::Path::GetTemporaryDirectory());
75 ret = graph.Build(tempDir, langMap);
78 tempDir.eraseFromDisk(true);
83 tempDir.eraseFromDisk(true);
88 int main(int argc, char** argv) {
91 CompilationGraph graph;
93 cl::ParseCommandLineOptions
94 (argc, argv, "LLVM Compiler Driver (Work In Progress)", true);
97 Plugins.PopulateLanguageMap(langMap);
98 Plugins.PopulateCompilationGraph(graph);
101 int ret = graph.Check();
103 std::cerr << "check-graph: no errors found.\n";
115 graph.writeGraph(OutputFilename.empty()
116 ? std::string("compilation-graph.dot")
121 if (InputFilenames.empty()) {
122 throw std::runtime_error("no input files");
125 return BuildTargets(graph, langMap);
127 catch(llvmc::error_code& ec) {
130 catch(const std::exception& ex) {
131 std::cerr << argv[0] << ": " << ex.what() << '\n';
134 std::cerr << argv[0] << ": unknown error!\n";
139 #endif // LLVM_INCLUDE_COMPILER_DRIVER_MAIN_INC