[lld] r241701 - COFF: Handle /machine option in a similar manner for other options. NFC.

Rui Ueyama ruiu at google.com
Wed Jul 8 11:14:52 PDT 2015


Author: ruiu
Date: Wed Jul  8 13:14:51 2015
New Revision: 241701

URL: http://llvm.org/viewvc/llvm-project?rev=241701&view=rev
Log:
COFF: Handle /machine option in a similar manner for other options. NFC.

Modified:
    lld/trunk/COFF/Config.h
    lld/trunk/COFF/Driver.cpp
    lld/trunk/COFF/Driver.h
    lld/trunk/COFF/DriverUtils.cpp

Modified: lld/trunk/COFF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Config.h?rev=241701&r1=241700&r2=241701&view=diff
==============================================================================
--- lld/trunk/COFF/Config.h (original)
+++ lld/trunk/COFF/Config.h Wed Jul  8 13:14:51 2015
@@ -20,6 +20,7 @@
 namespace lld {
 namespace coff {
 
+using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
 using llvm::COFF::WindowsSubsystem;
 using llvm::StringRef;
 class Undefined;
@@ -45,7 +46,7 @@ struct Export {
 struct Configuration {
   enum ManifestKind { SideBySide, Embed, No };
 
-  llvm::COFF::MachineTypes MachineType = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
+  llvm::COFF::MachineTypes MachineType = IMAGE_FILE_MACHINE_UNKNOWN;
   bool Verbose = false;
   WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
   Undefined *Entry = nullptr;

Modified: lld/trunk/COFF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.cpp?rev=241701&r1=241700&r2=241701&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.cpp (original)
+++ lld/trunk/COFF/Driver.cpp Wed Jul  8 13:14:51 2015
@@ -322,12 +322,12 @@ bool LinkerDriver::link(llvm::ArrayRef<c
   }
 
   // Handle /machine
-  auto MTOrErr = getMachineType(&Args);
-  if (auto EC = MTOrErr.getError()) {
-    llvm::errs() << EC.message() << "\n";
-    return false;
+  if (auto *Arg = Args.getLastArg(OPT_machine)) {
+    ErrorOr<MachineTypes> MTOrErr = getMachineType(Arg->getValue());
+    if (MTOrErr.getError())
+      return false;
+    Config->MachineType = MTOrErr.get();
   }
-  Config->MachineType = MTOrErr.get();
 
   // Handle /nodefaultlib:<filename>
   for (auto *Arg : Args.filtered(OPT_nodefaultlib))

Modified: lld/trunk/COFF/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Driver.h?rev=241701&r1=241700&r2=241701&view=diff
==============================================================================
--- lld/trunk/COFF/Driver.h (original)
+++ lld/trunk/COFF/Driver.h Wed Jul  8 13:14:51 2015
@@ -117,7 +117,7 @@ std::error_code writeImportLibrary();
 void printHelp(const char *Argv0);
 
 // For /machine option.
-ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args);
+ErrorOr<MachineTypes> getMachineType(StringRef Arg);
 StringRef machineTypeToStr(MachineTypes MT);
 
 // Parses a string in the form of "<integer>[,<integer>]".

Modified: lld/trunk/COFF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DriverUtils.cpp?rev=241701&r1=241700&r2=241701&view=diff
==============================================================================
--- lld/trunk/COFF/DriverUtils.cpp (original)
+++ lld/trunk/COFF/DriverUtils.cpp Wed Jul  8 13:14:51 2015
@@ -79,21 +79,16 @@ private:
 } // anonymous namespace
 
 // Returns /machine's value.
-ErrorOr<MachineTypes> getMachineType(llvm::opt::InputArgList *Args) {
-  if (auto *Arg = Args->getLastArg(OPT_machine)) {
-    StringRef S(Arg->getValue());
-    MachineTypes MT = StringSwitch<MachineTypes>(S.lower())
-                          .Case("arm", IMAGE_FILE_MACHINE_ARMNT)
-                          .Case("x64", IMAGE_FILE_MACHINE_AMD64)
-                          .Case("x86", IMAGE_FILE_MACHINE_I386)
-                          .Default(IMAGE_FILE_MACHINE_UNKNOWN);
-    if (MT == IMAGE_FILE_MACHINE_UNKNOWN) {
-      llvm::errs() << "unknown /machine argument" << S << "\n";
-      return make_error_code(LLDError::InvalidOption);
-    }
+ErrorOr<MachineTypes> getMachineType(StringRef S) {
+  MachineTypes MT = StringSwitch<MachineTypes>(S.lower())
+                        .Case("arm", IMAGE_FILE_MACHINE_ARMNT)
+                        .Case("x64", IMAGE_FILE_MACHINE_AMD64)
+                        .Case("x86", IMAGE_FILE_MACHINE_I386)
+                        .Default(IMAGE_FILE_MACHINE_UNKNOWN);
+  if (MT != IMAGE_FILE_MACHINE_UNKNOWN)
     return MT;
-  }
-  return IMAGE_FILE_MACHINE_UNKNOWN;
+  llvm::errs() << "unknown /machine argument" << S << "\n";
+  return make_error_code(LLDError::InvalidOption);
 }
 
 StringRef machineTypeToStr(MachineTypes MT) {





More information about the llvm-commits mailing list