[lld] r261919 - ELF: Define log() to print out message if --verbose is given.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 25 10:56:03 PST 2016


Author: ruiu
Date: Thu Feb 25 12:56:01 2016
New Revision: 261919

URL: http://llvm.org/viewvc/llvm-project?rev=261919&view=rev
Log:
ELF: Define log() to print out message if --verbose is given.

Modified:
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Error.cpp
    lld/trunk/ELF/Error.h
    lld/trunk/ELF/ICF.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=261919&r1=261918&r2=261919&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Feb 25 12:56:01 2016
@@ -89,8 +89,7 @@ static std::vector<MemoryBufferRef> getA
 // Newly created memory buffers are owned by this driver.
 void LinkerDriver::addFile(StringRef Path) {
   using namespace llvm::sys::fs;
-  if (Config->Verbose)
-    llvm::outs() << Path << "\n";
+  log(Path);
   auto MBOrErr = MemoryBuffer::getFile(Path);
   if (error(MBOrErr, "cannot open " + Path))
     return;

Modified: lld/trunk/ELF/Error.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.cpp?rev=261919&r1=261918&r2=261919&view=diff
==============================================================================
--- lld/trunk/ELF/Error.cpp (original)
+++ lld/trunk/ELF/Error.cpp Thu Feb 25 12:56:01 2016
@@ -8,6 +8,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "Error.h"
+#include "Config.h"
 
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/raw_ostream.h"
@@ -18,6 +19,11 @@ namespace elf2 {
 bool HasError;
 llvm::raw_ostream *ErrorOS;
 
+void log(const Twine &Msg) {
+  if (Config->Verbose)
+    llvm::outs() << Msg << "\n";
+}
+
 void warning(const Twine &Msg) { llvm::errs() << Msg << "\n"; }
 
 void error(const Twine &Msg) {

Modified: lld/trunk/ELF/Error.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Error.h?rev=261919&r1=261918&r2=261919&view=diff
==============================================================================
--- lld/trunk/ELF/Error.h (original)
+++ lld/trunk/ELF/Error.h Thu Feb 25 12:56:01 2016
@@ -22,6 +22,7 @@ namespace elf2 {
 extern bool HasError;
 extern llvm::raw_ostream *ErrorOS;
 
+void log(const Twine &Msg);
 void warning(const Twine &Msg);
 
 void error(const Twine &Msg);

Modified: lld/trunk/ELF/ICF.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ICF.cpp?rev=261919&r1=261918&r2=261919&view=diff
==============================================================================
--- lld/trunk/ELF/ICF.cpp (original)
+++ lld/trunk/ELF/ICF.cpp Thu Feb 25 12:56:01 2016
@@ -349,8 +349,7 @@ template <class ELFT> void ICF<ELFT>::ru
     if (Id == NextId)
       break;
   }
-  if (Config->Verbose)
-    llvm::outs() << "ICF needed " << Cnt << " iterations.\n";
+  log("ICF needed " + Twine(Cnt) + " iterations.");
 
   // Merge sections in the same group.
   for (auto I = V.begin(), E = V.end(); I != E;) {
@@ -360,12 +359,10 @@ template <class ELFT> void ICF<ELFT>::ru
     });
     if (I == Bound)
       continue;
-    if (Config->Verbose)
-      llvm::outs() << "Selected " << Head->getSectionName() << "\n";
+    log("Selected " + Head->getSectionName());
     while (I != Bound) {
       InputSection<ELFT> *S = *I++;
-      if (Config->Verbose)
-        llvm::outs() << "  Removed " << S->getSectionName() << "\n";
+      log("  Removed " + S->getSectionName());
       Head->replace(S);
     }
   }




More information about the llvm-commits mailing list