Split ScriptParser::readMemory.
llvm-svn: 293141
diff --git a/lld/ELF/LinkerScript.cpp b/lld/ELF/LinkerScript.cpp
index 81b9aee..d351eb1 100644
--- a/lld/ELF/LinkerScript.cpp
+++ b/lld/ELF/LinkerScript.cpp
@@ -1017,7 +1017,6 @@
void readGroup();
void readInclude();
void readMemory();
- std::pair<uint32_t, uint32_t> readMemoryAttributes();
void readOutput();
void readOutputArch();
void readOutputFormat();
@@ -1044,6 +1043,9 @@
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 @@
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 @@
}
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())