[lld] r274109 - Create Strings.cpp and move string manipulation functions to that file.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 29 01:01:33 PDT 2016


Author: ruiu
Date: Wed Jun 29 03:01:32 2016
New Revision: 274109

URL: http://llvm.org/viewvc/llvm-project?rev=274109&view=rev
Log:
Create Strings.cpp and move string manipulation functions to that file.

Added:
    lld/trunk/ELF/Strings.cpp
    lld/trunk/ELF/Strings.h
Modified:
    lld/trunk/ELF/CMakeLists.txt
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/DriverUtils.cpp
    lld/trunk/ELF/LinkerScript.cpp
    lld/trunk/ELF/LinkerScript.h
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/ELF/ScriptParser.h
    lld/trunk/ELF/SymbolTable.cpp

Modified: lld/trunk/ELF/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/CMakeLists.txt?rev=274109&r1=274108&r2=274109&view=diff
==============================================================================
--- lld/trunk/ELF/CMakeLists.txt (original)
+++ lld/trunk/ELF/CMakeLists.txt Wed Jun 29 03:01:32 2016
@@ -16,6 +16,7 @@ add_lld_library(lldELF
   OutputSections.cpp
   Relocations.cpp
   ScriptParser.cpp
+  Strings.cpp
   SymbolListFile.cpp
   SymbolTable.cpp
   Symbols.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=274109&r1=274108&r2=274109&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed Jun 29 03:01:32 2016
@@ -14,6 +14,7 @@
 #include "InputFiles.h"
 #include "InputSection.h"
 #include "LinkerScript.h"
+#include "Strings.h"
 #include "SymbolListFile.h"
 #include "SymbolTable.h"
 #include "Target.h"
@@ -402,7 +403,7 @@ void LinkerDriver::readConfigs(opt::Inpu
       Config->BuildId = BuildIdKind::None;
     } else if (S.startswith("0x")) {
       Config->BuildId = BuildIdKind::Hexstring;
-      Config->BuildIdVector = parseHexstring(S.substr(2));
+      Config->BuildIdVector = parseHex(S.substr(2));
     } else {
       error("unknown --build-id style: " + S);
     }

Modified: lld/trunk/ELF/DriverUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/DriverUtils.cpp?rev=274109&r1=274108&r2=274109&view=diff
==============================================================================
--- lld/trunk/ELF/DriverUtils.cpp (original)
+++ lld/trunk/ELF/DriverUtils.cpp Wed Jun 29 03:01:32 2016
@@ -88,22 +88,6 @@ std::string elf::getVersionString() {
   return "LLD " + Version + " " + Repo + "\n";
 }
 
-// Converts a hex string (e.g. "0x123456") to a vector.
-std::vector<uint8_t> elf::parseHexstring(StringRef S) {
-  if (S.find_first_not_of("0123456789abcdefABCDEF") != StringRef::npos ||
-      S.size() % 2) {
-    error("malformed hexstring: " + S);
-    return {};
-  }
-  std::vector<uint8_t> V;
-  for (; !S.empty(); S = S.substr(2)) {
-    int I;
-    S.substr(0, 2).getAsInteger(16, I);
-    V.push_back(I);
-  }
-  return V;
-}
-
 // Makes a given pathname an absolute path first, and then remove
 // beginning /. For example, "../foo.o" is converted to "home/john/foo.o",
 // assuming that the current directory is "/home/john/bar".

Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=274109&r1=274108&r2=274109&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Wed Jun 29 03:01:32 2016
@@ -19,6 +19,7 @@
 #include "InputSection.h"
 #include "OutputSections.h"
 #include "ScriptParser.h"
+#include "Strings.h"
 #include "SymbolTable.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ELF.h"
@@ -286,30 +287,6 @@ int LinkerScript<ELFT>::compareSections(
   return I < J ? -1 : 1;
 }
 
-// Returns true if S matches T. S can contain glob meta-characters.
-// The asterisk ('*') matches zero or more characters, and the question
-// mark ('?') matches one character.
-bool elf::globMatch(StringRef S, StringRef T) {
-  for (;;) {
-    if (S.empty())
-      return T.empty();
-    if (S[0] == '*') {
-      S = S.substr(1);
-      if (S.empty())
-        // Fast path. If a pattern is '*', it matches anything.
-        return true;
-      for (size_t I = 0, E = T.size(); I < E; ++I)
-        if (globMatch(S, T.substr(I)))
-          return true;
-      return false;
-    }
-    if (T.empty() || (S[0] != T[0] && S[0] != '?'))
-      return false;
-    S = S.substr(1);
-    T = T.substr(1);
-  }
-}
-
 class elf::ScriptParser : public ScriptParserBase {
   typedef void (ScriptParser::*Handler)();
 

Modified: lld/trunk/ELF/LinkerScript.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.h?rev=274109&r1=274108&r2=274109&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.h (original)
+++ lld/trunk/ELF/LinkerScript.h Wed Jun 29 03:01:32 2016
@@ -19,8 +19,6 @@
 namespace lld {
 namespace elf {
 
-bool globMatch(StringRef S, StringRef T);
-
 // Parses a linker script. Calling this function updates
 // Config and ScriptConfig.
 void readLinkerScript(MemoryBufferRef MB);

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=274109&r1=274108&r2=274109&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Wed Jun 29 03:01:32 2016
@@ -161,18 +161,3 @@ size_t ScriptParserBase::getPos() {
   const char *Tok = Tokens[Pos - 1].data();
   return StringRef(Begin, Tok - Begin).count('\n') + 1;
 }
-
-std::vector<uint8_t> ScriptParserBase::parseHex(StringRef S) {
-  std::vector<uint8_t> Hex;
-  while (!S.empty()) {
-    StringRef B = S.substr(0, 2);
-    S = S.substr(2);
-    uint8_t H;
-    if (B.getAsInteger(16, H)) {
-      setError("not a hexadecimal value: " + B);
-      return {};
-    }
-    Hex.push_back(H);
-  }
-  return Hex;
-}

Modified: lld/trunk/ELF/ScriptParser.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.h?rev=274109&r1=274108&r2=274109&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.h (original)
+++ lld/trunk/ELF/ScriptParser.h Wed Jun 29 03:01:32 2016
@@ -37,8 +37,6 @@ protected:
   size_t getPos();
   void printErrorPos();
 
-  std::vector<uint8_t> parseHex(StringRef S);
-
   StringRef Input;
   std::vector<StringRef> Tokens;
   size_t Pos = 0;

Added: lld/trunk/ELF/Strings.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.cpp?rev=274109&view=auto
==============================================================================
--- lld/trunk/ELF/Strings.cpp (added)
+++ lld/trunk/ELF/Strings.cpp Wed Jun 29 03:01:32 2016
@@ -0,0 +1,57 @@
+//===- Strings.cpp -------------------------------------------------------===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "Strings.h"
+#include "Error.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
+
+using namespace llvm;
+using namespace lld;
+using namespace lld::elf;
+
+// Returns true if S matches T. S can contain glob meta-characters.
+// The asterisk ('*') matches zero or more characters, and the question
+// mark ('?') matches one character.
+bool elf::globMatch(StringRef S, StringRef T) {
+  for (;;) {
+    if (S.empty())
+      return T.empty();
+    if (S[0] == '*') {
+      S = S.substr(1);
+      if (S.empty())
+        // Fast path. If a pattern is '*', it matches anything.
+        return true;
+      for (size_t I = 0, E = T.size(); I < E; ++I)
+        if (globMatch(S, T.substr(I)))
+          return true;
+      return false;
+    }
+    if (T.empty() || (S[0] != T[0] && S[0] != '?'))
+      return false;
+    S = S.substr(1);
+    T = T.substr(1);
+  }
+}
+
+// Converts a hex string (e.g. "deadbeef") to a vector.
+std::vector<uint8_t> elf::parseHex(StringRef S) {
+  std::vector<uint8_t> Hex;
+  while (!S.empty()) {
+    StringRef B = S.substr(0, 2);
+    S = S.substr(2);
+    uint8_t H;
+    if (B.getAsInteger(16, H)) {
+      error("not a hexadecimal value: " + B);
+      return {};
+    }
+    Hex.push_back(H);
+  }
+  return Hex;
+}

Added: lld/trunk/ELF/Strings.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Strings.h?rev=274109&view=auto
==============================================================================
--- lld/trunk/ELF/Strings.h (added)
+++ lld/trunk/ELF/Strings.h Wed Jun 29 03:01:32 2016
@@ -0,0 +1,23 @@
+//===- Strings.h ------------------------------------------------*- C++ -*-===//
+//
+//                             The LLVM Linker
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLD_COFF_STRINGS_H
+#define LLD_COFF_STRINGS_H
+
+#include "lld/Core/LLVM.h"
+#include <vector>
+
+namespace lld {
+namespace elf {
+bool globMatch(StringRef S, StringRef T);
+std::vector<uint8_t> parseHex(StringRef S);
+}
+}
+
+#endif

Modified: lld/trunk/ELF/SymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/SymbolTable.cpp?rev=274109&r1=274108&r2=274109&view=diff
==============================================================================
--- lld/trunk/ELF/SymbolTable.cpp (original)
+++ lld/trunk/ELF/SymbolTable.cpp Wed Jun 29 03:01:32 2016
@@ -18,6 +18,7 @@
 #include "Config.h"
 #include "Error.h"
 #include "LinkerScript.h"
+#include "Strings.h"
 #include "Symbols.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Support/StringSaver.h"




More information about the llvm-commits mailing list