[lld] r185657 - Don't pass llvm::errs() all over the place. Diagnostics always go to stderr.

Rafael Espindola rafael.espindola at gmail.com
Thu Jul 4 10:06:04 PDT 2013


Author: rafael
Date: Thu Jul  4 12:06:04 2013
New Revision: 185657

URL: http://llvm.org/viewvc/llvm-project?rev=185657&view=rev
Log:
Don't pass llvm::errs() all over the place. Diagnostics always go to stderr.

Modified:
    lld/trunk/include/lld/Driver/Driver.h
    lld/trunk/lib/Driver/CoreDriver.cpp
    lld/trunk/lib/Driver/DarwinLdDriver.cpp
    lld/trunk/lib/Driver/Driver.cpp
    lld/trunk/lib/Driver/GnuLdDriver.cpp
    lld/trunk/lib/Driver/UniversalDriver.cpp
    lld/trunk/lib/Driver/WinLinkDriver.cpp

Modified: lld/trunk/include/lld/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/Driver.h?rev=185657&r1=185656&r2=185657&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/Driver.h (original)
+++ lld/trunk/include/lld/Driver/Driver.h Thu Jul  4 12:06:04 2013
@@ -20,7 +20,6 @@
 #include "lld/Core/LLVM.h"
 
 #include "llvm/ADT/Triple.h"
-#include "llvm/Support/raw_ostream.h"
 
 #include <memory>
 #include <vector>
@@ -37,8 +36,7 @@ class Driver {
 protected:
 
   /// Performs link using specified options.
-  static bool link(const TargetInfo &targetInfo,
-                   raw_ostream &diagnostics = llvm::errs());
+  static bool link(const TargetInfo &targetInfo);
 private:
   Driver() LLVM_DELETED_FUNCTION;
 };
