forked from OSchip/llvm-project
Make getFlavor function.
The dangling "else" at the end of #if looked a bit error-prone. Make it a separate function. No functionality change. llvm-svn: 217568
This commit is contained in:
parent
8e5f548b81
commit
a726ef12a4
|
@ -123,6 +123,32 @@ static ProgramNameParts parseProgramName(StringRef programName) {
|
|||
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, const char *argv[],
|
|||
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:
|
||||
|
|
Loading…
Reference in New Issue