[llvm] r242655 - Refactor duplicated code. NFC.

Rafael Espindola rafael.espindola at gmail.com
Sun Jul 19 20:01:50 PDT 2015


Author: rafael
Date: Sun Jul 19 22:01:49 2015
New Revision: 242655

URL: http://llvm.org/viewvc/llvm-project?rev=242655&view=rev
Log:
Refactor duplicated code. NFC.

Modified:
    llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp

Modified: llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp?rev=242655&r1=242654&r2=242655&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp (original)
+++ llvm/trunk/tools/llvm-readobj/llvm-readobj.cpp Sun Jul 19 22:01:49 2015
@@ -190,15 +190,19 @@ namespace opts {
 
 static int ReturnValue = EXIT_SUCCESS;
 
+static void reportError(Twine Msg) {
+  ReturnValue = EXIT_FAILURE;
+  outs() << Msg << "\n";
+  outs().flush();
+}
+
 namespace llvm {
 
 bool error(std::error_code EC) {
   if (!EC)
     return false;
 
-  ReturnValue = EXIT_FAILURE;
-  outs() << "\nError reading file: " << EC.message() << ".\n";
-  outs().flush();
+  reportError(Twine("\nError reading file: ") + EC.message() + ".");
   return true;
 }
 
@@ -212,17 +216,14 @@ static void reportError(StringRef Input,
   if (Input == "-")
     Input = "<stdin>";
 
-  errs() << Input << ": " << EC.message() << "\n";
-  errs().flush();
-  ReturnValue = EXIT_FAILURE;
+  reportError(Twine(Input) + ": " + EC.message());
 }
 
 static void reportError(StringRef Input, StringRef Message) {
   if (Input == "-")
     Input = "<stdin>";
 
-  errs() << Input << ": " << Message << "\n";
-  ReturnValue = EXIT_FAILURE;
+  reportError(Twine(Input) + ": " + Message);
 }
 
 static bool isMipsArch(unsigned Arch) {





More information about the llvm-commits mailing list