forked from OSchip/llvm-project
Define a utility function to read -O and lto-O options.
llvm-svn: 265056
This commit is contained in:
parent
9a7689db91
commit
b339b6de0d
|
@ -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.
|
||||
|
|
|
@ -170,6 +170,16 @@ getString(opt::InputArgList &Args, unsigned Key, StringRef Default = "") {
|
|||
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::InputArgList &Args) {
|
|||
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::InputArgList &Args) {
|
|||
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") {
|
||||
|
|
Loading…
Reference in New Issue