Split ScriptParser::readMemory.

llvm-svn: 293141
This commit is contained in:
Rui Ueyama 2017-01-26 02:58:19 +00:00
parent 728c290daf
commit 24e626cc76

View File

@ -1017,7 +1017,6 @@ private:
void readGroup();
void readInclude();
void readMemory();
std::pair<uint32_t, uint32_t> readMemoryAttributes();
void readOutput();
void readOutputArch();
void readOutputFormat();
@ -1044,6 +1043,9 @@ private:
void readSort();
Expr readAssert();
uint64_t readMemoryAssignment(StringRef, StringRef, StringRef);
std::pair<uint32_t, uint32_t> readMemoryAttributes();
Expr readExpr();
Expr readExpr1(Expr Lhs, int MinPrec);
StringRef readParenLiteral();
@ -2000,12 +2002,30 @@ std::vector<SymbolVersion> ScriptParser::readVersionExtern() {
return Ret;
}
// Parse the MEMORY command As specified in:
// https://sourceware.org/binutils/docs/ld/MEMORY.html#MEMORY
uint64_t ScriptParser::readMemoryAssignment(
StringRef S1, StringRef S2, StringRef S3) {
if (!(consume(S1) || consume(S2) || consume(S3))) {
setError("expected one of: " + S1 + ", " + S2 + ", or " + S3);
return 0;
}
expect("=");
// TODO: Fully support constant expressions.
uint64_t Val;
if (!readInteger(next(), Val))
setError("nonconstant expression for "+ S1);
return Val;
}
// Parse the MEMORY command as specified in:
// https://sourceware.org/binutils/docs/ld/MEMORY.html
//
// MEMORY { name [(attr)] : ORIGIN = origin, LENGTH = len ... }
void ScriptParser::readMemory() {
expect("{");
while (!Error && !consume("}")) {
StringRef Name = next();
uint32_t Flags = 0;
uint32_t NotFlags = 0;
if (consume("(")) {
@ -2014,32 +2034,10 @@ void ScriptParser::readMemory() {
}
expect(":");
// Parse the ORIGIN.
if (!(consume("ORIGIN") || consume("org") || consume("o"))) {
setError("expected one of: ORIGIN, org, or o");
return;
}
expect("=");
uint64_t Origin;
// TODO: Fully support constant expressions.
if (!readInteger(next(), Origin)) {
setError("nonconstant expression for origin");
return;
}
uint64_t Origin = readMemoryAssignment("ORIGIN", "org", "o");
expect(",");
uint64_t Length = readMemoryAssignment("LENGTH", "len", "l");
// Parse the LENGTH.
if (!(consume("LENGTH") || consume("len") || consume("l"))) {
setError("expected one of: LENGTH, len, or l");
return;
}
expect("=");
uint64_t Length;
// TODO: Fully support constant expressions.
if (!readInteger(next(), Length)) {
setError("nonconstant expression for length");
return;
}
// Add the memory region to the region map (if it doesn't already exist).
auto It = Opt.MemoryRegions.find(Name);
if (It != Opt.MemoryRegions.end())