- PrintStackTraceOnErrorSignal();
-
- // Parse the command line options
- cl::ParseCommandLineOptions(argc, argv,
- " LLVM Compilation Driver (llvmc)\n\n"
- " This program provides easy invocation of the LLVM tool set\n"
- " and source language compiler tools.\n"
- );
-
- // Deal with unimplemented options.
- if (Native)
- std::cerr << argv[0] << ": Not implemented yet: -native";
- if (EmitRawCode)
- std::cerr << argv[0] << ": Not implemented yet: -emit-raw-code";
-
- // Default the output file, only if we're going to try to link
- if (OutputFilename.empty() && OptLevel == CompilerDriver::LINKING)
- OutputFilename = "a.out";
-
- // Construct the ConfigDataProvider object
- LLVMC_ConfigDataProvider Provider;
-
- // Construct the CompilerDriver object
- CompilerDriver CD(Provider);
-
- // Configure the driver based on options
- CD.setVerbose(Verbose);
- CD.setDebug(Debug);
- CD.setDryRun(DryRun);
- CD.setFinalPhase(FinalPhase);
- CD.setOptimization(OptLevel);
- CD.setOutputMachine(OutputMachine);
- CD.setEmitNativeCode(Native);
- CD.setEmitRawCode(EmitRawCode);
- std::vector<std::string>::iterator pathIt = LibPaths.begin();
- while ( pathIt != LibPaths.end() ) {
- CD.addLibraryPath( *pathIt++ );
- }
-
- // Prepare the list of files to be compiled by the CompilerDriver.
- CompilerDriver::InputList InpList;
- std::vector<std::string>::iterator fileIt = Files.begin();
- std::vector<std::string>::iterator libIt = Libraries.begin();
- unsigned libPos = 0, filePos = 0;
- while ( 1 ) {
- if ( libIt != Libraries.end() )
- libPos = Libraries.getPosition( libIt - Libraries.begin() );
- else
- libPos = 0;
- if ( fileIt != Files.end() )
- filePos = Files.getPosition( fileIt - Files.begin() );
- else
- filePos = 0;
-
- if ( filePos != 0 && (libPos == 0 || filePos < libPos) ) {
- // Add a source file
- InpList.push_back( std::make_pair(*fileIt, GetFileType(*fileIt,filePos)));
- ++fileIt;
+ sys::PrintStackTraceOnErrorSignal();
+
+ try {
+
+ // Parse the command line options
+ cl::ParseCommandLineOptions(argc, argv,
+ " LLVM Compiler Driver (llvmc)\n\n"
+ " This program provides easy invocation of the LLVM tool set\n"
+ " and other compiler tools.\n"
+ );
+
+ // Deal with unimplemented options.
+ if (PipeCommands)
+ throw std::string("Not implemented yet: -pipe");
+
+ if (OutputFilename.empty())
+ if (OptLevel == CompilerDriver::LINKING)
+ OutputFilename = "a.out";
+
+ // Construct the ConfigDataProvider object
+ LLVMC_ConfigDataProvider Provider;
+ Provider.setConfigDir(sys::Path(ConfigDir));
+
+ // Construct the CompilerDriver object
+ CompilerDriver* CD = CompilerDriver::Get(Provider);
+
+ // If the LLVM_LIB_SEARCH_PATH environment variable is
+ // set, append it to the list of places to search for libraries
+ char *srchPath = getenv("LLVM_LIB_SEARCH_PATH");
+ if (srchPath != NULL && strlen(srchPath) != 0)
+ LibPaths.push_back(std::string(srchPath));
+
+ // Set the driver flags based on command line options
+ unsigned flags = 0;
+ if (Verbose) flags |= CompilerDriver::VERBOSE_FLAG;
+ if (Debug) flags |= CompilerDriver::DEBUG_FLAG;
+ if (DryRun) flags |= CompilerDriver::DRY_RUN_FLAG;
+ if (Native) flags |= CompilerDriver::EMIT_NATIVE_FLAG;
+ if (EmitRawCode) flags |= CompilerDriver::EMIT_RAW_FLAG;
+ if (KeepTemps) flags |= CompilerDriver::KEEP_TEMPS_FLAG;
+ if (ShowStats) flags |= CompilerDriver::SHOW_STATS_FLAG;
+ if (TimeActions) flags |= CompilerDriver::TIME_ACTIONS_FLAG;
+ if (StripOutput) flags |= CompilerDriver::STRIP_OUTPUT_FLAG;
+ CD->setDriverFlags(flags);
+
+ // Specify required parameters
+ CD->setFinalPhase(FinalPhase);
+ CD->setOptimization(OptLevel);
+ CD->setOutputMachine(OutputMachine);
+ CD->setIncludePaths(Includes);
+ CD->setSymbolDefines(Defines);
+ CD->setLibraryPaths(LibPaths);
+ CD->setfPassThrough(fOpts);
+ CD->setMPassThrough(MOpts);
+ CD->setWPassThrough(WOpts);
+
+ // Provide additional tool arguments
+ if (!PreprocessorToolOpts.empty())
+ CD->setPhaseArgs(CompilerDriver::PREPROCESSING, PreprocessorToolOpts);
+ if (!TranslatorToolOpts.empty())
+ CD->setPhaseArgs(CompilerDriver::TRANSLATION, TranslatorToolOpts);
+ if (!OptimizerToolOpts.empty())
+ CD->setPhaseArgs(CompilerDriver::OPTIMIZATION, OptimizerToolOpts);
+ if (!AssemblerToolOpts.empty())
+ CD->setPhaseArgs(CompilerDriver::ASSEMBLY,AssemblerToolOpts);
+ if (!LinkerToolOpts.empty())
+ CD->setPhaseArgs(CompilerDriver::LINKING, LinkerToolOpts);
+
+ // Check for options that cause us to terminate before any significant work
+ // is done.
+ handleTerminatingOptions(CD);
+
+ // Prepare the list of files to be compiled by the CompilerDriver.
+ CompilerDriver::InputList InpList;
+ std::vector<std::string>::iterator fileIt = Files.begin();
+ std::vector<std::string>::iterator libIt = Libraries.begin();
+ unsigned libPos = 0, filePos = 0;
+ while ( 1 ) {
+ if (libIt != Libraries.end())
+ libPos = Libraries.getPosition( libIt - Libraries.begin() );
+ else
+ libPos = 0;
+ if (fileIt != Files.end())
+ filePos = Files.getPosition(fileIt - Files.begin());
+ else
+ filePos = 0;
+
+ if (filePos != 0 && (libPos == 0 || filePos < libPos)) {
+ // Add a source file
+ InpList.push_back(std::make_pair(*fileIt,
+ GetFileType(*fileIt, filePos)));
+ ++fileIt;
+ } else if ( libPos != 0 && (filePos == 0 || libPos < filePos) ) {
+ // Add a library
+ InpList.push_back(std::make_pair(*libIt++, ""));
+ }
+ else
+ break; // we're done with the list