blob: 1a316c84390bbb471b9f35ede6495096a50257f1 [file] [log] [blame]
Reid Spencera3f18552004-08-13 20:25:54 +00001//===- CompilerDriver.cpp - The LLVM Compiler Driver ------------*- C++ -*-===//
Reid Spencer5c56dc12004-08-13 20:22:43 +00002//
3//
4// The LLVM Compiler Infrastructure
5//
6// This file was developed by Reid Spencer and is distributed under the
7// University of Illinois Open Source License. See LICENSE.TXT for details.
8//
9//===----------------------------------------------------------------------===//
10//
Reid Spencera3f18552004-08-13 20:25:54 +000011// This file implements the bulk of the LLVM Compiler Driver (llvmc).
Reid Spencer5c56dc12004-08-13 20:22:43 +000012//
13//===------------------------------------------------------------------------===
14
15#include "CompilerDriver.h"
Reid Spencerbf437722004-08-15 08:19:46 +000016#include "ConfigLexer.h"
Reid Spencera01439a2004-08-24 13:55:17 +000017#include "llvm/Module.h"
Reid Spencer52c2dc12004-08-29 19:26:56 +000018#include "llvm/Bytecode/Reader.h"
Reid Spencer54fafe42004-09-14 01:58:45 +000019#include "llvm/Support/Timer.h"
Reid Spencer93426ba2004-08-29 20:02:28 +000020#include "llvm/System/Signals.h"
Reid Spencer551ccae2004-09-01 22:55:40 +000021#include "llvm/ADT/SetVector.h"
22#include "llvm/ADT/StringExtras.h"
Reid Spencer5c56dc12004-08-13 20:22:43 +000023#include <iostream>
Brian Gaekefabf41f2004-12-20 04:02:01 +000024#include "llvm/Config/alloca.h"
Reid Spencer5c56dc12004-08-13 20:22:43 +000025
26using namespace llvm;
27
28namespace {
Reid Spencer5c56dc12004-08-13 20:22:43 +000029
Reid Spenceraf77d742004-10-28 04:05:06 +000030void WriteAction(CompilerDriver::Action* action ) {
31 std::cerr << action->program.c_str();
Reid Spencerf6358c72004-12-19 18:00:56 +000032 std::vector<std::string>::const_iterator I = action->args.begin();
Reid Spenceraf77d742004-10-28 04:05:06 +000033 while (I != action->args.end()) {
Reid Spencerf6358c72004-12-19 18:00:56 +000034 std::cerr << " " << *I;
Reid Spenceraf77d742004-10-28 04:05:06 +000035 ++I;
36 }
37 std::cerr << "\n";
38}
39
40void DumpAction(CompilerDriver::Action* action) {
41 std::cerr << "command = " << action->program.c_str();
Reid Spencerf6358c72004-12-19 18:00:56 +000042 std::vector<std::string>::const_iterator I = action->args.begin();
Reid Spenceraf77d742004-10-28 04:05:06 +000043 while (I != action->args.end()) {
Reid Spencerf6358c72004-12-19 18:00:56 +000044 std::cerr << " " << *I;
Reid Spenceraf77d742004-10-28 04:05:06 +000045 ++I;
46 }
47 std::cerr << "\n";
48 std::cerr << "flags = " << action->flags << "\n";
49}
50
51void DumpConfigData(CompilerDriver::ConfigData* cd, const std::string& type ){
52 std::cerr << "Configuration Data For '" << cd->langName << "' (" << type
53 << ")\n";
54 std::cerr << "PreProcessor: ";
55 DumpAction(&cd->PreProcessor);
56 std::cerr << "Translator: ";
57 DumpAction(&cd->Translator);
58 std::cerr << "Optimizer: ";
59 DumpAction(&cd->Optimizer);
60 std::cerr << "Assembler: ";
61 DumpAction(&cd->Assembler);
62 std::cerr << "Linker: ";
63 DumpAction(&cd->Linker);
64}
65
66/// This specifies the passes to run for OPT_FAST_COMPILE (-O1)
67/// which should reduce the volume of code and make compilation
68/// faster. This is also safe on any llvm module.
69static const char* DefaultFastCompileOptimizations[] = {
70 "-simplifycfg", "-mem2reg", "-instcombine"
71};
72
73class CompilerDriverImpl : public CompilerDriver {
74/// @name Constructors
75/// @{
76public:
77 CompilerDriverImpl(ConfigDataProvider& confDatProv )
78 : cdp(&confDatProv)
79 , finalPhase(LINKING)
80 , optLevel(OPT_FAST_COMPILE)
81 , Flags(0)
82 , machine()
83 , LibraryPaths()
84 , TempDir()
85 , AdditionalArgs()
86 {
87 TempDir = sys::Path::GetTemporaryDirectory();
88 sys::RemoveDirectoryOnSignal(TempDir);
89 AdditionalArgs.reserve(NUM_PHASES);
90 StringVector emptyVec;
91 for (unsigned i = 0; i < NUM_PHASES; ++i)
92 AdditionalArgs.push_back(emptyVec);
93 }
94
95 virtual ~CompilerDriverImpl() {
96 cleanup();
97 cdp = 0;
98 LibraryPaths.clear();
99 IncludePaths.clear();
100 Defines.clear();
101 TempDir.clear();
102 AdditionalArgs.clear();
103 fOptions.clear();
104 MOptions.clear();
105 WOptions.clear();
106 }
107
108/// @}
109/// @name Methods
110/// @{
111public:
112 virtual void setFinalPhase( Phases phase ) {
113 finalPhase = phase;
114 }
115
116 virtual void setOptimization( OptimizationLevels level ) {
117 optLevel = level;
118 }
119
120 virtual void setDriverFlags( unsigned flags ) {
121 Flags = flags & DRIVER_FLAGS_MASK;
122 }
123
124 virtual void setOutputMachine( const std::string& machineName ) {
125 machine = machineName;
126 }
127
128 virtual void setPhaseArgs(Phases phase, const StringVector& opts) {
129 assert(phase <= LINKING && phase >= PREPROCESSING);
130 AdditionalArgs[phase] = opts;
131 }
132
133 virtual void setIncludePaths(const StringVector& paths) {
134 StringVector::const_iterator I = paths.begin();
135 StringVector::const_iterator E = paths.end();
136 while (I != E) {
137 sys::Path tmp;
Reid Spencer07adb282004-11-05 22:15:36 +0000138 tmp.setDirectory(*I);
Reid Spenceraf77d742004-10-28 04:05:06 +0000139 IncludePaths.push_back(tmp);
Reid Spencer68fb37a2004-08-14 09:37:15 +0000140 ++I;
141 }
Reid Spencer68fb37a2004-08-14 09:37:15 +0000142 }
143
Reid Spenceraf77d742004-10-28 04:05:06 +0000144 virtual void setSymbolDefines(const StringVector& defs) {
145 Defines = defs;
146 }
147
148 virtual void setLibraryPaths(const StringVector& paths) {
149 StringVector::const_iterator I = paths.begin();
150 StringVector::const_iterator E = paths.end();
151 while (I != E) {
152 sys::Path tmp;
Reid Spencer07adb282004-11-05 22:15:36 +0000153 tmp.setDirectory(*I);
Reid Spenceraf77d742004-10-28 04:05:06 +0000154 LibraryPaths.push_back(tmp);
Reid Spencerbf437722004-08-15 08:19:46 +0000155 ++I;
156 }
Reid Spencerbf437722004-08-15 08:19:46 +0000157 }
158
Reid Spenceraf77d742004-10-28 04:05:06 +0000159 virtual void addLibraryPath( const sys::Path& libPath ) {
160 LibraryPaths.push_back(libPath);
Reid Spencer68fb37a2004-08-14 09:37:15 +0000161 }
Reid Spencer5c56dc12004-08-13 20:22:43 +0000162
Reid Spencer07adb282004-11-05 22:15:36 +0000163 virtual void addToolPath( const sys::Path& toolPath ) {
164 ToolPaths.push_back(toolPath);
165 }
166
Reid Spenceraf77d742004-10-28 04:05:06 +0000167 virtual void setfPassThrough(const StringVector& fOpts) {
168 fOptions = fOpts;
169 }
Reid Spencer5c56dc12004-08-13 20:22:43 +0000170
Reid Spenceraf77d742004-10-28 04:05:06 +0000171 /// @brief Set the list of -M options to be passed through
172 virtual void setMPassThrough(const StringVector& MOpts) {
173 MOptions = MOpts;
174 }
Reid Spencerbae68252004-08-19 04:49:47 +0000175
Reid Spenceraf77d742004-10-28 04:05:06 +0000176 /// @brief Set the list of -W options to be passed through
177 virtual void setWPassThrough(const StringVector& WOpts) {
178 WOptions = WOpts;
179 }
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000180
Reid Spenceraf77d742004-10-28 04:05:06 +0000181/// @}
182/// @name Functions
183/// @{
184private:
185 bool isSet(DriverFlags flag) {
186 return 0 != ((flag & DRIVER_FLAGS_MASK) & Flags);
187 }
Reid Spencerbae68252004-08-19 04:49:47 +0000188
Reid Spenceraf77d742004-10-28 04:05:06 +0000189 void cleanup() {
190 if (!isSet(KEEP_TEMPS_FLAG)) {
Reid Spencer07adb282004-11-05 22:15:36 +0000191 if (TempDir.isDirectory() && TempDir.writable())
192 TempDir.destroyDirectory(/*remove_contents=*/true);
Reid Spenceraf77d742004-10-28 04:05:06 +0000193 } else {
Reid Spencer12786d52004-12-13 08:53:36 +0000194 std::cout << "Temporary files are in " << TempDir << "\n";
Reid Spenceraf77d742004-10-28 04:05:06 +0000195 }
196 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000197
Reid Spenceraf77d742004-10-28 04:05:06 +0000198 sys::Path MakeTempFile(const std::string& basename,
199 const std::string& suffix ) {
200 sys::Path result(TempDir);
Reid Spencer07adb282004-11-05 22:15:36 +0000201 if (!result.appendFile(basename))
Reid Spenceraf77d742004-10-28 04:05:06 +0000202 throw basename + ": can't use this file name";
Reid Spencer07adb282004-11-05 22:15:36 +0000203 if (!result.appendSuffix(suffix))
Reid Spenceraf77d742004-10-28 04:05:06 +0000204 throw suffix + ": can't use this file suffix";
205 return result;
206 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000207
Reid Spenceraf77d742004-10-28 04:05:06 +0000208 Action* GetAction(ConfigData* cd,
209 const sys::Path& input,
210 const sys::Path& output,
211 Phases phase)
212 {
213 Action* pat = 0; ///< The pattern/template for the action
214 Action* action = new Action; ///< The actual action to execute
Reid Spencer52c2dc12004-08-29 19:26:56 +0000215
Reid Spenceraf77d742004-10-28 04:05:06 +0000216 // Get the action pattern
217 switch (phase) {
218 case PREPROCESSING: pat = &cd->PreProcessor; break;
219 case TRANSLATION: pat = &cd->Translator; break;
220 case OPTIMIZATION: pat = &cd->Optimizer; break;
221 case ASSEMBLY: pat = &cd->Assembler; break;
222 case LINKING: pat = &cd->Linker; break;
223 default:
224 assert(!"Invalid driver phase!");
225 break;
226 }
227 assert(pat != 0 && "Invalid command pattern");
Reid Spencer52c2dc12004-08-29 19:26:56 +0000228
Reid Spenceraf77d742004-10-28 04:05:06 +0000229 // Copy over some pattern things that don't need to change
230 action->program = pat->program;
231 action->flags = pat->flags;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000232
Reid Spenceraf77d742004-10-28 04:05:06 +0000233 // Do the substitutions from the pattern to the actual
234 StringVector::iterator PI = pat->args.begin();
235 StringVector::iterator PE = pat->args.end();
236 while (PI != PE) {
237 if ((*PI)[0] == '%' && PI->length() >2) {
238 bool found = true;
239 switch ((*PI)[1]) {
240 case 'a':
241 if (*PI == "%args%") {
242 if (AdditionalArgs.size() > unsigned(phase))
243 if (!AdditionalArgs[phase].empty()) {
244 // Get specific options for each kind of action type
245 StringVector& addargs = AdditionalArgs[phase];
246 // Add specific options for each kind of action type
247 action->args.insert(action->args.end(), addargs.begin(),
248 addargs.end());
249 }
250 } else
251 found = false;
252 break;
253 case 'd':
254 if (*PI == "%defs%") {
255 StringVector::iterator I = Defines.begin();
256 StringVector::iterator E = Defines.end();
257 while (I != E) {
258 action->args.push_back( std::string("-D") + *I);
259 ++I;
260 }
261 } else
262 found = false;
263 break;
264 case 'f':
265 if (*PI == "%fOpts%") {
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000266 if (!fOptions.empty())
267 action->args.insert(action->args.end(), fOptions.begin(),
268 fOptions.end());
Reid Spenceraf77d742004-10-28 04:05:06 +0000269 } else
270 found = false;
271 break;
272 case 'i':
273 if (*PI == "%in%") {
Reid Spencer1fce0912004-12-11 00:14:15 +0000274 action->args.push_back(input.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000275 } else if (*PI == "%incls%") {
276 PathVector::iterator I = IncludePaths.begin();
277 PathVector::iterator E = IncludePaths.end();
278 while (I != E) {
Reid Spencer1fce0912004-12-11 00:14:15 +0000279 action->args.push_back( std::string("-I") + I->toString() );
Reid Spenceraf77d742004-10-28 04:05:06 +0000280 ++I;
281 }
282 } else
283 found = false;
284 break;
285 case 'l':
286 if (*PI == "%libs%") {
287 PathVector::iterator I = LibraryPaths.begin();
288 PathVector::iterator E = LibraryPaths.end();
289 while (I != E) {
Reid Spencer1fce0912004-12-11 00:14:15 +0000290 action->args.push_back( std::string("-L") + I->toString() );
Reid Spenceraf77d742004-10-28 04:05:06 +0000291 ++I;
292 }
293 } else
294 found = false;
295 break;
296 case 'o':
297 if (*PI == "%out%") {
Reid Spencer1fce0912004-12-11 00:14:15 +0000298 action->args.push_back(output.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000299 } else if (*PI == "%opt%") {
300 if (!isSet(EMIT_RAW_FLAG)) {
301 if (cd->opts.size() > static_cast<unsigned>(optLevel) &&
302 !cd->opts[optLevel].empty())
303 action->args.insert(action->args.end(),
304 cd->opts[optLevel].begin(),
305 cd->opts[optLevel].end());
306 else
307 throw std::string("Optimization options for level ") +
308 utostr(unsigned(optLevel)) + " were not specified";
309 }
310 } else
311 found = false;
312 break;
313 case 's':
314 if (*PI == "%stats%") {
315 if (isSet(SHOW_STATS_FLAG))
316 action->args.push_back("-stats");
317 } else
318 found = false;
319 break;
320 case 't':
321 if (*PI == "%target%") {
322 action->args.push_back(std::string("-march=") + machine);
323 } else if (*PI == "%time%") {
324 if (isSet(TIME_PASSES_FLAG))
325 action->args.push_back("-time-passes");
326 } else
327 found = false;
328 break;
329 case 'v':
330 if (*PI == "%verbose%") {
331 if (isSet(VERBOSE_FLAG))
332 action->args.push_back("-v");
333 } else
334 found = false;
335 break;
336 case 'M':
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000337 if (*PI == "%Mopts%") {
338 if (!MOptions.empty())
339 action->args.insert(action->args.end(), MOptions.begin(),
340 MOptions.end());
Reid Spenceraf77d742004-10-28 04:05:06 +0000341 } else
342 found = false;
343 break;
344 case 'W':
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000345 if (*PI == "%Wopts%") {
346 for (StringVector::iterator I = WOptions.begin(),
347 E = WOptions.end(); I != E ; ++I ) {
348 action->args.push_back( std::string("-W") + *I );
349 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000350 } else
351 found = false;
352 break;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000353 default:
Reid Spenceraf77d742004-10-28 04:05:06 +0000354 found = false;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000355 break;
356 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000357 if (!found) {
358 // Did it even look like a substitution?
359 if (PI->length()>1 && (*PI)[0] == '%' &&
360 (*PI)[PI->length()-1] == '%') {
361 throw std::string("Invalid substitution token: '") + *PI +
Reid Spencer1fce0912004-12-11 00:14:15 +0000362 "' for command '" + pat->program.toString() + "'";
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000363 } else if (!PI->empty()) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000364 // It's not a legal substitution, just pass it through
Reid Spencer52c2dc12004-08-29 19:26:56 +0000365 action->args.push_back(*PI);
366 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000367 }
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000368 } else if (!PI->empty()) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000369 // Its not a substitution, just put it in the action
370 action->args.push_back(*PI);
Reid Spencer52c2dc12004-08-29 19:26:56 +0000371 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000372 PI++;
373 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000374
Reid Spenceraf77d742004-10-28 04:05:06 +0000375 // Finally, we're done
376 return action;
377 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000378
Reid Spenceraf77d742004-10-28 04:05:06 +0000379 bool DoAction(Action*action) {
380 assert(action != 0 && "Invalid Action!");
381 if (isSet(VERBOSE_FLAG))
382 WriteAction(action);
383 if (!isSet(DRY_RUN_FLAG)) {
384 sys::Path progpath = sys::Program::FindProgramByName(
Reid Spencer1fce0912004-12-11 00:14:15 +0000385 action->program.toString());
Reid Spencer07adb282004-11-05 22:15:36 +0000386 if (progpath.isEmpty())
Reid Spencer1fce0912004-12-11 00:14:15 +0000387 throw std::string("Can't find program '" +
388 action->program.toString()+"'");
Reid Spenceraf77d742004-10-28 04:05:06 +0000389 else if (progpath.executable())
390 action->program = progpath;
391 else
Reid Spencer1fce0912004-12-11 00:14:15 +0000392 throw std::string("Program '"+action->program.toString()+
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000393 "' is not executable.");
Reid Spenceraf77d742004-10-28 04:05:06 +0000394
395 // Invoke the program
Reid Spencerf6358c72004-12-19 18:00:56 +0000396 const char** Args = (const char**)
Reid Spencerc30088f2005-04-11 05:48:04 +0000397 alloca(sizeof(const char*)*(action->args.size()+2));
398 Args[0] = action->program.toString().c_str();
399 for (unsigned i = 1; i != action->args.size(); ++i)
Reid Spencerf6358c72004-12-19 18:00:56 +0000400 Args[i] = action->args[i].c_str();
Chris Lattner7456e3c2005-02-13 23:10:45 +0000401 Args[action->args.size()] = 0; // null terminate list.
Reid Spenceraf77d742004-10-28 04:05:06 +0000402 if (isSet(TIME_ACTIONS_FLAG)) {
Reid Spencer1fce0912004-12-11 00:14:15 +0000403 Timer timer(action->program.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000404 timer.startTimer();
Chris Lattner7456e3c2005-02-13 23:10:45 +0000405 int resultCode = sys::Program::ExecuteAndWait(action->program, Args);
Reid Spenceraf77d742004-10-28 04:05:06 +0000406 timer.stopTimer();
407 timer.print(timer,std::cerr);
408 return resultCode == 0;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000409 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000410 else
Chris Lattner7456e3c2005-02-13 23:10:45 +0000411 return 0 == sys::Program::ExecuteAndWait(action->program, Args);
Reid Spenceraf77d742004-10-28 04:05:06 +0000412 }
413 return true;
414 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000415
Reid Spenceraf77d742004-10-28 04:05:06 +0000416 /// This method tries various variants of a linkage item's file
417 /// name to see if it can find an appropriate file to link with
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000418 /// in the directories of the LibraryPaths.
Reid Spenceraf77d742004-10-28 04:05:06 +0000419 llvm::sys::Path GetPathForLinkageItem(const std::string& link_item,
Reid Spenceraf77d742004-10-28 04:05:06 +0000420 bool native = false) {
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000421 sys::Path fullpath;
422 fullpath.setFile(link_item);
423 if (fullpath.readable())
424 return fullpath;
425 for (PathVector::iterator PI = LibraryPaths.begin(),
426 PE = LibraryPaths.end(); PI != PE; ++PI) {
Reid Spencer1fce0912004-12-11 00:14:15 +0000427 fullpath.setDirectory(PI->toString());
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000428 fullpath.appendFile(link_item);
Reid Spenceraf77d742004-10-28 04:05:06 +0000429 if (fullpath.readable())
430 return fullpath;
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000431 if (native) {
432 fullpath.appendSuffix("a");
433 } else {
434 fullpath.appendSuffix("bc");
435 if (fullpath.readable())
436 return fullpath;
437 fullpath.elideSuffix();
438 fullpath.appendSuffix("o");
439 if (fullpath.readable())
440 return fullpath;
441 fullpath = *PI;
442 fullpath.appendFile(std::string("lib") + link_item);
443 fullpath.appendSuffix("a");
444 if (fullpath.readable())
445 return fullpath;
446 fullpath.elideSuffix();
447 fullpath.appendSuffix("so");
448 if (fullpath.readable())
449 return fullpath;
450 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000451 }
452
453 // Didn't find one.
454 fullpath.clear();
455 return fullpath;
456 }
457
458 /// This method processes a linkage item. The item could be a
459 /// Bytecode file needing translation to native code and that is
460 /// dependent on other bytecode libraries, or a native code
461 /// library that should just be linked into the program.
462 bool ProcessLinkageItem(const llvm::sys::Path& link_item,
463 SetVector<sys::Path>& set,
464 std::string& err) {
465 // First, see if the unadorned file name is not readable. If so,
466 // we must track down the file in the lib search path.
467 sys::Path fullpath;
468 if (!link_item.readable()) {
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000469 // look for the library using the -L arguments specified
Reid Spenceraf77d742004-10-28 04:05:06 +0000470 // on the command line.
Reid Spencer1fce0912004-12-11 00:14:15 +0000471 fullpath = GetPathForLinkageItem(link_item.toString());
Reid Spencer52c2dc12004-08-29 19:26:56 +0000472
Reid Spenceraf77d742004-10-28 04:05:06 +0000473 // If we didn't find the file in any of the library search paths
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000474 // we have to bail. No where else to look.
Reid Spencer07adb282004-11-05 22:15:36 +0000475 if (fullpath.isEmpty()) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000476 err =
Reid Spencer1fce0912004-12-11 00:14:15 +0000477 std::string("Can't find linkage item '") + link_item.toString() + "'";
Reid Spenceraf77d742004-10-28 04:05:06 +0000478 return false;
479 }
480 } else {
481 fullpath = link_item;
482 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000483
Reid Spenceraf77d742004-10-28 04:05:06 +0000484 // If we got here fullpath is the path to the file, and its readable.
485 set.insert(fullpath);
Reid Spencer52c2dc12004-08-29 19:26:56 +0000486
Reid Spenceraf77d742004-10-28 04:05:06 +0000487 // If its an LLVM bytecode file ...
Reid Spencer07adb282004-11-05 22:15:36 +0000488 if (fullpath.isBytecodeFile()) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000489 // Process the dependent libraries recursively
490 Module::LibraryListType modlibs;
Reid Spencer1fce0912004-12-11 00:14:15 +0000491 if (GetBytecodeDependentLibraries(fullpath.toString(),modlibs)) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000492 // Traverse the dependent libraries list
493 Module::lib_iterator LI = modlibs.begin();
494 Module::lib_iterator LE = modlibs.end();
495 while ( LI != LE ) {
496 if (!ProcessLinkageItem(sys::Path(*LI),set,err)) {
497 if (err.empty()) {
498 err = std::string("Library '") + *LI +
499 "' is not valid for linking but is required by file '" +
Reid Spencer1fce0912004-12-11 00:14:15 +0000500 fullpath.toString() + "'";
Reid Spenceraf77d742004-10-28 04:05:06 +0000501 } else {
Reid Spencer1fce0912004-12-11 00:14:15 +0000502 err += " which is required by file '" + fullpath.toString() + "'";
Reid Spencer52c2dc12004-08-29 19:26:56 +0000503 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000504 return false;
505 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000506 ++LI;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000507 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000508 } else if (err.empty()) {
509 err = std::string(
510 "The dependent libraries could not be extracted from '") +
Reid Spencer1fce0912004-12-11 00:14:15 +0000511 fullpath.toString();
Reid Spenceraf77d742004-10-28 04:05:06 +0000512 return false;
513 }
514 }
515 return true;
516 }
517
518/// @}
519/// @name Methods
520/// @{
521public:
522 virtual int execute(const InputList& InpList, const sys::Path& Output ) {
523 try {
524 // Echo the configuration of options if we're running verbose
525 if (isSet(DEBUG_FLAG)) {
526 std::cerr << "Compiler Driver Options:\n";
527 std::cerr << "DryRun = " << isSet(DRY_RUN_FLAG) << "\n";
528 std::cerr << "Verbose = " << isSet(VERBOSE_FLAG) << " \n";
529 std::cerr << "TimeActions = " << isSet(TIME_ACTIONS_FLAG) << "\n";
530 std::cerr << "TimePasses = " << isSet(TIME_PASSES_FLAG) << "\n";
531 std::cerr << "ShowStats = " << isSet(SHOW_STATS_FLAG) << "\n";
532 std::cerr << "EmitRawCode = " << isSet(EMIT_RAW_FLAG) << "\n";
533 std::cerr << "EmitNativeCode = " << isSet(EMIT_NATIVE_FLAG) << "\n";
534 std::cerr << "KeepTemps = " << isSet(KEEP_TEMPS_FLAG) << "\n";
535 std::cerr << "OutputMachine = " << machine << "\n";
536 InputList::const_iterator I = InpList.begin();
537 while ( I != InpList.end() ) {
Reid Spencer12786d52004-12-13 08:53:36 +0000538 std::cerr << "Input: " << I->first << "(" << I->second
Reid Spenceraf77d742004-10-28 04:05:06 +0000539 << ")\n";
540 ++I;
541 }
Reid Spencer12786d52004-12-13 08:53:36 +0000542 std::cerr << "Output: " << Output << "\n";
Reid Spencer52c2dc12004-08-29 19:26:56 +0000543 }
544
Reid Spenceraf77d742004-10-28 04:05:06 +0000545 // If there's no input, we're done.
546 if (InpList.empty())
547 throw std::string("Nothing to compile.");
Reid Spencer52c2dc12004-08-29 19:26:56 +0000548
Reid Spenceraf77d742004-10-28 04:05:06 +0000549 // If they are asking for linking and didn't provide an output
550 // file then its an error (no way for us to "make up" a meaningful
551 // file name based on the various linker input files).
Reid Spencer07adb282004-11-05 22:15:36 +0000552 if (finalPhase == LINKING && Output.isEmpty())
Reid Spenceraf77d742004-10-28 04:05:06 +0000553 throw std::string(
554 "An output file name must be specified for linker output");
Reid Spencer52c2dc12004-08-29 19:26:56 +0000555
Reid Spenceraf77d742004-10-28 04:05:06 +0000556 // If they are not asking for linking, provided an output file and
557 // there is more than one input file, its an error
Reid Spencer07adb282004-11-05 22:15:36 +0000558 if (finalPhase != LINKING && !Output.isEmpty() && InpList.size() > 1)
Reid Spenceraf77d742004-10-28 04:05:06 +0000559 throw std::string("An output file name cannot be specified ") +
560 "with more than one input file name when not linking";
561
562 // This vector holds all the resulting actions of the following loop.
563 std::vector<Action*> actions;
564
565 /// PRE-PROCESSING / TRANSLATION / OPTIMIZATION / ASSEMBLY phases
566 // for each input item
567 SetVector<sys::Path> LinkageItems;
Reid Spencerf6358c72004-12-19 18:00:56 +0000568 StringVector LibFiles;
Reid Spenceraf77d742004-10-28 04:05:06 +0000569 InputList::const_iterator I = InpList.begin();
Reid Spencer679a7232004-11-20 20:39:33 +0000570 for (InputList::const_iterator I = InpList.begin(), E = InpList.end();
571 I != E; ++I ) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000572 // Get the suffix of the file name
573 const std::string& ftype = I->second;
574
575 // If its a library, bytecode file, or object file, save
576 // it for linking below and short circuit the
577 // pre-processing/translation/assembly phases
578 if (ftype.empty() || ftype == "o" || ftype == "bc" || ftype=="a") {
579 // We shouldn't get any of these types of files unless we're
580 // later going to link. Enforce this limit now.
581 if (finalPhase != LINKING) {
Reid Spencer52c2dc12004-08-29 19:26:56 +0000582 throw std::string(
Reid Spenceraf77d742004-10-28 04:05:06 +0000583 "Pre-compiled objects found but linking not requested");
584 }
585 if (ftype.empty())
Reid Spencer1fce0912004-12-11 00:14:15 +0000586 LibFiles.push_back(I->first.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000587 else
588 LinkageItems.insert(I->first);
Reid Spencer679a7232004-11-20 20:39:33 +0000589 continue; // short circuit remainder of loop
Reid Spenceraf77d742004-10-28 04:05:06 +0000590 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000591
Reid Spenceraf77d742004-10-28 04:05:06 +0000592 // At this point, we know its something we need to translate
593 // and/or optimize. See if we can get the configuration data
594 // for this kind of file.
595 ConfigData* cd = cdp->ProvideConfigData(I->second);
596 if (cd == 0)
597 throw std::string("Files of type '") + I->second +
598 "' are not recognized.";
599 if (isSet(DEBUG_FLAG))
600 DumpConfigData(cd,I->second);
Reid Spencer54fafe42004-09-14 01:58:45 +0000601
Reid Spencer0b3c7d02004-11-23 23:45:49 +0000602 // Add the config data's library paths to the end of the list
603 for (StringVector::iterator LPI = cd->libpaths.begin(),
604 LPE = cd->libpaths.end(); LPI != LPE; ++LPI){
605 LibraryPaths.push_back(sys::Path(*LPI));
606 }
607
Reid Spenceraf77d742004-10-28 04:05:06 +0000608 // Initialize the input and output files
609 sys::Path InFile(I->first);
Reid Spencer07adb282004-11-05 22:15:36 +0000610 sys::Path OutFile(I->first.getBasename());
Reid Spencer52c2dc12004-08-29 19:26:56 +0000611
Reid Spenceraf77d742004-10-28 04:05:06 +0000612 // PRE-PROCESSING PHASE
613 Action& action = cd->PreProcessor;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000614
Reid Spenceraf77d742004-10-28 04:05:06 +0000615 // Get the preprocessing action, if needed, or error if appropriate
Reid Spencer07adb282004-11-05 22:15:36 +0000616 if (!action.program.isEmpty()) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000617 if (action.isSet(REQUIRED_FLAG) || finalPhase == PREPROCESSING) {
618 if (finalPhase == PREPROCESSING) {
Reid Spencer679a7232004-11-20 20:39:33 +0000619 if (Output.isEmpty()) {
620 OutFile.appendSuffix("E");
621 actions.push_back(GetAction(cd,InFile,OutFile,PREPROCESSING));
622 } else {
623 actions.push_back(GetAction(cd,InFile,Output,PREPROCESSING));
624 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000625 } else {
Reid Spencer07adb282004-11-05 22:15:36 +0000626 sys::Path TempFile(MakeTempFile(I->first.getBasename(),"E"));
Reid Spenceraf77d742004-10-28 04:05:06 +0000627 actions.push_back(GetAction(cd,InFile,TempFile,
628 PREPROCESSING));
629 InFile = TempFile;
630 }
631 }
632 } else if (finalPhase == PREPROCESSING) {
633 throw cd->langName + " does not support pre-processing";
634 } else if (action.isSet(REQUIRED_FLAG)) {
635 throw std::string("Don't know how to pre-process ") +
636 cd->langName + " files";
637 }
638
639 // Short-circuit remaining actions if all they want is
640 // pre-processing
Reid Spencer679a7232004-11-20 20:39:33 +0000641 if (finalPhase == PREPROCESSING) { continue; };
Reid Spenceraf77d742004-10-28 04:05:06 +0000642
643 /// TRANSLATION PHASE
644 action = cd->Translator;
645
646 // Get the translation action, if needed, or error if appropriate
Reid Spencer07adb282004-11-05 22:15:36 +0000647 if (!action.program.isEmpty()) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000648 if (action.isSet(REQUIRED_FLAG) || finalPhase == TRANSLATION) {
649 if (finalPhase == TRANSLATION) {
Reid Spencer679a7232004-11-20 20:39:33 +0000650 if (Output.isEmpty()) {
651 OutFile.appendSuffix("o");
652 actions.push_back(GetAction(cd,InFile,OutFile,TRANSLATION));
653 } else {
654 actions.push_back(GetAction(cd,InFile,Output,TRANSLATION));
655 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000656 } else {
Reid Spencer07adb282004-11-05 22:15:36 +0000657 sys::Path TempFile(MakeTempFile(I->first.getBasename(),"trans"));
Reid Spenceraf77d742004-10-28 04:05:06 +0000658 actions.push_back(GetAction(cd,InFile,TempFile,TRANSLATION));
659 InFile = TempFile;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000660 }
661
Reid Spenceraf77d742004-10-28 04:05:06 +0000662 // ll -> bc Helper
663 if (action.isSet(OUTPUT_IS_ASM_FLAG)) {
664 /// The output of the translator is an LLVM Assembly program
665 /// We need to translate it to bytecode
666 Action* action = new Action();
Reid Spencer07adb282004-11-05 22:15:36 +0000667 action->program.setFile("llvm-as");
Reid Spencer1fce0912004-12-11 00:14:15 +0000668 action->args.push_back(InFile.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000669 action->args.push_back("-o");
Reid Spencer07adb282004-11-05 22:15:36 +0000670 InFile.appendSuffix("bc");
Reid Spencer1fce0912004-12-11 00:14:15 +0000671 action->args.push_back(InFile.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000672 actions.push_back(action);
Reid Spencer52c2dc12004-08-29 19:26:56 +0000673 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000674 }
675 } else if (finalPhase == TRANSLATION) {
676 throw cd->langName + " does not support translation";
677 } else if (action.isSet(REQUIRED_FLAG)) {
678 throw std::string("Don't know how to translate ") +
679 cd->langName + " files";
680 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000681
Reid Spenceraf77d742004-10-28 04:05:06 +0000682 // Short-circuit remaining actions if all they want is translation
Reid Spencer679a7232004-11-20 20:39:33 +0000683 if (finalPhase == TRANSLATION) { continue; }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000684
Reid Spenceraf77d742004-10-28 04:05:06 +0000685 /// OPTIMIZATION PHASE
686 action = cd->Optimizer;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000687
Reid Spenceraf77d742004-10-28 04:05:06 +0000688 // Get the optimization action, if needed, or error if appropriate
689 if (!isSet(EMIT_RAW_FLAG)) {
Reid Spencer07adb282004-11-05 22:15:36 +0000690 if (!action.program.isEmpty()) {
Reid Spenceraf77d742004-10-28 04:05:06 +0000691 if (action.isSet(REQUIRED_FLAG) || finalPhase == OPTIMIZATION) {
692 if (finalPhase == OPTIMIZATION) {
Reid Spencer679a7232004-11-20 20:39:33 +0000693 if (Output.isEmpty()) {
694 OutFile.appendSuffix("o");
695 actions.push_back(GetAction(cd,InFile,OutFile,OPTIMIZATION));
696 } else {
697 actions.push_back(GetAction(cd,InFile,Output,OPTIMIZATION));
698 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000699 } else {
Reid Spencer07adb282004-11-05 22:15:36 +0000700 sys::Path TempFile(MakeTempFile(I->first.getBasename(),"opt"));
Reid Spenceraf77d742004-10-28 04:05:06 +0000701 actions.push_back(GetAction(cd,InFile,TempFile,OPTIMIZATION));
702 InFile = TempFile;
703 }
704 // ll -> bc Helper
705 if (action.isSet(OUTPUT_IS_ASM_FLAG)) {
706 /// The output of the optimizer is an LLVM Assembly program
707 /// We need to translate it to bytecode with llvm-as
Reid Spencer52c2dc12004-08-29 19:26:56 +0000708 Action* action = new Action();
Reid Spencer07adb282004-11-05 22:15:36 +0000709 action->program.setFile("llvm-as");
Reid Spencer1fce0912004-12-11 00:14:15 +0000710 action->args.push_back(InFile.toString());
Reid Spencer52c2dc12004-08-29 19:26:56 +0000711 action->args.push_back("-f");
712 action->args.push_back("-o");
Reid Spencer07adb282004-11-05 22:15:36 +0000713 InFile.appendSuffix("bc");
Reid Spencer1fce0912004-12-11 00:14:15 +0000714 action->args.push_back(InFile.toString());
Reid Spencer52c2dc12004-08-29 19:26:56 +0000715 actions.push_back(action);
716 }
717 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000718 } else if (finalPhase == OPTIMIZATION) {
719 throw cd->langName + " does not support optimization";
720 } else if (action.isSet(REQUIRED_FLAG)) {
721 throw std::string("Don't know how to optimize ") +
722 cd->langName + " files";
Reid Spencer52c2dc12004-08-29 19:26:56 +0000723 }
Reid Spencer52c2dc12004-08-29 19:26:56 +0000724 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000725
726 // Short-circuit remaining actions if all they want is optimization
Reid Spencer679a7232004-11-20 20:39:33 +0000727 if (finalPhase == OPTIMIZATION) { continue; }
Reid Spenceraf77d742004-10-28 04:05:06 +0000728
729 /// ASSEMBLY PHASE
730 action = cd->Assembler;
731
732 if (finalPhase == ASSEMBLY) {
Reid Spencer679a7232004-11-20 20:39:33 +0000733
734 // Build either a native compilation action or a disassembly action
735 Action* action = new Action();
Reid Spenceraf77d742004-10-28 04:05:06 +0000736 if (isSet(EMIT_NATIVE_FLAG)) {
737 // Use llc to get the native assembly file
Reid Spencer07adb282004-11-05 22:15:36 +0000738 action->program.setFile("llc");
Reid Spencer1fce0912004-12-11 00:14:15 +0000739 action->args.push_back(InFile.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000740 action->args.push_back("-f");
741 action->args.push_back("-o");
Reid Spencer679a7232004-11-20 20:39:33 +0000742 if (Output.isEmpty()) {
743 OutFile.appendSuffix("o");
Reid Spencer1fce0912004-12-11 00:14:15 +0000744 action->args.push_back(OutFile.toString());
Reid Spencer679a7232004-11-20 20:39:33 +0000745 } else {
Reid Spencer1fce0912004-12-11 00:14:15 +0000746 action->args.push_back(Output.toString());
Reid Spencer679a7232004-11-20 20:39:33 +0000747 }
748 actions.push_back(action);
Reid Spenceraf77d742004-10-28 04:05:06 +0000749 } else {
750 // Just convert back to llvm assembly with llvm-dis
Reid Spencer07adb282004-11-05 22:15:36 +0000751 action->program.setFile("llvm-dis");
Reid Spencer1fce0912004-12-11 00:14:15 +0000752 action->args.push_back(InFile.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000753 action->args.push_back("-f");
754 action->args.push_back("-o");
Reid Spencer679a7232004-11-20 20:39:33 +0000755 if (Output.isEmpty()) {
756 OutFile.appendSuffix("ll");
Reid Spencer1fce0912004-12-11 00:14:15 +0000757 action->args.push_back(OutFile.toString());
Reid Spencer679a7232004-11-20 20:39:33 +0000758 } else {
Reid Spencer1fce0912004-12-11 00:14:15 +0000759 action->args.push_back(Output.toString());
Reid Spencer679a7232004-11-20 20:39:33 +0000760 }
Reid Spenceraf77d742004-10-28 04:05:06 +0000761 }
762
Reid Spencer679a7232004-11-20 20:39:33 +0000763 // Put the action on the list
764 actions.push_back(action);
765
Reid Spenceraf77d742004-10-28 04:05:06 +0000766 // Short circuit the rest of the loop, we don't want to link
Reid Spenceraf77d742004-10-28 04:05:06 +0000767 continue;
768 }
769
770 // Register the result of the actions as a link candidate
771 LinkageItems.insert(InFile);
772
Reid Spenceraf77d742004-10-28 04:05:06 +0000773 } // end while loop over each input file
774
775 /// RUN THE COMPILATION ACTIONS
776 std::vector<Action*>::iterator AI = actions.begin();
777 std::vector<Action*>::iterator AE = actions.end();
778 while (AI != AE) {
779 if (!DoAction(*AI))
780 throw std::string("Action failed");
781 AI++;
Reid Spencer52c2dc12004-08-29 19:26:56 +0000782 }
783
Reid Spenceraf77d742004-10-28 04:05:06 +0000784 /// LINKING PHASE
785 if (finalPhase == LINKING) {
Reid Spencer52c2dc12004-08-29 19:26:56 +0000786
Reid Spenceraf77d742004-10-28 04:05:06 +0000787 // Insert the platform-specific system libraries to the path list
Reid Spencer11db4b82004-12-13 03:01:26 +0000788 std::vector<sys::Path> SysLibs;
789 sys::Path::GetSystemLibraryPaths(SysLibs);
790 LibraryPaths.insert(LibraryPaths.end(), SysLibs.begin(), SysLibs.end());
Reid Spenceraf77d742004-10-28 04:05:06 +0000791
792 // Set up the linking action with llvm-ld
793 Action* link = new Action();
Reid Spencer07adb282004-11-05 22:15:36 +0000794 link->program.setFile("llvm-ld");
Reid Spenceraf77d742004-10-28 04:05:06 +0000795
796 // Add in the optimization level requested
797 switch (optLevel) {
798 case OPT_FAST_COMPILE:
799 link->args.push_back("-O1");
800 break;
801 case OPT_SIMPLE:
802 link->args.push_back("-O2");
803 break;
804 case OPT_AGGRESSIVE:
805 link->args.push_back("-O3");
806 break;
807 case OPT_LINK_TIME:
808 link->args.push_back("-O4");
809 break;
810 case OPT_AGGRESSIVE_LINK_TIME:
811 link->args.push_back("-O5");
812 break;
813 case OPT_NONE:
814 break;
815 }
816
817 // Add in all the linkage items we generated. This includes the
818 // output from the translation/optimization phases as well as any
819 // -l arguments specified.
820 for (PathVector::const_iterator I=LinkageItems.begin(),
821 E=LinkageItems.end(); I != E; ++I )
Reid Spencer1fce0912004-12-11 00:14:15 +0000822 link->args.push_back(I->toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000823
824 // Add in all the libraries we found.
Reid Spencerf6358c72004-12-19 18:00:56 +0000825 for (StringVector::const_iterator I=LibFiles.begin(),
Reid Spenceraf77d742004-10-28 04:05:06 +0000826 E=LibFiles.end(); I != E; ++I )
827 link->args.push_back(std::string("-l")+*I);
828
829 // Add in all the library paths to the command line
830 for (PathVector::const_iterator I=LibraryPaths.begin(),
831 E=LibraryPaths.end(); I != E; ++I)
Reid Spencer1fce0912004-12-11 00:14:15 +0000832 link->args.push_back( std::string("-L") + I->toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000833
834 // Add in the additional linker arguments requested
835 for (StringVector::const_iterator I=AdditionalArgs[LINKING].begin(),
836 E=AdditionalArgs[LINKING].end(); I != E; ++I)
837 link->args.push_back( *I );
838
839 // Add in other optional flags
840 if (isSet(EMIT_NATIVE_FLAG))
841 link->args.push_back("-native");
842 if (isSet(VERBOSE_FLAG))
843 link->args.push_back("-v");
844 if (isSet(TIME_PASSES_FLAG))
845 link->args.push_back("-time-passes");
846 if (isSet(SHOW_STATS_FLAG))
847 link->args.push_back("-stats");
848 if (isSet(STRIP_OUTPUT_FLAG))
849 link->args.push_back("-s");
850 if (isSet(DEBUG_FLAG)) {
851 link->args.push_back("-debug");
852 link->args.push_back("-debug-pass=Details");
853 }
854
855 // Add in mandatory flags
856 link->args.push_back("-o");
Reid Spencer1fce0912004-12-11 00:14:15 +0000857 link->args.push_back(Output.toString());
Reid Spenceraf77d742004-10-28 04:05:06 +0000858
859 // Execute the link
860 if (!DoAction(link))
861 throw std::string("Action failed");
862 }
863 } catch (std::string& msg) {
864 cleanup();
865 throw;
866 } catch (...) {
867 cleanup();
868 throw std::string("Unspecified error");
869 }
870 cleanup();
871 return 0;
872 }
873
874/// @}
875/// @name Data
876/// @{
877private:
878 ConfigDataProvider* cdp; ///< Where we get configuration data from
879 Phases finalPhase; ///< The final phase of compilation
880 OptimizationLevels optLevel; ///< The optimization level to apply
881 unsigned Flags; ///< The driver flags
882 std::string machine; ///< Target machine name
883 PathVector LibraryPaths; ///< -L options
884 PathVector IncludePaths; ///< -I options
Reid Spencer07adb282004-11-05 22:15:36 +0000885 PathVector ToolPaths; ///< -B options
Reid Spenceraf77d742004-10-28 04:05:06 +0000886 StringVector Defines; ///< -D options
887 sys::Path TempDir; ///< Name of the temporary directory.
888 StringTable AdditionalArgs; ///< The -Txyz options
889 StringVector fOptions; ///< -f options
890 StringVector MOptions; ///< -M options
891 StringVector WOptions; ///< -W options
892
893/// @}
894};
Reid Spencer5c56dc12004-08-13 20:22:43 +0000895}
896
897CompilerDriver::~CompilerDriver() {
Reid Spencer52c2dc12004-08-29 19:26:56 +0000898}
899
900CompilerDriver*
901CompilerDriver::Get(ConfigDataProvider& CDP) {
902 return new CompilerDriverImpl(CDP);
Reid Spencerbae68252004-08-19 04:49:47 +0000903}
904
905CompilerDriver::ConfigData::ConfigData()
906 : langName()
907 , PreProcessor()
908 , Translator()
909 , Optimizer()
910 , Assembler()
911 , Linker()
912{
913 StringVector emptyVec;
914 for (unsigned i = 0; i < NUM_PHASES; ++i)
915 opts.push_back(emptyVec);
Reid Spencer5c56dc12004-08-13 20:22:43 +0000916}
917
Reid Spencer5c56dc12004-08-13 20:22:43 +0000918// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab