[lld] r265056 - Define a utility function to read -O and lto-O options.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 31 14:15:31 PDT 2016


Author: ruiu
Date: Thu Mar 31 16:15:31 2016
New Revision: 265056

URL: http://llvm.org/viewvc/llvm-project?rev=265056&view=rev
Log:
Define a utility function to read -O and lto-O options.

Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=265056&r1=265055&r2=265056&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Thu Mar 31 16:15:31 2016
@@ -90,8 +90,8 @@ struct Configuration {
   ELFKind EKind = ELFNoneKind;
   uint16_t EMachine = llvm::ELF::EM_NONE;
   uint64_t EntryAddr = -1;
-  unsigned LtoO = 2;
-  unsigned Optimize = 0;
+  unsigned LtoO;
+  unsigned Optimize;
 };
 
 // The only instance of Configuration struct.

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=265056&r1=265055&r2=265056&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Mar 31 16:15:31 2016
@@ -170,6 +170,16 @@ getString(opt::InputArgList &Args, unsig
   return Default;
 }
 
+static int getInteger(opt::InputArgList &Args, unsigned Key, int Default) {
+  int V = Default;
+  if (auto *Arg = Args.getLastArg(Key)) {
+    StringRef S = Arg->getValue();
+    if (S.getAsInteger(10, V))
+      error(Arg->getSpelling() + ": number expected, but got " + S);
+  }
+  return V;
+}
+
 static bool hasZOption(opt::InputArgList &Args, StringRef Key) {
   for (auto *Arg : Args.filtered(OPT_z))
     if (Key == Arg->getValue())
@@ -265,6 +275,9 @@ void LinkerDriver::readConfigs(opt::Inpu
   Config->SoName = getString(Args, OPT_soname);
   Config->Sysroot = getString(Args, OPT_sysroot);
 
+  Config->Optimize = getInteger(Args, OPT_O, 0);
+  Config->LtoO = getInteger(Args, OPT_lto_O, 2);
+
   Config->ZExecStack = hasZOption(Args, "execstack");
   Config->ZNodelete = hasZOption(Args, "nodelete");
   Config->ZNow = hasZOption(Args, "now");
@@ -276,18 +289,6 @@ void LinkerDriver::readConfigs(opt::Inpu
   if (Config->Relocatable)
     Config->StripAll = false;
 
-  if (auto *Arg = Args.getLastArg(OPT_O)) {
-    StringRef Val = Arg->getValue();
-    if (Val.getAsInteger(10, Config->Optimize))
-      error("invalid optimization level");
-  }
-
-  if (auto *Arg = Args.getLastArg(OPT_lto_O)) {
-    StringRef Val = Arg->getValue();
-    if (Val.getAsInteger(10, Config->LtoO))
-      error("invalid optimization level");
-  }
-
   if (auto *Arg = Args.getLastArg(OPT_hash_style)) {
     StringRef S = Arg->getValue();
     if (S == "gnu") {




More information about the llvm-commits mailing list