blob: 989a416ad82af655c4dc18181cf2993e4ff76703 [file] [log] [blame]
Reid Spencer034a5442004-08-10 16:26:01 +00001//===--- llvmc.cpp - The LLVM Compiler Driver -----------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Reid Spencerand is distributed under the
6// University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
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
13// the --help option.
14//
15//===------------------------------------------------------------------------===
16
17#include "llvm/Driver/CompilerDriver.h"
18#include "llvm/System/Signals.h"
19#include "Support/CommandLine.h"
20#include <iostream>
21
22using namespace llvm;
23
24//===------------------------------------------------------------------------===
25//=== PHASE OPTIONS
26//===------------------------------------------------------------------------===
27static cl::opt<CompilerDriver::Phases> FinalPhase(
28 cl::desc("Choose final phase of compilation:"),
29 cl::values(
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"),
36 clEnumValEnd
37 )
38);
39
40//===------------------------------------------------------------------------===
41//=== OPTIMIZATION OPTIONS
42//===------------------------------------------------------------------------===
43static cl::opt<CompilerDriver::OptimizationLevels> OptLevel(
44 cl::desc("Choose level of optimization to apply:"),
45 cl::values(
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"),
58 clEnumValEnd
59 )
60);
61
62//===------------------------------------------------------------------------===
63//=== TOOL OPTIONS
64//===------------------------------------------------------------------------===
65
66static cl::opt<std::string> PPToolOpts("Tpp", cl::ZeroOrMore,
67 cl::desc("Pass specific options to the pre-processor"));
68
69static cl::opt<std::string> AsmToolOpts("Tasm", cl::ZeroOrMore,
70 cl::desc("Pass specific options to the assembler"));
71
72static cl::opt<std::string> OptToolOpts("Topt", cl::ZeroOrMore,
73 cl::desc("Pass specific options to the optimizer"));
74
75static cl::opt<std::string> LinkToolOpts("Tlink", cl::ZeroOrMore,
76 cl::desc("Pass specific options to the linker"));
77
78//===------------------------------------------------------------------------===
79//=== INPUT OPTIONS
80//===------------------------------------------------------------------------===
81
82static cl::list<std::string> LibPaths("L", cl::Prefix,
83 cl::desc("Specify a library search path"), cl::value_desc("directory"));
84
85static cl::list<std::string> Libraries("l", cl::Prefix,
86 cl::desc("Specify libraries to link to"), cl::value_desc("library prefix"));
87
88
89//===------------------------------------------------------------------------===
90//=== OUTPUT OPTIONS
91//===------------------------------------------------------------------------===
92
93static cl::opt<std::string> OutputFilename("o", cl::init("a.out"),
94 cl::desc("Override output filename"), cl::value_desc("filename"));
95
96static cl::opt<std::string> OutputMachne("m", cl::Prefix,
97 cl::desc("Specify a target machine"), cl::value_desc("machine"));
98
99static cl::opt<bool> Native("native",
100 cl::desc("Generative native object and executables instead of bytecode"));
101
102//===------------------------------------------------------------------------===
103//=== INFORMATION OPTIONS
104//===------------------------------------------------------------------------===
105
106static cl::opt<bool> NoOperation("no-operation", cl::Optional,
107 cl::desc("Do not perform actions"));
108
109static cl::alias NoOp("n", cl::Optional,
110 cl::desc("Alias for -no-operation"), cl::aliasopt(NoOperation));
111
112static cl::opt<bool> Verbose("verbose", cl::Optional,
113 cl::desc("Print out each action taken"));
114
115static cl::alias VerboseAlias("v", cl::Optional,
116 cl::desc("Alias for -verbose"), cl::aliasopt(Verbose));
117
118static cl::opt<bool> TimeActions("time-actions", cl::Optional,
119 cl::desc("Print execution time for each action taken"));
120
121//===------------------------------------------------------------------------===
122//=== ADVANCED OPTIONS
123//===------------------------------------------------------------------------===
124
125static cl::list<std::string> ConfigFiles("config-dir", cl::Optional,
126 cl::desc("Specify a configuration directory to override defaults"));
127
128static cl::opt<bool> EmitRawCode("emit-raw-code", cl::Hidden,
129 cl::desc("Emit raw, unoptimized code"));
130
131//===------------------------------------------------------------------------===
132//=== POSITIONAL OPTIONS
133//===------------------------------------------------------------------------===
134
135static cl::list<std::string> Files(cl::Positional, cl::OneOrMore,
136 cl::desc("Source and object files"));
137
138
139/// @brief The main program for llvmc
140int main(int argc, char **argv) {
141 // Make sure we print stack trace if we get bad signals
142 PrintStackTraceOnErrorSignal();
143
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"
149 );
150
151 // Construct the CompilerDriver object
152 //CompilerDriver CD;
153
154 // Set the options for the Compiler Driver
155
156 // Tell the driver to do its thing
157 int result = 0;
158 // result = CD.execute();
159 if (result != 0) {
160 std::cerr << argv[0] << ": Error executing actions. Terminated.\n";
161 return result;
162 }
163
164 // All is good, return success
165 return 0;
166}
167