[lld] r293141 - Split ScriptParser::readMemory.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 25 18:58:19 PST 2017


Author: ruiu
Date: Wed Jan 25 20:58:19 2017
New Revision: 293141

URL: http://llvm.org/viewvc/llvm-project?rev=293141&view=rev
Log:
Split ScriptParser::readMemory.

Modified:
    lld/trunk/ELF/LinkerScript.cpp

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=293141&r1=293140&r2=293141&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Jan 25 20:58:19 2017
@@ -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:
   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())




More information about the llvm-commits mailing list