Refactor duplicated code. NFC.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 20 Jul 2015 03:01:49 +0000 (03:01 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 20 Jul 2015 03:01:49 +0000 (03:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242655 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-readobj/llvm-readobj.cpp

index 12afacb0a858e5bce5d7cea19a293f561fbf4ae7..39d2e1c3342c3ca148ac8bd74d8bfce446bfdc16 100644 (file)
@@ -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, std::error_code EC) {
   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) {