[lld] r344099 - Adapt OptTable::PrintHelp change in D51009

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 9 17:15:36 PDT 2018


Author: maskray
Date: Tue Oct  9 17:15:36 2018
New Revision: 344099

URL: http://llvm.org/viewvc/llvm-project?rev=344099&view=rev
Log:
Adapt OptTable::PrintHelp change in D51009

Summary: Before, OptTable::PrintHelp append "[options] <inputs>" to its parameter `Help`. It is more flexible to change its semantic to `Usage` and let user customize the usage line.

Reviewers: rupprecht, ruiu, espindola

Reviewed By: rupprecht

Subscribers: emaste, sbc100, arichardson, aheejin, llvm-commits

Differential Revision: https://reviews.llvm.org/D53054

Modified:
    lld/trunk/COFF/DriverUtils.cpp
    lld/trunk/ELF/DriverUtils.cpp
    lld/trunk/lib/Driver/DarwinLdDriver.cpp
    lld/trunk/wasm/Driver.cpp

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=344099&r1=344098&r2=344099&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Tue Oct  9 17:15:36 2018
@@ -28,6 +28,7 @@
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileUtilities.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
@@ -863,7 +864,8 @@ std::vector<const char *> ArgParser::tok
 }
 
 void printHelp(const char *Argv0) {
-  COFFOptTable().PrintHelp(outs(), Argv0, "LLVM Linker", false);
+  std::string Usage = formatv("{0} [options] file...", Argv0).str();
+  COFFOptTable().PrintHelp(outs(), Usage.c_str(), "LLVM Linker", false);
 }
 
 } // namespace coff

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=344099&r1=344098&r2=344099&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Tue Oct  9 17:15:36 2018
@@ -24,6 +24,7 @@
 #include "llvm/Option/Option.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/FileSystem.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 
@@ -139,8 +140,9 @@ opt::InputArgList ELFOptTable::parse(Arr
 }
 
 void elf::printHelp() {
-  ELFOptTable().PrintHelp(outs(), Config->ProgName.data(), "lld",
-                          false /*ShowHidden*/, true /*ShowAllAliases*/);
+  std::string Usage = formatv("{0} [options] file...", Config->ProgName).str();
+  ELFOptTable().PrintHelp(outs(), Usage.c_str(), "lld", false /*ShowHidden*/,
+                          true /*ShowAllAliases*/);
   outs() << "\n";
 
   // Scripts generated by Libtool versions up to at least 2.4.6 (the most

Modified: lld/trunk/lib/Driver/DarwinLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/DarwinLdDriver.cpp?rev=344099&r1=344098&r2=344099&view=diff
==============================================================================
--- lld/trunk/lib/Driver/DarwinLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/DarwinLdDriver.cpp Tue Oct  9 17:15:36 2018
@@ -44,6 +44,7 @@
 #include "llvm/Support/Error.h"
 #include "llvm/Support/ErrorOr.h"
 #include "llvm/Support/Format.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
@@ -382,10 +383,13 @@ bool parse(llvm::ArrayRef<const char *>
     if (arch == MachOLinkingContext::arch_unknown &&
         !parsedArgs.getLastArg(OPT_test_file_usage)) {
       // If no -arch and no options at all, print usage message.
-      if (parsedArgs.size() == 0)
-        table.PrintHelp(llvm::outs(), args[0], "LLVM Linker", false);
-      else
+      if (parsedArgs.size() == 0) {
+        std::string Usage =
+            llvm::formatv("{0} [options] file...", args[0]).str();
+        table.PrintHelp(llvm::outs(), Usage.c_str(), "LLVM Linker", false);
+      } else {
         error("-arch not specified and could not be inferred");
+      }
       return false;
     }
   }

Modified: lld/trunk/wasm/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Driver.cpp?rev=344099&r1=344098&r2=344099&view=diff
==============================================================================
--- lld/trunk/wasm/Driver.cpp (original)
+++ lld/trunk/wasm/Driver.cpp Tue Oct  9 17:15:36 2018
@@ -24,6 +24,7 @@
 #include "llvm/Object/Wasm.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Support/CommandLine.h"
+#include "llvm/Support/FormatVariadic.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/TargetSelect.h"
@@ -349,7 +350,8 @@ void LinkerDriver::link(ArrayRef<const c
 
   // Handle --help
   if (Args.hasArg(OPT_help)) {
-    Parser.PrintHelp(outs(), ArgsArr[0], "LLVM Linker", false);
+    std::string Usage = formatv("{0} [options] file...", ArgsArr[0]).str();
+    Parser.PrintHelp(outs(), Usage.c_str(), "LLVM Linker", false);
     return;
   }
 




More information about the llvm-commits mailing list