1 //===- CompilerDriver.cpp - The LLVM Compiler Driver ------------*- C++ -*-===//
4 // The LLVM Compiler Infrastructure
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.
9 //===----------------------------------------------------------------------===//
11 // This file implements the bulk of the LLVM Compiler Driver (llvmc).
13 //===------------------------------------------------------------------------===
15 #include "CompilerDriver.h"
16 #include "ConfigLexer.h"
17 #include "llvm/Module.h"
18 #include "llvm/Bytecode/Reader.h"
19 #include "llvm/Support/Timer.h"
20 #include "llvm/System/Signals.h"
21 #include "llvm/ADT/SetVector.h"
22 #include "llvm/ADT/StringExtras.h"
23 #include "llvm/Config/alloca.h"
29 void WriteAction(CompilerDriver::Action* action ) {
30 std::cerr << action->program.c_str();
31 std::vector<std::string>::const_iterator I = action->args.begin();
32 while (I != action->args.end()) {
33 std::cerr << ' ' << *I;
39 void DumpAction(CompilerDriver::Action* action) {
40 std::cerr << "command = " << action->program.c_str();
41 std::vector<std::string>::const_iterator I = action->args.begin();
42 while (I != action->args.end()) {
43 std::cerr << ' ' << *I;
47 std::cerr << "flags = " << action->flags << '\n';
50 void DumpConfigData(CompilerDriver::ConfigData* cd, const std::string& type ){
51 std::cerr << "Configuration Data For '" << cd->langName << "' (" << type
53 std::cerr << "PreProcessor: ";
54 DumpAction(&cd->PreProcessor);
55 std::cerr << "Translator: ";
56 DumpAction(&cd->Translator);
57 std::cerr << "Optimizer: ";
58 DumpAction(&cd->Optimizer);
59 std::cerr << "Assembler: ";
60 DumpAction(&cd->Assembler);
61 std::cerr << "Linker: ";
62 DumpAction(&cd->Linker);
65 /// This specifies the passes to run for OPT_FAST_COMPILE (-O1)
66 /// which should reduce the volume of code and make compilation
67 /// faster. This is also safe on any llvm module.
68 static const char* DefaultFastCompileOptimizations[] = {
69 "-simplifycfg", "-mem2reg", "-instcombine"
72 class CompilerDriverImpl : public CompilerDriver {
73 /// @name Constructors
76 CompilerDriverImpl(ConfigDataProvider& confDatProv )
79 , optLevel(OPT_FAST_COMPILE)
86 TempDir = sys::Path::GetTemporaryDirectory();
87 sys::RemoveDirectoryOnSignal(TempDir);
88 AdditionalArgs.reserve(NUM_PHASES);
89 StringVector emptyVec;
90 for (unsigned i = 0; i < NUM_PHASES; ++i)
91 AdditionalArgs.push_back(emptyVec);
94 virtual ~CompilerDriverImpl() {
101 AdditionalArgs.clear();
111 virtual void setFinalPhase(Phases phase) {
115 virtual void setOptimization(OptimizationLevels level) {
119 virtual void setDriverFlags(unsigned flags) {
120 Flags = flags & DRIVER_FLAGS_MASK;
123 virtual void setOutputMachine(const std::string& machineName) {
124 machine = machineName;
127 virtual void setPhaseArgs(Phases phase, const StringVector& opts) {
128 assert(phase <= LINKING && phase >= PREPROCESSING);
129 AdditionalArgs[phase] = opts;
132 virtual void setIncludePaths(const StringVector& paths) {
133 StringVector::const_iterator I = paths.begin();
134 StringVector::const_iterator E = paths.end();
138 IncludePaths.push_back(tmp);
143 virtual void setSymbolDefines(const StringVector& defs) {
147 virtual void setLibraryPaths(const StringVector& paths) {
148 StringVector::const_iterator I = paths.begin();
149 StringVector::const_iterator E = paths.end();
153 LibraryPaths.push_back(tmp);
158 virtual void addLibraryPath(const sys::Path& libPath) {
159 LibraryPaths.push_back(libPath);
162 virtual void addToolPath(const sys::Path& toolPath) {
163 ToolPaths.push_back(toolPath);
166 virtual void setfPassThrough(const StringVector& fOpts) {
170 /// @brief Set the list of -M options to be passed through
171 virtual void setMPassThrough(const StringVector& MOpts) {
175 /// @brief Set the list of -W options to be passed through
176 virtual void setWPassThrough(const StringVector& WOpts) {
184 bool isSet(DriverFlags flag) {
185 return 0 != ((flag & DRIVER_FLAGS_MASK) & Flags);
189 if (!isSet(KEEP_TEMPS_FLAG)) {
190 if (TempDir.isDirectory() && TempDir.canWrite())
191 TempDir.eraseFromDisk(/*remove_contents=*/true);
193 std::cout << "Temporary files are in " << TempDir << "\n";
197 sys::Path MakeTempFile(const std::string& basename,
198 const std::string& suffix) {
199 sys::Path result(TempDir);
200 if (!result.appendComponent(basename))
201 throw basename + ": can't use this file name";
202 if (!result.appendSuffix(suffix))
203 throw suffix + ": can't use this file suffix";
207 Action* GetAction(ConfigData* cd,
208 const sys::Path& input,
209 const sys::Path& output,
212 Action* pat = 0; ///< The pattern/template for the action
213 Action* action = new Action; ///< The actual action to execute
215 // Get the action pattern
217 case PREPROCESSING: pat = &cd->PreProcessor; break;
218 case TRANSLATION: pat = &cd->Translator; break;
219 case OPTIMIZATION: pat = &cd->Optimizer; break;
220 case ASSEMBLY: pat = &cd->Assembler; break;
221 case LINKING: pat = &cd->Linker; break;
223 assert(!"Invalid driver phase!");
226 assert(pat != 0 && "Invalid command pattern");
228 // Copy over some pattern things that don't need to change
229 action->program = pat->program;
230 action->flags = pat->flags;
232 // Do the substitutions from the pattern to the actual
233 StringVector::iterator PI = pat->args.begin();
234 StringVector::iterator PE = pat->args.end();
236 if ((*PI)[0] == '%' && PI->length() >2) {
240 if (*PI == "%args%") {
241 if (AdditionalArgs.size() > unsigned(phase))
242 if (!AdditionalArgs[phase].empty()) {
243 // Get specific options for each kind of action type
244 StringVector& addargs = AdditionalArgs[phase];
245 // Add specific options for each kind of action type
246 action->args.insert(action->args.end(), addargs.begin(),
253 if (*PI == "%bindir%") {
254 std::string tmp(*PI);
255 tmp.replace(0,8,LLVM_BINDIR);
256 action->args.push_back(tmp);
261 if (*PI == "%defs%") {
262 StringVector::iterator I = Defines.begin();
263 StringVector::iterator E = Defines.end();
265 action->args.push_back( std::string("-D") + *I);
272 if (*PI == "%fOpts%") {
273 if (!fOptions.empty())
274 action->args.insert(action->args.end(), fOptions.begin(),
281 action->args.push_back(input.toString());
282 } else if (*PI == "%incls%") {
283 PathVector::iterator I = IncludePaths.begin();
284 PathVector::iterator E = IncludePaths.end();
286 action->args.push_back( std::string("-I") + I->toString() );
293 if ((*PI)[1] == 'l') {
294 std::string tmp(*PI);
295 if (*PI == "%llvmgccdir%")
296 tmp.replace(0,12,LLVMGCCDIR);
297 else if (*PI == "%llvmgccarch%")
298 tmp.replace(0,13,LLVMGCCARCH);
299 else if (*PI == "%llvmgcc%")
300 tmp.replace(0,9,LLVMGCC);
301 else if (*PI == "%llvmgxx%")
302 tmp.replace(0,9,LLVMGXX);
303 else if (*PI == "%llvmcc1%")
304 tmp.replace(0,9,LLVMCC1);
305 else if (*PI == "%llvmcc1plus%")
306 tmp.replace(0,9,LLVMCC1);
310 action->args.push_back(tmp);
311 } else if (*PI == "%libs%") {
312 PathVector::iterator I = LibraryPaths.begin();
313 PathVector::iterator E = LibraryPaths.end();
315 action->args.push_back( std::string("-L") + I->toString() );
318 } else if (*PI == "%libdir%") {
319 std::string tmp(*PI);
320 tmp.replace(0,8,LLVM_LIBDIR);
321 action->args.push_back(tmp);
326 if (*PI == "%out%") {
327 action->args.push_back(output.toString());
328 } else if (*PI == "%opt%") {
329 if (!isSet(EMIT_RAW_FLAG)) {
330 if (cd->opts.size() > static_cast<unsigned>(optLevel) &&
331 !cd->opts[optLevel].empty())
332 action->args.insert(action->args.end(),
333 cd->opts[optLevel].begin(),
334 cd->opts[optLevel].end());
336 throw std::string("Optimization options for level ") +
337 utostr(unsigned(optLevel)) + " were not specified";
343 if (*PI == "%stats%") {
344 if (isSet(SHOW_STATS_FLAG))
345 action->args.push_back("-stats");
350 if (*PI == "%target%") {
351 action->args.push_back(std::string("-march=") + machine);
352 } else if (*PI == "%time%") {
353 if (isSet(TIME_PASSES_FLAG))
354 action->args.push_back("-time-passes");
359 if (*PI == "%verbose%") {
360 if (isSet(VERBOSE_FLAG))
361 action->args.push_back("-v");
366 if (*PI == "%Mopts%") {
367 if (!MOptions.empty())
368 action->args.insert(action->args.end(), MOptions.begin(),
374 if (*PI == "%Wopts%") {
375 for (StringVector::iterator I = WOptions.begin(),
376 E = WOptions.end(); I != E ; ++I ) {
377 action->args.push_back(std::string("-W") + *I);
387 // Did it even look like a substitution?
388 if (PI->length()>1 && (*PI)[0] == '%' &&
389 (*PI)[PI->length()-1] == '%') {
390 throw std::string("Invalid substitution token: '") + *PI +
391 "' for command '" + pat->program.toString() + "'";
392 } else if (!PI->empty()) {
393 // It's not a legal substitution, just pass it through
394 action->args.push_back(*PI);
397 } else if (!PI->empty()) {
398 // Its not a substitution, just put it in the action
399 action->args.push_back(*PI);
404 // Finally, we're done
408 bool DoAction(Action*action) {
409 assert(action != 0 && "Invalid Action!");
410 if (isSet(VERBOSE_FLAG))
412 if (!isSet(DRY_RUN_FLAG)) {
413 sys::Path progpath = sys::Program::FindProgramByName(
414 action->program.toString());
415 if (progpath.isEmpty())
416 throw std::string("Can't find program '" +
417 action->program.toString()+"'");
418 else if (progpath.canExecute())
419 action->program = progpath;
421 throw std::string("Program '"+action->program.toString()+
422 "' is not executable.");
424 // Invoke the program
425 const char** Args = (const char**)
426 alloca(sizeof(const char*)*(action->args.size()+2));
427 Args[0] = action->program.toString().c_str();
428 for (unsigned i = 1; i != action->args.size(); ++i)
429 Args[i] = action->args[i].c_str();
430 Args[action->args.size()] = 0; // null terminate list.
431 if (isSet(TIME_ACTIONS_FLAG)) {
432 Timer timer(action->program.toString());
434 int resultCode = sys::Program::ExecuteAndWait(action->program, Args);
436 timer.print(timer,std::cerr);
437 return resultCode == 0;
440 return 0 == sys::Program::ExecuteAndWait(action->program, Args);
445 /// This method tries various variants of a linkage item's file
446 /// name to see if it can find an appropriate file to link with
447 /// in the directories of the LibraryPaths.
448 llvm::sys::Path GetPathForLinkageItem(const std::string& link_item,
449 bool native = false) {
451 fullpath.set(link_item);
452 if (fullpath.canRead())
454 for (PathVector::iterator PI = LibraryPaths.begin(),
455 PE = LibraryPaths.end(); PI != PE; ++PI) {
456 fullpath.set(PI->toString());
457 fullpath.appendComponent(link_item);
458 if (fullpath.canRead())
461 fullpath.appendSuffix("a");
463 fullpath.appendSuffix("bc");
464 if (fullpath.canRead())
466 fullpath.eraseSuffix();
467 fullpath.appendSuffix("o");
468 if (fullpath.canRead())
471 fullpath.appendComponent(std::string("lib") + link_item);
472 fullpath.appendSuffix("a");
473 if (fullpath.canRead())
475 fullpath.eraseSuffix();
476 fullpath.appendSuffix("so");
477 if (fullpath.canRead())
487 /// This method processes a linkage item. The item could be a
488 /// Bytecode file needing translation to native code and that is
489 /// dependent on other bytecode libraries, or a native code
490 /// library that should just be linked into the program.
491 bool ProcessLinkageItem(const llvm::sys::Path& link_item,
492 SetVector<sys::Path>& set,
494 // First, see if the unadorned file name is not readable. If so,
495 // we must track down the file in the lib search path.
497 if (!link_item.canRead()) {
498 // look for the library using the -L arguments specified
499 // on the command line.
500 fullpath = GetPathForLinkageItem(link_item.toString());
502 // If we didn't find the file in any of the library search paths
503 // we have to bail. No where else to look.
504 if (fullpath.isEmpty()) {
506 std::string("Can't find linkage item '") + link_item.toString() + "'";
510 fullpath = link_item;
513 // If we got here fullpath is the path to the file, and its readable.
514 set.insert(fullpath);
516 // If its an LLVM bytecode file ...
517 if (fullpath.isBytecodeFile()) {
518 // Process the dependent libraries recursively
519 Module::LibraryListType modlibs;
520 if (GetBytecodeDependentLibraries(fullpath.toString(),modlibs)) {
521 // Traverse the dependent libraries list
522 Module::lib_iterator LI = modlibs.begin();
523 Module::lib_iterator LE = modlibs.end();
525 if (!ProcessLinkageItem(sys::Path(*LI),set,err)) {
527 err = std::string("Library '") + *LI +
528 "' is not valid for linking but is required by file '" +
529 fullpath.toString() + "'";
531 err += " which is required by file '" + fullpath.toString() + "'";
537 } else if (err.empty()) {
539 "The dependent libraries could not be extracted from '") +
551 virtual int execute(const InputList& InpList, const sys::Path& Output ) {
553 // Echo the configuration of options if we're running verbose
554 if (isSet(DEBUG_FLAG)) {
555 std::cerr << "Compiler Driver Options:\n";
556 std::cerr << "DryRun = " << isSet(DRY_RUN_FLAG) << "\n";
557 std::cerr << "Verbose = " << isSet(VERBOSE_FLAG) << " \n";
558 std::cerr << "TimeActions = " << isSet(TIME_ACTIONS_FLAG) << "\n";
559 std::cerr << "TimePasses = " << isSet(TIME_PASSES_FLAG) << "\n";
560 std::cerr << "ShowStats = " << isSet(SHOW_STATS_FLAG) << "\n";
561 std::cerr << "EmitRawCode = " << isSet(EMIT_RAW_FLAG) << "\n";
562 std::cerr << "EmitNativeCode = " << isSet(EMIT_NATIVE_FLAG) << "\n";
563 std::cerr << "KeepTemps = " << isSet(KEEP_TEMPS_FLAG) << "\n";
564 std::cerr << "OutputMachine = " << machine << "\n";
565 InputList::const_iterator I = InpList.begin();
566 while ( I != InpList.end() ) {
567 std::cerr << "Input: " << I->first << "(" << I->second
571 std::cerr << "Output: " << Output << "\n";
574 // If there's no input, we're done.
576 throw std::string("Nothing to compile.");
578 // If they are asking for linking and didn't provide an output
579 // file then its an error (no way for us to "make up" a meaningful
580 // file name based on the various linker input files).
581 if (finalPhase == LINKING && Output.isEmpty())
583 "An output file name must be specified for linker output");
585 // If they are not asking for linking, provided an output file and
586 // there is more than one input file, its an error
587 if (finalPhase != LINKING && !Output.isEmpty() && InpList.size() > 1)
588 throw std::string("An output file name cannot be specified ") +
589 "with more than one input file name when not linking";
591 // This vector holds all the resulting actions of the following loop.
592 std::vector<Action*> actions;
594 /// PRE-PROCESSING / TRANSLATION / OPTIMIZATION / ASSEMBLY phases
595 // for each input item
596 SetVector<sys::Path> LinkageItems;
597 StringVector LibFiles;
598 InputList::const_iterator I = InpList.begin();
599 for (InputList::const_iterator I = InpList.begin(), E = InpList.end();
601 // Get the suffix of the file name
602 const std::string& ftype = I->second;
604 // If its a library, bytecode file, or object file, save
605 // it for linking below and short circuit the
606 // pre-processing/translation/assembly phases
607 if (ftype.empty() || ftype == "o" || ftype == "bc" || ftype=="a") {
608 // We shouldn't get any of these types of files unless we're
609 // later going to link. Enforce this limit now.
610 if (finalPhase != LINKING) {
612 "Pre-compiled objects found but linking not requested");
615 LibFiles.push_back(I->first.toString());
617 LinkageItems.insert(I->first);
618 continue; // short circuit remainder of loop
621 // At this point, we know its something we need to translate
622 // and/or optimize. See if we can get the configuration data
623 // for this kind of file.
624 ConfigData* cd = cdp->ProvideConfigData(I->second);
626 throw std::string("Files of type '") + I->second +
627 "' are not recognized.";
628 if (isSet(DEBUG_FLAG))
629 DumpConfigData(cd,I->second);
631 // Add the config data's library paths to the end of the list
632 for (StringVector::iterator LPI = cd->libpaths.begin(),
633 LPE = cd->libpaths.end(); LPI != LPE; ++LPI){
634 LibraryPaths.push_back(sys::Path(*LPI));
637 // Initialize the input and output files
638 sys::Path InFile(I->first);
639 sys::Path OutFile(I->first.getBasename());
641 // PRE-PROCESSING PHASE
642 Action& action = cd->PreProcessor;
644 // Get the preprocessing action, if needed, or error if appropriate
645 if (!action.program.isEmpty()) {
646 if (action.isSet(REQUIRED_FLAG) || finalPhase == PREPROCESSING) {
647 if (finalPhase == PREPROCESSING) {
648 if (Output.isEmpty()) {
649 OutFile.appendSuffix("E");
650 actions.push_back(GetAction(cd,InFile,OutFile,PREPROCESSING));
652 actions.push_back(GetAction(cd,InFile,Output,PREPROCESSING));
655 sys::Path TempFile(MakeTempFile(I->first.getBasename(),"E"));
656 actions.push_back(GetAction(cd,InFile,TempFile,
661 } else if (finalPhase == PREPROCESSING) {
662 throw cd->langName + " does not support pre-processing";
663 } else if (action.isSet(REQUIRED_FLAG)) {
664 throw std::string("Don't know how to pre-process ") +
665 cd->langName + " files";
668 // Short-circuit remaining actions if all they want is
670 if (finalPhase == PREPROCESSING) { continue; };
672 /// TRANSLATION PHASE
673 action = cd->Translator;
675 // Get the translation action, if needed, or error if appropriate
676 if (!action.program.isEmpty()) {
677 if (action.isSet(REQUIRED_FLAG) || finalPhase == TRANSLATION) {
678 if (finalPhase == TRANSLATION) {
679 if (Output.isEmpty()) {
680 OutFile.appendSuffix("o");
681 actions.push_back(GetAction(cd,InFile,OutFile,TRANSLATION));
683 actions.push_back(GetAction(cd,InFile,Output,TRANSLATION));
686 sys::Path TempFile(MakeTempFile(I->first.getBasename(),"trans"));
687 actions.push_back(GetAction(cd,InFile,TempFile,TRANSLATION));
692 if (action.isSet(OUTPUT_IS_ASM_FLAG)) {
693 /// The output of the translator is an LLVM Assembly program
694 /// We need to translate it to bytecode
695 Action* action = new Action();
696 action->program.set("llvm-as");
697 action->args.push_back(InFile.toString());
698 action->args.push_back("-o");
699 InFile.appendSuffix("bc");
700 action->args.push_back(InFile.toString());
701 actions.push_back(action);
704 } else if (finalPhase == TRANSLATION) {
705 throw cd->langName + " does not support translation";
706 } else if (action.isSet(REQUIRED_FLAG)) {
707 throw std::string("Don't know how to translate ") +
708 cd->langName + " files";
711 // Short-circuit remaining actions if all they want is translation
712 if (finalPhase == TRANSLATION) { continue; }
714 /// OPTIMIZATION PHASE
715 action = cd->Optimizer;
717 // Get the optimization action, if needed, or error if appropriate
718 if (!isSet(EMIT_RAW_FLAG)) {
719 if (!action.program.isEmpty()) {
720 if (action.isSet(REQUIRED_FLAG) || finalPhase == OPTIMIZATION) {
721 if (finalPhase == OPTIMIZATION) {
722 if (Output.isEmpty()) {
723 OutFile.appendSuffix("o");
724 actions.push_back(GetAction(cd,InFile,OutFile,OPTIMIZATION));
726 actions.push_back(GetAction(cd,InFile,Output,OPTIMIZATION));
729 sys::Path TempFile(MakeTempFile(I->first.getBasename(),"opt"));
730 actions.push_back(GetAction(cd,InFile,TempFile,OPTIMIZATION));
734 if (action.isSet(OUTPUT_IS_ASM_FLAG)) {
735 /// The output of the optimizer is an LLVM Assembly program
736 /// We need to translate it to bytecode with llvm-as
737 Action* action = new Action();
738 action->program.set("llvm-as");
739 action->args.push_back(InFile.toString());
740 action->args.push_back("-f");
741 action->args.push_back("-o");
742 InFile.appendSuffix("bc");
743 action->args.push_back(InFile.toString());
744 actions.push_back(action);
747 } else if (finalPhase == OPTIMIZATION) {
748 throw cd->langName + " does not support optimization";
749 } else if (action.isSet(REQUIRED_FLAG)) {
750 throw std::string("Don't know how to optimize ") +
751 cd->langName + " files";
755 // Short-circuit remaining actions if all they want is optimization
756 if (finalPhase == OPTIMIZATION) { continue; }
759 action = cd->Assembler;
761 if (finalPhase == ASSEMBLY) {
763 // Build either a native compilation action or a disassembly action
764 Action* action = new Action();
765 if (isSet(EMIT_NATIVE_FLAG)) {
766 // Use llc to get the native assembly file
767 action->program.set("llc");
768 action->args.push_back(InFile.toString());
769 action->args.push_back("-f");
770 action->args.push_back("-o");
771 if (Output.isEmpty()) {
772 OutFile.appendSuffix("o");
773 action->args.push_back(OutFile.toString());
775 action->args.push_back(Output.toString());
777 actions.push_back(action);
779 // Just convert back to llvm assembly with llvm-dis
780 action->program.set("llvm-dis");
781 action->args.push_back(InFile.toString());
782 action->args.push_back("-f");
783 action->args.push_back("-o");
784 if (Output.isEmpty()) {
785 OutFile.appendSuffix("ll");
786 action->args.push_back(OutFile.toString());
788 action->args.push_back(Output.toString());
792 // Put the action on the list
793 actions.push_back(action);
795 // Short circuit the rest of the loop, we don't want to link
799 // Register the result of the actions as a link candidate
800 LinkageItems.insert(InFile);
802 } // end while loop over each input file
804 /// RUN THE COMPILATION ACTIONS
805 std::vector<Action*>::iterator AI = actions.begin();
806 std::vector<Action*>::iterator AE = actions.end();
809 throw std::string("Action failed");
814 if (finalPhase == LINKING) {
816 // Insert the platform-specific system libraries to the path list
817 std::vector<sys::Path> SysLibs;
818 sys::Path::GetSystemLibraryPaths(SysLibs);
819 LibraryPaths.insert(LibraryPaths.end(), SysLibs.begin(), SysLibs.end());
821 // Set up the linking action with llvm-ld
822 Action* link = new Action();
823 link->program.set("llvm-ld");
825 // Add in the optimization level requested
827 case OPT_FAST_COMPILE:
828 link->args.push_back("-O1");
831 link->args.push_back("-O2");
834 link->args.push_back("-O3");
837 link->args.push_back("-O4");
839 case OPT_AGGRESSIVE_LINK_TIME:
840 link->args.push_back("-O5");
846 // Add in all the linkage items we generated. This includes the
847 // output from the translation/optimization phases as well as any
848 // -l arguments specified.
849 for (PathVector::const_iterator I=LinkageItems.begin(),
850 E=LinkageItems.end(); I != E; ++I )
851 link->args.push_back(I->toString());
853 // Add in all the libraries we found.
854 for (StringVector::const_iterator I=LibFiles.begin(),
855 E=LibFiles.end(); I != E; ++I )
856 link->args.push_back(std::string("-l")+*I);
858 // Add in all the library paths to the command line
859 for (PathVector::const_iterator I=LibraryPaths.begin(),
860 E=LibraryPaths.end(); I != E; ++I)
861 link->args.push_back( std::string("-L") + I->toString());
863 // Add in the additional linker arguments requested
864 for (StringVector::const_iterator I=AdditionalArgs[LINKING].begin(),
865 E=AdditionalArgs[LINKING].end(); I != E; ++I)
866 link->args.push_back( *I );
868 // Add in other optional flags
869 if (isSet(EMIT_NATIVE_FLAG))
870 link->args.push_back("-native");
871 if (isSet(VERBOSE_FLAG))
872 link->args.push_back("-v");
873 if (isSet(TIME_PASSES_FLAG))
874 link->args.push_back("-time-passes");
875 if (isSet(SHOW_STATS_FLAG))
876 link->args.push_back("-stats");
877 if (isSet(STRIP_OUTPUT_FLAG))
878 link->args.push_back("-s");
879 if (isSet(DEBUG_FLAG)) {
880 link->args.push_back("-debug");
881 link->args.push_back("-debug-pass=Details");
884 // Add in mandatory flags
885 link->args.push_back("-o");
886 link->args.push_back(Output.toString());
890 throw std::string("Action failed");
892 } catch (std::string& msg) {
897 throw std::string("Unspecified error");
907 ConfigDataProvider* cdp; ///< Where we get configuration data from
908 Phases finalPhase; ///< The final phase of compilation
909 OptimizationLevels optLevel; ///< The optimization level to apply
910 unsigned Flags; ///< The driver flags
911 std::string machine; ///< Target machine name
912 PathVector LibraryPaths; ///< -L options
913 PathVector IncludePaths; ///< -I options
914 PathVector ToolPaths; ///< -B options
915 StringVector Defines; ///< -D options
916 sys::Path TempDir; ///< Name of the temporary directory.
917 StringTable AdditionalArgs; ///< The -Txyz options
918 StringVector fOptions; ///< -f options
919 StringVector MOptions; ///< -M options
920 StringVector WOptions; ///< -W options
926 CompilerDriver::~CompilerDriver() {
929 CompilerDriver::ConfigDataProvider::~ConfigDataProvider() {}
932 CompilerDriver::Get(ConfigDataProvider& CDP) {
933 return new CompilerDriverImpl(CDP);
936 CompilerDriver::ConfigData::ConfigData()
944 StringVector emptyVec;
945 for (unsigned i = 0; i < NUM_PHASES; ++i)
946 opts.push_back(emptyVec);