1 //===--- llvmc.cpp - The LLVM Compiler Driver -----------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by Reid Spencerand is distributed under the
6 // University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This tool provides a single point of access to the LLVM compilation tools.
11 // It has many options. To discover the options supported please refer to the
12 // tools' manual page (docs/CommandGuide/html/llvmc.html) or run the tool with
15 //===------------------------------------------------------------------------===
17 #include "llvm/Driver/CompilerDriver.h"
18 #include "llvm/System/Signals.h"
19 #include "Support/CommandLine.h"
24 //===------------------------------------------------------------------------===
26 //===------------------------------------------------------------------------===
27 static cl::opt<CompilerDriver::Phases> FinalPhase(
28 cl::desc("Choose final phase of compilation:"),
30 clEnumValN(CompilerDriver::PREPROCESSING,"E",
31 "Stop compilation after pre-processing"),
32 clEnumValN(CompilerDriver::OPTIMIZATION,"c",
33 "Stop compilation after source code translation and optimization"),
34 clEnumValN(CompilerDriver::ASSEMBLY,"S",
35 "Stop compilation after assembly"),
40 //===------------------------------------------------------------------------===
41 //=== OPTIMIZATION OPTIONS
42 //===------------------------------------------------------------------------===
43 static cl::opt<CompilerDriver::OptimizationLevels> OptLevel(
44 cl::desc("Choose level of optimization to apply:"),
46 clEnumValN(CompilerDriver::OPT_FAST_COMPILE,"O0",
47 "Optimize for compilation speed, not execution speed."),
48 clEnumValN(CompilerDriver::OPT_FAST_COMPILE,"O1",
49 "Optimize for compilation speed, not execution speed."),
50 clEnumValN(CompilerDriver::OPT_SIMPLE,"O2",
51 "Perform simple translation time optimizations"),
52 clEnumValN(CompilerDriver::OPT_AGGRESSIVE,"O3",
53 "Perform aggressive translation time optimizations"),
54 clEnumValN(CompilerDriver::OPT_LINK_TIME,"O4",
55 "Perform link time optimizations"),
56 clEnumValN(CompilerDriver::OPT_AGGRESSIVE_LINK_TIME,"O5",
57 "Perform aggressive link time optimizations"),
62 //===------------------------------------------------------------------------===
64 //===------------------------------------------------------------------------===
66 static cl::opt<std::string> PPToolOpts("Tpp", cl::ZeroOrMore,
67 cl::desc("Pass specific options to the pre-processor"));
69 static cl::opt<std::string> AsmToolOpts("Tasm", cl::ZeroOrMore,
70 cl::desc("Pass specific options to the assembler"));
72 static cl::opt<std::string> OptToolOpts("Topt", cl::ZeroOrMore,
73 cl::desc("Pass specific options to the optimizer"));
75 static cl::opt<std::string> LinkToolOpts("Tlink", cl::ZeroOrMore,
76 cl::desc("Pass specific options to the linker"));
78 //===------------------------------------------------------------------------===
80 //===------------------------------------------------------------------------===
82 static cl::list<std::string> LibPaths("L", cl::Prefix,
83 cl::desc("Specify a library search path"), cl::value_desc("directory"));
85 static cl::list<std::string> Libraries("l", cl::Prefix,
86 cl::desc("Specify libraries to link to"), cl::value_desc("library prefix"));
89 //===------------------------------------------------------------------------===
91 //===------------------------------------------------------------------------===
93 static cl::opt<std::string> OutputFilename("o", cl::init("a.out"),
94 cl::desc("Override output filename"), cl::value_desc("filename"));
96 static cl::opt<std::string> OutputMachne("m", cl::Prefix,
97 cl::desc("Specify a target machine"), cl::value_desc("machine"));
99 static cl::opt<bool> Native("native",
100 cl::desc("Generative native object and executables instead of bytecode"));
102 //===------------------------------------------------------------------------===
103 //=== INFORMATION OPTIONS
104 //===------------------------------------------------------------------------===
106 static cl::opt<bool> NoOperation("no-operation", cl::Optional,
107 cl::desc("Do not perform actions"));
109 static cl::alias NoOp("n", cl::Optional,
110 cl::desc("Alias for -no-operation"), cl::aliasopt(NoOperation));
112 static cl::opt<bool> Verbose("verbose", cl::Optional,
113 cl::desc("Print out each action taken"));
115 static cl::alias VerboseAlias("v", cl::Optional,
116 cl::desc("Alias for -verbose"), cl::aliasopt(Verbose));
118 static cl::opt<bool> TimeActions("time-actions", cl::Optional,
119 cl::desc("Print execution time for each action taken"));
121 //===------------------------------------------------------------------------===
122 //=== ADVANCED OPTIONS
123 //===------------------------------------------------------------------------===
125 static cl::list<std::string> ConfigFiles("config-dir", cl::Optional,
126 cl::desc("Specify a configuration directory to override defaults"));
128 static cl::opt<bool> EmitRawCode("emit-raw-code", cl::Hidden,
129 cl::desc("Emit raw, unoptimized code"));
131 //===------------------------------------------------------------------------===
132 //=== POSITIONAL OPTIONS
133 //===------------------------------------------------------------------------===
135 static cl::list<std::string> Files(cl::Positional, cl::OneOrMore,
136 cl::desc("Source and object files"));
139 /// @brief The main program for llvmc
140 int main(int argc, char **argv) {
141 // Make sure we print stack trace if we get bad signals
142 PrintStackTraceOnErrorSignal();
144 // Parse the command line options
145 cl::ParseCommandLineOptions(argc, argv,
146 " LLVM Compilation Driver (llvmc)\n\n"
147 " This program provides easy invocation of the LLVM tool set\n"
148 " and source language compiler tools.\n"
151 // Construct the CompilerDriver object
154 // Set the options for the Compiler Driver
156 // Tell the driver to do its thing
158 // result = CD.execute();
160 std::cerr << argv[0] << ": Error executing actions. Terminated.\n";
164 // All is good, return success