[lld] r249592 - ELF2: Define a utility function to handle simple command line options.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 7 12:34:51 PDT 2015
Author: ruiu
Date: Wed Oct 7 14:34:51 2015
New Revision: 249592
URL: http://llvm.org/viewvc/llvm-project?rev=249592&view=rev
Log:
ELF2: Define a utility function to handle simple command line 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=249592&r1=249591&r2=249592&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed Oct 7 14:34:51 2015
@@ -29,8 +29,8 @@ enum ELFKind {
struct Configuration {
llvm::StringRef DynamicLinker;
llvm::StringRef Entry;
- llvm::StringRef Fini = "_fini";
- llvm::StringRef Init = "_init";
+ llvm::StringRef Fini;
+ llvm::StringRef Init;
llvm::StringRef OutputFile;
llvm::StringRef SoName;
llvm::StringRef Sysroot;
Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=249592&r1=249591&r2=249592&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Oct 7 14:34:51 2015
@@ -139,18 +139,19 @@ void LinkerDriver::addFile(StringRef Pat
}
}
+static StringRef
+getString(opt::InputArgList &Args, unsigned Key, StringRef Default = "") {
+ if (auto *Arg = Args.getLastArg(Key))
+ return Arg->getValue();
+ return Default;
+}
+
void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
// Parse command line options.
opt::InputArgList Args = Parser.parse(ArgsArr);
- if (auto *Arg = Args.getLastArg(OPT_output))
- Config->OutputFile = Arg->getValue();
-
- if (auto *Arg = Args.getLastArg(OPT_dynamic_linker))
- Config->DynamicLinker = Arg->getValue();
-
- if (auto *Arg = Args.getLastArg(OPT_sysroot))
- Config->Sysroot = Arg->getValue();
+ for (auto *Arg : Args.filtered(OPT_L))
+ Config->InputSearchPaths.push_back(Arg->getValue());
std::vector<StringRef> RPaths;
for (auto *Arg : Args.filtered(OPT_rpath))
@@ -158,21 +159,6 @@ void LinkerDriver::link(ArrayRef<const c
if (!RPaths.empty())
Config->RPath = llvm::join(RPaths.begin(), RPaths.end(), ":");
- for (auto *Arg : Args.filtered(OPT_L))
- Config->InputSearchPaths.push_back(Arg->getValue());
-
- if (auto *Arg = Args.getLastArg(OPT_entry))
- Config->Entry = Arg->getValue();
-
- if (auto *Arg = Args.getLastArg(OPT_fini))
- Config->Fini = Arg->getValue();
-
- if (auto *Arg = Args.getLastArg(OPT_init))
- Config->Init = Arg->getValue();
-
- if (auto *Arg = Args.getLastArg(OPT_soname))
- Config->SoName = Arg->getValue();
-
if (auto *Arg = Args.getLastArg(OPT_m))
setELFType(Arg->getValue());
@@ -186,6 +172,14 @@ void LinkerDriver::link(ArrayRef<const c
Config->NoUndefined = Args.hasArg(OPT_no_undefined);
Config->Shared = Args.hasArg(OPT_shared);
+ Config->DynamicLinker = getString(Args, OPT_dynamic_linker);
+ Config->Entry = getString(Args, OPT_entry);
+ Config->Fini = getString(Args, OPT_fini, "_fini");
+ Config->Init = getString(Args, OPT_init, "_init");
+ Config->OutputFile = getString(Args, OPT_output);
+ Config->SoName = getString(Args, OPT_soname);
+ Config->Sysroot = getString(Args, OPT_sysroot);
+
for (auto *Arg : Args.filtered(OPT_z))
if (Arg->getValue() == StringRef("now"))
Config->ZNow = true;
More information about the llvm-commits
mailing list