@@ -49,8 +47,7 @@ private:
 class UniversalDriver : public Driver {
 public:
   /// Determine flavor and pass control to Driver for that flavor.
-  static bool link(int argc, const char *argv[],
-                   raw_ostream &diagnostics = llvm::errs());
+  static bool link(int argc, const char *argv[]);
 
 private:
   UniversalDriver() LLVM_DELETED_FUNCTION;
@@ -62,14 +59,12 @@ class GnuLdDriver : public Driver {
 public:
   /// Parses command line arguments same as gnu/binutils ld and performs link.
   /// Returns true iff an error occurred.
-  static bool linkELF(int argc, const char *argv[],
-                  raw_ostream &diagnostics = llvm::errs());
+  static bool linkELF(int argc, const char *argv[]);
 
   /// Uses gnu/binutils style ld command line options to fill in options struct.
   /// Returns true iff there was an error.
   static bool parse(int argc, const char *argv[],
-                    std::unique_ptr<ELFTargetInfo> &targetInfo,
-                    raw_ostream &diagnostics = llvm::errs());
+                    std::unique_ptr<ELFTargetInfo> &targetInfo);
 
 private:
   static llvm::Triple getDefaultTarget(const char *progName);
@@ -83,13 +78,11 @@ class DarwinLdDriver : public Driver {
 public:
   /// Parses command line arguments same as darwin's ld and performs link.
   /// Returns true iff there was an error.
-  static bool linkMachO(int argc, const char *argv[],
-                        raw_ostream &diagnostics = llvm::errs());
+  static bool linkMachO(int argc, const char *argv[]);
 
   /// Uses darwin style ld command line options to update targetInfo object.
   /// Returns true iff there was an error.
-  static bool parse(int argc, const char *argv[], MachOTargetInfo &info,
-                    raw_ostream &diagnostics = llvm::errs());
+  static bool parse(int argc, const char *argv[], MachOTargetInfo &info);
 private:
   DarwinLdDriver() LLVM_DELETED_FUNCTION;
 };
@@ -100,13 +93,11 @@ class WinLinkDriver : public Driver {
 public:
   /// Parses command line arguments same as Windows link.exe and performs link.
   /// Returns true iff there was an error.
-  static bool linkPECOFF(int argc, const char *argv[],
-                         raw_ostream &diagnostics = llvm::errs());
+  static bool linkPECOFF(int argc, const char *argv[]);
 
   /// Uses Windows style link command line options to fill in options struct.
   /// Returns true iff there was an error.
-  static bool parse(int argc, const char *argv[], PECOFFTargetInfo &info,
-                    raw_ostream &diagnostics = llvm::errs());
+  static bool parse(int argc, const char *argv[], PECOFFTargetInfo &info);
 
 private:
   WinLinkDriver() LLVM_DELETED_FUNCTION;
@@ -119,13 +110,11 @@ public:
 
   /// Parses command line arguments same as lld-core and performs link.
   /// Returns true iff there was an error.
-  static bool link(int argc, const char *argv[],
-                   raw_ostream &diagnostics = llvm::errs());
+  static bool link(int argc, const char *argv[]);
 
   /// Uses lld-core command line options to fill in options struct.
   /// Returns true iff there was an error.
-  static bool parse(int argc, const char *argv[], CoreTargetInfo &info,
-                    raw_ostream &diagnostics = llvm::errs());
+  static bool parse(int argc, const char *argv[], CoreTargetInfo &info);
 
 private:
   CoreDriver() LLVM_DELETED_FUNCTION;

Modified: lld/trunk/lib/Driver/CoreDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/CoreDriver.cpp?rev=185657&r1=185656&r2=185657&view=diff
==============================================================================
--- lld/trunk/lib/Driver/CoreDriver.cpp (original)
+++ lld/trunk/lib/Driver/CoreDriver.cpp Thu Jul  4 12:06:04 2013
@@ -67,17 +67,15 @@ public:
 
 namespace lld {
 
-bool CoreDriver::link(int argc, const char *argv[], raw_ostream &diagnostics) {
+bool CoreDriver::link(int argc, const char *argv[]) {
   CoreTargetInfo info;
   if (parse(argc, argv, info))
     return true;
-  
+
   return Driver::link(info);
 }
 
-
-bool CoreDriver::parse(int argc, const char *argv[],  
-                          CoreTargetInfo &info, raw_ostream &diagnostics) {
+bool CoreDriver::parse(int argc, const char *argv[], CoreTargetInfo &info) {
   // Parse command line options using CoreOptions.td
   std::unique_ptr<llvm::opt::InputArgList> parsedArgs;
   CoreOptTable table;
@@ -86,15 +84,15 @@ bool CoreDriver::parse(int argc, const c
   parsedArgs.reset(table.ParseArgs(&argv[1], &argv[argc], 
                                                 missingIndex, missingCount));
   if (missingCount) {
-    diagnostics  << "error: missing arg value for '"
-                 << parsedArgs->getArgString(missingIndex)
-                 << "' expected " << missingCount << " argument(s).\n";
+    llvm::errs() << "error: missing arg value for '"
+                 << parsedArgs->getArgString(missingIndex) << "' expected "
+                 << missingCount << " argument(s).\n";
     return true;
   }
 
   for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
             ie = parsedArgs->filtered_end(); it != ie; ++it) {
-    diagnostics  << "warning: ignoring unknown argument: "
+    llvm::errs() << "warning: ignoring unknown argument: "
                  << (*it)->getAsString(*parsedArgs) << "\n";
   }
   

Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=185657&r1=185656&r2=185657&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Thu Jul  4 12:06:04 2013
@@ -70,19 +70,16 @@ public:
 
 namespace lld {
 
-bool DarwinLdDriver::linkMachO(int argc, const char *argv[], 
-                                                    raw_ostream &diagnostics) {
+bool DarwinLdDriver::linkMachO(int argc, const char *argv[]) {
   MachOTargetInfo info;
-  if (parse(argc, argv, info, diagnostics))
+  if (parse(argc, argv, info))
     return true;
-    
-  return link(info, diagnostics);
-}
-
 
+  return link(info);
+}
 
-bool DarwinLdDriver::parse(int argc, const char *argv[],  
-                          MachOTargetInfo &info, raw_ostream &diagnostics) {
+bool DarwinLdDriver::parse(int argc, const char *argv[],
+                           MachOTargetInfo &info) {
   // Parse command line options using DarwinOptions.td
   std::unique_ptr<llvm::opt::InputArgList> parsedArgs;
   DarwinLdOptTable table;
@@ -91,15 +88,15 @@ bool DarwinLdDriver::parse(int argc, con
   parsedArgs.reset(table.ParseArgs(&argv[1], &argv[argc], 
                                                 missingIndex, missingCount));
   if (missingCount) {
-    diagnostics  << "error: missing arg value for '"
-                 << parsedArgs->getArgString(missingIndex)
-                 << "' expected " << missingCount << " argument(s).\n";
+    llvm::errs() << "error: missing arg value for '"
+                 << parsedArgs->getArgString(missingIndex) << "' expected "
+                 << missingCount << " argument(s).\n";
     return true;
   }
 
   for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
             ie = parsedArgs->filtered_end(); it != ie; ++it) {
-    diagnostics  << "warning: ignoring unknown argument: "
+    llvm::errs() << "warning: ignoring unknown argument: "
                  << (*it)->getAsString(*parsedArgs) << "\n";
   }
   
@@ -158,19 +155,19 @@ bool DarwinLdDriver::parse(int argc, con
     switch (minOS->getOption().getID()) {
     case OPT_macosx_version_min:
       if (info.setOS(MachOTargetInfo::OS::macOSX, minOS->getValue())) {
-        diagnostics << "error: malformed macosx_version_min value\n";
+        llvm::errs() << "error: malformed macosx_version_min value\n";
         return true;
       }
       break;
     case OPT_ios_version_min:
       if (info.setOS(MachOTargetInfo::OS::iOS, minOS->getValue())) {
-        diagnostics << "error: malformed ios_version_min value\n";
+        llvm::errs() << "error: malformed ios_version_min value\n";
         return true;
       }
       break;
     case OPT_ios_simulator_version_min:
       if (info.setOS(MachOTargetInfo::OS::iOS_simulator, minOS->getValue())) {
-        diagnostics << "error: malformed ios_simulator_version_min value\n";
+        llvm::errs() << "error: malformed ios_simulator_version_min value\n";
         return true;
       }
       break;
@@ -187,9 +184,9 @@ bool DarwinLdDriver::parse(int argc, con
                               it != ie; ++it) {
     info.appendInputFile((*it)->getValue());
   }
-  
+
   // Validate the combination of options used.
-  if (info.validate(diagnostics))
+  if (info.validate(llvm::errs()))
     return true;
 
   return false;

Modified: lld/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/Driver.cpp?rev=185657&r1=185656&r2=185657&view=diff
==============================================================================
--- lld/trunk/lib/Driver/Driver.cpp (original)
+++ lld/trunk/lib/Driver/Driver.cpp Thu Jul  4 12:06:04 2013
@@ -29,7 +29,7 @@
 namespace lld {
 
 /// This is where the link is actually performed.
-bool Driver::link(const TargetInfo &targetInfo, raw_ostream &diagnostics) {
+bool Driver::link(const TargetInfo &targetInfo) {
   // Honor -mllvm
   if (!targetInfo.llvmOptions().empty()) {
     unsigned numArgs = targetInfo.llvmOptions().size();
@@ -52,10 +52,10 @@ bool Driver::link(const TargetInfo &targ
     if (targetInfo.logInputFiles())
       llvm::outs() << input.getPath() << "\n";
 
-    tg.spawn([&, index] {
+    tg.spawn([ &, index]{
       if (error_code ec = targetInfo.readFile(input.getPath(), files[index])) {
-        diagnostics << "Failed to read file: " << input.getPath()
-                    << ": " << ec.message() << "\n";
+        llvm::errs() << "Failed to read file: " << input.getPath() << ": "
+                     << ec.message() << "\n";
         fail = true;
         return;
       }
@@ -98,8 +98,8 @@ bool Driver::link(const TargetInfo &targ
   // Give linked atoms to Writer to generate output file.
   ScopedTask writeTask(getDefaultDomain(), "Write");
   if (error_code ec = targetInfo.writeFile(merged)) {
-    diagnostics << "Failed to write file '" << targetInfo.outputPath() 
-                << "': " << ec.message() << "\n";
+    llvm::errs() << "Failed to write file '" << targetInfo.outputPath()
+                 << "': " << ec.message() << "\n";
     return true;
   }
 

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=185657&r1=185656&r2=185657&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Thu Jul  4 12:06:04 2013
@@ -70,23 +70,19 @@ public:
 
 } // namespace
 
-
-
-bool GnuLdDriver::linkELF(int argc, const char *argv[],
-                                                  raw_ostream &diagnostics) {
+bool GnuLdDriver::linkELF(int argc, const char *argv[]) {
   std::unique_ptr<ELFTargetInfo> options;
-  bool error = parse(argc, argv, options, diagnostics);
+  bool error = parse(argc, argv, options);
   if (error)
     return true;
   if (!options)
     return false;
 
-  return link(*options, diagnostics);
+  return link(*options);
 }
 
 bool GnuLdDriver::parse(int argc, const char *argv[],
-                        std::unique_ptr<ELFTargetInfo> &targetInfo,
-                        raw_ostream &diagnostics) {
+                        std::unique_ptr<ELFTargetInfo> &targetInfo) {
   // Parse command line options using LDOptions.td
   std::unique_ptr<llvm::opt::InputArgList> parsedArgs;
   GnuLdOptTable table;
@@ -95,17 +91,16 @@ bool GnuLdDriver::parse(int argc, const
   parsedArgs.reset(
       table.ParseArgs(&argv[1], &argv[argc], missingIndex, missingCount));
   if (missingCount) {
-    diagnostics << "error: missing arg value for '"
-                << parsedArgs->getArgString(missingIndex) << "' expected "
-                << missingCount << " argument(s).\n";
+    llvm::errs() << "error: missing arg value for '"
+                 << parsedArgs->getArgString(missingIndex) << "' expected "
+                 << missingCount << " argument(s).\n";
     return true;
   }
 
   for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
             ie = parsedArgs->filtered_end(); it != ie; ++it) {
-    diagnostics << "warning: ignoring unknown argument: " << (*it)->getAsString(
-                                                                 *parsedArgs)
-                << "\n";
+    llvm::errs() << "warning: ignoring unknown argument: "
+                 << (*it)->getAsString(*parsedArgs) << "\n";
   }
 
   // Handle --help
@@ -123,7 +118,7 @@ bool GnuLdDriver::parse(int argc, const
   std::unique_ptr<ELFTargetInfo> options(ELFTargetInfo::create(triple));
 
   if (!options) {
-    diagnostics << "unknown target triple\n";
+    llvm::errs() << "unknown target triple\n";
     return true;
   }
 
@@ -253,8 +248,8 @@ bool GnuLdDriver::parse(int argc, const
       break;
     case OPT_l:
       if (options->appendLibrary((*it)->getValue())) {
-        diagnostics << "Failed to find library for " << (*it)->getValue()
-                    << "\n";
+        llvm::errs() << "Failed to find library for " << (*it)->getValue()
+                     << "\n";
         return true;
       }
       break;
@@ -264,7 +259,7 @@ bool GnuLdDriver::parse(int argc, const
   }
 
   // Validate the combination of options used.
-  if (options->validate(diagnostics))
+  if (options->validate(llvm::errs()))
     return true;
 
   targetInfo.swap(options);

Modified: lld/trunk/lib/Driver/UniversalDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/UniversalDriver.cpp?rev=185657&r1=185656&r2=185657&view=diff
==============================================================================
--- lld/trunk/lib/Driver/UniversalDriver.cpp (original)
+++ lld/trunk/lib/Driver/UniversalDriver.cpp Thu Jul  4 12:06:04 2013
@@ -80,7 +80,7 @@ ProgramNameParts parseProgramName(String
   return ret;
 }
 
-Flavor selectFlavor(std::vector<const char *> &args, raw_ostream &diag) {
+Flavor selectFlavor(std::vector<const char *> &args) {
   // -core as first arg is shorthand for -flavor core.
   if (args.size() > 1 && StringRef(args[1]) == "-core") {
     args.erase(args.begin() + 1);
@@ -92,7 +92,7 @@ Flavor selectFlavor(std::vector<const ch
     args.erase(args.begin() + 1);
     args.erase(args.begin() + 1);
     if (flavor == Flavor::invalid)
-      diag << "error: '" << args[2] << "' invalid value for -flavor.\n";
+      llvm::errs() << "error: '" << args[2] << "' invalid value for -flavor.\n";
     return flavor;
   }
 
@@ -101,33 +101,32 @@ Flavor selectFlavor(std::vector<const ch
 
   // If flavor still undetermined, then error out.
   if (flavor == Flavor::invalid)
-    diag << "error: failed to determine driver flavor from program name"
-         << " '" << args[0] << "'.\n"
-         << "select a flavor with -flavor [gnu|darwin|link|core].\n";
+    llvm::errs() << "error: failed to determine driver flavor from program name"
+                 << " '" << args[0] << "'.\n"
+                 << "select a flavor with -flavor [gnu|darwin|link|core].\n";
   return flavor;
 }
 }
 
 namespace lld {
-bool UniversalDriver::link(int argc, const char *argv[],
-                           raw_ostream &diagnostics) {
+bool UniversalDriver::link(int argc, const char *argv[]) {
   // Convert argv[] C-array to vector.
   std::vector<const char *> args(argv, argv + argc);
 
   // Determine flavor of link based on command name or -flavor argument.
   // Note: 'args' is modified to remove -flavor option.
-  Flavor flavor = selectFlavor(args, diagnostics);
+  Flavor flavor = selectFlavor(args);
 
   // Switch to appropriate driver.
   switch (flavor) {
   case Flavor::gnu_ld:
-    return GnuLdDriver::linkELF(args.size(), args.data(), diagnostics);
+    return GnuLdDriver::linkELF(args.size(), args.data());
   case Flavor::darwin_ld:
-    return DarwinLdDriver::linkMachO(args.size(), args.data(), diagnostics);
+    return DarwinLdDriver::linkMachO(args.size(), args.data());
   case Flavor::win_link:
-    return WinLinkDriver::linkPECOFF(args.size(), args.data(), diagnostics);
+    return WinLinkDriver::linkPECOFF(args.size(), args.data());
   case Flavor::core:
-    return CoreDriver::link(args.size(), args.data(), diagnostics);
+    return CoreDriver::link(args.size(), args.data());
   case Flavor::invalid:
     return true;
   }

Modified: lld/trunk/lib/Driver/WinLinkDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/WinLinkDriver.cpp?rev=185657&r1=185656&r2=185657&view=diff
==============================================================================
--- lld/trunk/lib/Driver/WinLinkDriver.cpp (original)
+++ lld/trunk/lib/Driver/WinLinkDriver.cpp Thu Jul  4 12:06:04 2013
@@ -185,16 +185,15 @@ StringRef getDefaultOutputFileName(PECOF
 } // namespace
 
 
-bool WinLinkDriver::linkPECOFF(int argc, const char *argv[],
-                               raw_ostream &diagnostics) {
+bool WinLinkDriver::linkPECOFF(int argc, const char *argv[]) {
   PECOFFTargetInfo info;
-  if (parse(argc, argv, info, diagnostics))
+  if (parse(argc, argv, info))
     return true;
-  return link(info, diagnostics);
+  return link(info);
 }
 
 bool WinLinkDriver::parse(int argc, const char *argv[],
-                          PECOFFTargetInfo &info, raw_ostream &diagnostics) {
+                          PECOFFTargetInfo &info) {
   // Arguments after "--" are interpreted as filenames even if they start with
   // a hyphen or a slash. This is not compatible with link.exe but useful for
   // us to test lld on Unix.
@@ -209,9 +208,9 @@ bool WinLinkDriver::parse(int argc, cons
   parsedArgs.reset(
       table.ParseArgs(&argv[1], &argv[argEnd], missingIndex, missingCount));
   if (missingCount) {
-    diagnostics << "error: missing arg value for '"
-                << parsedArgs->getArgString(missingIndex) << "' expected "
-                << missingCount << " argument(s).\n";
+    llvm::errs() << "error: missing arg value for '"
+                 << parsedArgs->getArgString(missingIndex) << "' expected "
+                 << missingCount << " argument(s).\n";
     return true;
   }
 
@@ -224,8 +223,8 @@ bool WinLinkDriver::parse(int argc, cons
   // Show warning for unknown arguments
   for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
             ie = parsedArgs->filtered_end(); it != ie; ++it) {
-    diagnostics << "warning: ignoring unknown argument: "
-                << (*it)->getAsString(*parsedArgs) << "\n";
+    llvm::errs() << "warning: ignoring unknown argument: "
+                 << (*it)->getAsString(*parsedArgs) << "\n";
   }
 
   // Copy -mllvm
@@ -237,17 +236,17 @@ bool WinLinkDriver::parse(int argc, cons
 
   // Handle -stack
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_stack))
-    if (!parseStackOption(info, arg->getValue(), diagnostics))
+    if (!parseStackOption(info, arg->getValue(), llvm::errs()))
       return true;
 
   // Handle -heap
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_heap))
-    if (!parseHeapOption(info, arg->getValue(), diagnostics))
+    if (!parseHeapOption(info, arg->getValue(), llvm::errs()))
       return true;
 
   // Handle -subsystem
   if (llvm::opt::Arg *arg = parsedArgs->getLastArg(OPT_subsystem))
-    if (!parseSubsystemOption(info, arg->getValue(), diagnostics))
+    if (!parseSubsystemOption(info, arg->getValue(), llvm::errs()))
       return true;
 
   // Handle -entry
@@ -289,7 +288,7 @@ bool WinLinkDriver::parse(int argc, cons
     info.setOutputPath(getDefaultOutputFileName(info, inputPaths[0]));
 
   // Validate the combination of options used.
-  return info.validate(diagnostics);
+  return info.validate(llvm::errs());
 }
 
 } // namespace lld





More information about the llvm-commits mailing list