[lld] r226292 - Split a function for readability.

Rui Ueyama ruiu at google.com
Fri Jan 16 09:53:56 PST 2015


Author: ruiu
Date: Fri Jan 16 11:53:55 2015
New Revision: 226292

URL: http://llvm.org/viewvc/llvm-project?rev=226292&view=rev
Log:
Split a function for readability.

Modified:
    lld/trunk/lib/Driver/GnuLdDriver.cpp

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=226292&r1=226291&r2=226292&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Fri Jan 16 11:53:55 2015
@@ -233,6 +233,32 @@ static bool isPathUnderSysroot(StringRef
 }
 
 static std::error_code
+evaluateLinkerScriptGroup(ELFLinkingContext &ctx, StringRef path,
+                          const script::Group *group, raw_ostream &diag) {
+  bool sysroot = (!ctx.getSysroot().empty()
+                  && isPathUnderSysroot(ctx.getSysroot(), path));
+  int numfiles = 0;
+  for (const script::Path &path : group->getPaths()) {
+    ErrorOr<StringRef> pathOrErr = path._isDashlPrefix
+      ? ctx.searchLibrary(path._path) : ctx.searchFile(path._path, sysroot);
+    if (std::error_code ec = pathOrErr.getError())
+      return make_dynamic_error_code(
+        Twine("Unable to find file ") + path._path + ": " + ec.message());
+
+    std::vector<std::unique_ptr<File>> files
+      = loadFile(ctx, pathOrErr.get(), false);
+    for (std::unique_ptr<File> &file : files) {
+      if (ctx.logInputFiles())
+        diag << file->path() << "\n";
+      ctx.getNodes().push_back(llvm::make_unique<FileNode>(std::move(file)));
+      ++numfiles;
+    }
+  }
+  ctx.getNodes().push_back(llvm::make_unique<GroupEnd>(numfiles));
+  return std::error_code();
+}
+
+static std::error_code
 evaluateLinkerScript(ELFLinkingContext &ctx, StringRef path,
                      raw_ostream &diag) {
   // Read the script file from disk and parse.
@@ -248,32 +274,10 @@ evaluateLinkerScript(ELFLinkingContext &
 
   // Evaluate script commands.
   // Currently we only recognize GROUP() command.
-  bool sysroot = (!ctx.getSysroot().empty()
-                  && isPathUnderSysroot(ctx.getSysroot(), path));
-  for (const script::Command *c : script->_commands) {
-    auto *group = dyn_cast<script::Group>(c);
-    if (!group)
-      continue;
-    int numfiles = 0;
-    for (const script::Path &path : group->getPaths()) {
-      // TODO : Propagate Set WholeArchive/dashlPrefix
-      ErrorOr<StringRef> pathOrErr = path._isDashlPrefix
-          ? ctx.searchLibrary(path._path) : ctx.searchFile(path._path, sysroot);
-      if (std::error_code ec = pathOrErr.getError())
-        return make_dynamic_error_code(
-            Twine("Unable to find file ") + path._path + ": " + ec.message());
-
-      std::vector<std::unique_ptr<File>> files
-          = loadFile(ctx, pathOrErr.get(), false);
-      for (std::unique_ptr<File> &file : files) {
-        if (ctx.logInputFiles())
-          diag << file->path() << "\n";
-        ctx.getNodes().push_back(llvm::make_unique<FileNode>(std::move(file)));
-        ++numfiles;
-      }
-    }
-    ctx.getNodes().push_back(llvm::make_unique<GroupEnd>(numfiles));
-  }
+  for (const script::Command *c : script->_commands)
+    if (auto *group = dyn_cast<script::Group>(c))
+      if (std::error_code ec = evaluateLinkerScriptGroup(ctx, path, group, diag))
+        return ec;
   return std::error_code();
 }
 





More information about the llvm-commits mailing list