X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=tools%2Fllvmc%2Fllvmc.cpp;h=3b22149db3cf3e20276ff553fd24bb30dc80e296;hb=aea932d27fa41bebaa8576b6002637e74054a7c4;hp=4f325e68e09a4cbcb4e510264ff152e47cfecd08;hpb=3a98ff8d3abe670c716f4a3b8d87c3583c61f505;p=oota-llvm.git diff --git a/tools/llvmc/llvmc.cpp b/tools/llvmc/llvmc.cpp index 4f325e68e09..3b22149db3c 100644 --- a/tools/llvmc/llvmc.cpp +++ b/tools/llvmc/llvmc.cpp @@ -12,7 +12,7 @@ // tools' manual page (docs/CommandGuide/html/llvmc.html) or run the tool with // the --help option. // -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// #include "CompilerDriver.h" #include "Configuration.h" @@ -24,9 +24,9 @@ using namespace llvm; namespace { -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== PHASE OPTIONS -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// cl::opt FinalPhase(cl::Optional, cl::desc("Choose final phase of compilation:"), cl::init(CompilerDriver::LINKING), @@ -43,9 +43,9 @@ cl::opt FinalPhase(cl::Optional, ) ); -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== OPTIMIZATION OPTIONS -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// cl::opt OptLevel(cl::ZeroOrMore, cl::desc("Choose level of optimization to apply:"), cl::init(CompilerDriver::OPT_FAST_COMPILE), @@ -66,9 +66,9 @@ cl::opt OptLevel(cl::ZeroOrMore, ) ); -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== TOOL OPTIONS -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// cl::list PreprocessorToolOpts("Tpre", cl::ZeroOrMore, cl::desc("Pass specific options to the pre-processor"), @@ -115,9 +115,9 @@ cl::list BOpt("B", cl::ZeroOrMore, cl::Prefix, cl::desc("Specify path to find llvmc sub-tools"), cl::value_desc("dir")); -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== INPUT OPTIONS -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// cl::list LibPaths("L", cl::Prefix, cl::desc("Specify a library search path"), cl::value_desc("dir")); @@ -133,9 +133,9 @@ cl::list Defines("D", cl::Prefix, cl::desc("Specify a pre-processor symbol to define"), cl::value_desc("symbol")); -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== OUTPUT OPTIONS -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// cl::opt OutputFilename("o", cl::desc("Override output filename"), cl::value_desc("file")); @@ -156,9 +156,9 @@ cl::opt PrintFileName("print-fname", cl::Optional, cl::value_desc("file"), cl::desc("Print the full path for the option's value")); -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== INFORMATION OPTIONS -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// cl::opt DryRun("dry-run", cl::Optional, cl::init(false), cl::desc("Do everything but perform the compilation actions")); @@ -184,9 +184,9 @@ cl::opt TimeActions("time-actions", cl::Optional, cl::init(false), cl::opt ShowStats("stats", cl::Optional, cl::init(false), cl::desc("Print statistics accumulated during optimization")); -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== ADVANCED OPTIONS -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// static cl::opt ConfigDir("config-dir", cl::Optional, cl::desc("Specify configuration directory to override defaults"), @@ -201,9 +201,9 @@ static cl::opt PipeCommands("pipe", cl::Optional, static cl::opt KeepTemps("keep-temps", cl::Optional, cl::desc("Don't delete temporary files created by llvmc")); -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== POSITIONAL OPTIONS -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// static cl::list Files(cl::Positional, cl::ZeroOrMore, cl::desc("[Sources/objects/libraries]")); @@ -212,17 +212,17 @@ static cl::list Languages("x", cl::ZeroOrMore, cl::desc("Specify the source language for subsequent files"), cl::value_desc("language")); -//===------------------------------------------------------------------------=== +//===----------------------------------------------------------------------===// //=== GetFileType - determine type of a file -//===------------------------------------------------------------------------=== -const std::string GetFileType(const std::string& fname, unsigned pos ) { +//===----------------------------------------------------------------------===// +const std::string GetFileType(const std::string& fname, unsigned pos) { static std::vector::iterator langIt = Languages.begin(); static std::string CurrLang = ""; // If a -x LANG option has been specified .. - if ( langIt != Languages.end() ) + if (langIt != Languages.end()) // If the -x LANG option came before the current file on command line - if ( Languages.getPosition( langIt - Languages.begin() ) < pos ) { + if (Languages.getPosition( langIt - Languages.begin() ) < pos) { // use that language CurrLang = *langIt++; return CurrLang; @@ -233,19 +233,19 @@ const std::string GetFileType(const std::string& fname, unsigned pos ) { return CurrLang; // use that language // otherwise just determine lang from the filename's suffix - return fname.substr( fname.rfind('.',fname.size()) + 1 ); + return fname.substr(fname.rfind('.', fname.size()) + 1); } } // end anonymous namespace void handleTerminatingOptions(CompilerDriver* CD) { if (!PrintFileName.empty()) { - sys::Path path = CD->GetPathForLinkageItem(PrintFileName,false); + sys::Path path = CD->GetPathForLinkageItem(PrintFileName, false); std::string p = path.toString(); if (p.empty()) - std::cout << "Can't locate '" << PrintFileName << "'.\n"; + std::cout << "Can't locate `" << PrintFileName << "'.\n"; else - std::cout << p << "\n"; + std::cout << p << '\n'; exit(0); } } @@ -295,11 +295,10 @@ int main(int argc, char **argv) { if (KeepTemps) flags |= CompilerDriver::KEEP_TEMPS_FLAG; if (ShowStats) flags |= CompilerDriver::SHOW_STATS_FLAG; if (TimeActions) flags |= CompilerDriver::TIME_ACTIONS_FLAG; - if (TimePassesIsEnabled) flags |= CompilerDriver::TIME_PASSES_FLAG; if (StripOutput) flags |= CompilerDriver::STRIP_OUTPUT_FLAG; CD->setDriverFlags(flags); - // Specify requred parameters + // Specify required parameters CD->setFinalPhase(FinalPhase); CD->setOptimization(OptLevel); CD->setOutputMachine(OutputMachine); @@ -332,39 +331,40 @@ int main(int argc, char **argv) { std::vector::iterator libIt = Libraries.begin(); unsigned libPos = 0, filePos = 0; while ( 1 ) { - if ( libIt != Libraries.end() ) + if (libIt != Libraries.end()) libPos = Libraries.getPosition( libIt - Libraries.begin() ); else libPos = 0; - if ( fileIt != Files.end() ) - filePos = Files.getPosition( fileIt - Files.begin() ); + if (fileIt != Files.end()) + filePos = Files.getPosition(fileIt - Files.begin()); else filePos = 0; - if ( filePos != 0 && (libPos == 0 || filePos < libPos) ) { + if (filePos != 0 && (libPos == 0 || filePos < libPos)) { // Add a source file - InpList.push_back( std::make_pair(*fileIt, GetFileType(*fileIt,filePos))); + InpList.push_back(std::make_pair(*fileIt, + GetFileType(*fileIt, filePos))); ++fileIt; - } - else if ( libPos != 0 && (filePos == 0 || libPos < filePos) ) { + } else if ( libPos != 0 && (filePos == 0 || libPos < filePos) ) { // Add a library - InpList.push_back( std::make_pair(*libIt++,"")); + InpList.push_back(std::make_pair(*libIt++, "")); } else break; // we're done with the list } // Tell the driver to do its thing - int result = CD->execute(InpList,sys::Path(OutputFilename)); + std::string ErrMsg; + int result = CD->execute(InpList, sys::Path(OutputFilename), ErrMsg); if (result != 0) { - throw std::string("Error executing actions. Terminated."); + std::cerr << argv[0] << ": " << ErrMsg << '\n'; return result; } // All is good, return success return 0; } catch (const std::string& msg) { - std::cerr << argv[0] << ": " << msg << "\n"; + std::cerr << argv[0] << ": " << msg << '\n'; } catch (...) { std::cerr << argv[0] << ": Unexpected unknown exception occurred.\n"; }