mirror of
https://github.com/intel/llvm.git
synced 2026-01-18 16:50:51 +08:00
[ELF] - Use llvm::to_integer() instead of StringRef::getAsInteger().
Switch to llvm::to_integer() everywhere in LLD instead of StringRef::getAsInteger() because API of latter is confusing. It returns true on error and false otherwise what makes reading the code incomfortable. Differential revision: https://reviews.llvm.org/D33187 llvm-svn: 303149
This commit is contained in:
@@ -284,7 +284,7 @@ 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))
|
||||
if (!to_integer(S, V, 10))
|
||||
error(Arg->getSpelling() + ": number expected, but got " + S);
|
||||
}
|
||||
return V;
|
||||
@@ -311,7 +311,7 @@ static uint64_t getZOptionValue(opt::InputArgList &Args, StringRef Key,
|
||||
if (Pos != StringRef::npos && Key == Value.substr(0, Pos)) {
|
||||
Value = Value.substr(Pos + 1);
|
||||
uint64_t Result;
|
||||
if (Value.getAsInteger(0, Result))
|
||||
if (!to_integer(Value, Result))
|
||||
error("invalid " + Key + ": " + Value);
|
||||
return Result;
|
||||
}
|
||||
@@ -522,7 +522,7 @@ static uint64_t parseSectionAddress(StringRef S, opt::Arg *Arg) {
|
||||
uint64_t VA = 0;
|
||||
if (S.startswith("0x"))
|
||||
S = S.drop_front(2);
|
||||
if (S.getAsInteger(16, VA))
|
||||
if (!to_integer(S, VA, 16))
|
||||
error("invalid argument: " + toString(Arg));
|
||||
return VA;
|
||||
}
|
||||
@@ -886,7 +886,7 @@ static uint64_t getImageBase(opt::InputArgList &Args) {
|
||||
|
||||
StringRef S = Arg->getValue();
|
||||
uint64_t V;
|
||||
if (S.getAsInteger(0, V)) {
|
||||
if (!to_integer(S, V)) {
|
||||
error("-image-base: number expected, but got " + S);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -639,7 +639,7 @@ ScriptParser::readOutputSectionDescription(StringRef OutSec) {
|
||||
// We are compatible with ld.gold because it's easier to implement.
|
||||
uint32_t ScriptParser::parseFill(StringRef Tok) {
|
||||
uint32_t V = 0;
|
||||
if (Tok.getAsInteger(0, V))
|
||||
if (!to_integer(Tok, V))
|
||||
setError("invalid filler expression: " + Tok);
|
||||
|
||||
uint32_t Buf;
|
||||
@@ -778,23 +778,23 @@ static Optional<uint64_t> parseInt(StringRef Tok) {
|
||||
|
||||
// Hexadecimal
|
||||
uint64_t Val;
|
||||
if (Tok.startswith_lower("0x") && !Tok.substr(2).getAsInteger(16, Val))
|
||||
if (Tok.startswith_lower("0x") && to_integer(Tok.substr(2), Val, 16))
|
||||
return Val;
|
||||
if (Tok.endswith_lower("H") && !Tok.drop_back().getAsInteger(16, Val))
|
||||
if (Tok.endswith_lower("H") && to_integer(Tok.drop_back(), Val, 16))
|
||||
return Val;
|
||||
|
||||
// Decimal
|
||||
if (Tok.endswith_lower("K")) {
|
||||
if (Tok.drop_back().getAsInteger(10, Val))
|
||||
if (!to_integer(Tok.drop_back(), Val, 10))
|
||||
return None;
|
||||
return Val * 1024;
|
||||
}
|
||||
if (Tok.endswith_lower("M")) {
|
||||
if (Tok.drop_back().getAsInteger(10, Val))
|
||||
if (!to_integer(Tok.drop_back(), Val, 10))
|
||||
return None;
|
||||
return Val * 1024 * 1024;
|
||||
}
|
||||
if (Tok.getAsInteger(10, Val))
|
||||
if (!to_integer(Tok, Val, 10))
|
||||
return None;
|
||||
return Val;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ int elf::getPriority(StringRef S) {
|
||||
if (Pos == StringRef::npos)
|
||||
return 65536;
|
||||
int V;
|
||||
if (S.substr(Pos + 1).getAsInteger(10, V))
|
||||
if (!to_integer(S.substr(Pos + 1), V, 10))
|
||||
return 65536;
|
||||
return V;
|
||||
}
|
||||
@@ -68,7 +68,7 @@ std::vector<uint8_t> elf::parseHex(StringRef S) {
|
||||
StringRef B = S.substr(0, 2);
|
||||
S = S.substr(2);
|
||||
uint8_t H;
|
||||
if (B.getAsInteger(16, H)) {
|
||||
if (!to_integer(B, H, 16)) {
|
||||
error("not a hexadecimal value: " + B);
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1590,7 +1590,7 @@ template <class ELFT> uint64_t Writer<ELFT>::getEntryAddr() {
|
||||
if (SymbolBody *B = Symtab<ELFT>::X->find(Config->Entry))
|
||||
return B->getVA();
|
||||
uint64_t Addr;
|
||||
if (!Config->Entry.getAsInteger(0, Addr))
|
||||
if (to_integer(Config->Entry, Addr))
|
||||
return Addr;
|
||||
|
||||
// Case 4
|
||||
|
||||
Reference in New Issue
Block a user