[lld] r217568 - Make getFlavor function.
Rui Ueyama
ruiu at google.com
Wed Sep 10 20:13:20 PDT 2014
Author: ruiu
Date: Wed Sep 10 22:13:20 2014
New Revision: 217568
URL: http://llvm.org/viewvc/llvm-project?rev=217568&view=rev
Log:
Make getFlavor function.
The dangling "else" at the end of #if looked a bit error-prone.
Make it a separate function. No functionality change.
Modified:
lld/trunk/lib/Driver/UniversalDriver.cpp
Modified: lld/trunk/lib/Driver/UniversalDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/UniversalDriver.cpp?rev=217568&r1=217567&r2=217568&view=diff
==============================================================================
--- lld/trunk/lib/Driver/UniversalDriver.cpp (original)
+++ lld/trunk/lib/Driver/UniversalDriver.cpp Wed Sep 10 22:13:20 2014
@@ -123,6 +123,32 @@ static ProgramNameParts parseProgramName
return ret;
}
+static Flavor getFlavor(int &argc, const char **&argv,
+ std::unique_ptr<llvm::opt::InputArgList> &parsedArgs) {
+#if LLVM_ON_UNIX
+ if (llvm::sys::path::filename(argv[0]).equals("ld")) {
+#if __APPLE__
+ // On a Darwin systems, if linker binary is named "ld", use Darwin driver.
+ return Flavor::darwin_ld;
+#endif
+ // On a ELF based systems, if linker binary is named "ld", use gnu driver.
+ return Flavor::gnu_ld;
+ }
+#endif
+ if (parsedArgs->getLastArg(OPT_core)) {
+ argc--;
+ argv++;
+ return Flavor::core;
+ }
+ if (llvm::opt::Arg *argFlavor = parsedArgs->getLastArg(OPT_flavor)) {
+ argc -= 2;
+ argv += 2;
+ return strToFlavor(argFlavor->getValue());
+ }
+ StringRef name = llvm::sys::path::stem(argv[0]);
+ return strToFlavor(parseProgramName(name)._flavor);
+}
+
namespace lld {
bool UniversalDriver::link(int argc, const char *argv[],
@@ -152,31 +178,9 @@ bool UniversalDriver::link(int argc, con
return true;
}
- Flavor flavor;
-
-#if LLVM_ON_UNIX
- if (llvm::sys::path::filename(argv[0]).equals("ld")) {
-#if __APPLE__
- // On a Darwin systems, if linker binary is named "ld", use Darwin driver.
- flavor = Flavor::darwin_ld;
-#else
- // On a ELF based systems, if linker binary is named "ld", use gnu driver.
- flavor = Flavor::gnu_ld;
-#endif
- } else
-#endif
- if (parsedArgs->getLastArg(OPT_core)) {
- flavor = Flavor::core;
- argv++;
- argc--;
- } else if (llvm::opt::Arg *argFlavor = parsedArgs->getLastArg(OPT_flavor)) {
- flavor = strToFlavor(argFlavor->getValue());
- argv += 2;
- argc -= 2;
- } else
- flavor = strToFlavor(parseProgramName(programName)._flavor);
-
+ Flavor flavor = getFlavor(argc, argv, parsedArgs);
std::vector<const char *> args(argv, argv + argc);
+
// Switch to appropriate driver.
switch (flavor) {
case Flavor::gnu_ld:
More information about the llvm-commits
mailing list