Update for llvm api change.
authorRafael Espindola <rafael.espindola@gmail.com>
Sat, 13 Jun 2015 12:50:13 +0000 (12:50 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Sat, 13 Jun 2015 12:50:13 +0000 (12:50 +0000)
llvm-svn: 239671

lld/COFF/Driver.cpp
lld/COFF/Driver.h
lld/COFF/DriverUtils.cpp
lld/COFF/InputFiles.h
lld/COFF/Memory.h [deleted file]
lld/COFF/SymbolTable.h
lld/include/lld/ReaderWriter/PECOFFLinkingContext.h
lld/lib/Driver/GnuLdDriver.cpp
lld/lib/Driver/WinLinkDriver.cpp
lld/lib/ReaderWriter/PECOFF/ReaderCOFF.cpp

index 63f680c..257c9b4 100644 (file)
@@ -10,7 +10,6 @@
 #include "Config.h"
 #include "Driver.h"
 #include "InputFiles.h"
-#include "Memory.h"
 #include "SymbolTable.h"
 #include "Writer.h"
 #include "llvm/ADT/Optional.h"
index d66b289..45bcfbf 100644 (file)
 #ifndef LLD_COFF_DRIVER_H
 #define LLD_COFF_DRIVER_H
 
-#include "Memory.h"
+#include "lld/Core/LLVM.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Object/COFF.h"
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
+#include "llvm/Support/StringSaver.h"
 #include <memory>
 #include <set>
 #include <system_error>
@@ -37,6 +38,7 @@ bool link(int Argc, const char *Argv[]);
 
 class ArgParser {
 public:
+  ArgParser() : Alloc(AllocAux) {}
   // Parses command line options.
   ErrorOr<std::unique_ptr<llvm::opt::InputArgList>> parse(int Argc,
                                                           const char *Argv[]);
@@ -55,12 +57,13 @@ private:
   ErrorOr<std::vector<const char *>>
   replaceResponseFiles(std::vector<const char *>);
 
-  StringAllocator Alloc;
+  llvm::BumpPtrAllocator AllocAux;
+  llvm::BumpPtrStringSaver Alloc;
 };
 
 class LinkerDriver {
 public:
LinkerDriver() : SearchPaths(getSearchPaths()) {}
 LinkerDriver() : Alloc(AllocAux), SearchPaths(getSearchPaths()) {}
   bool link(int Argc, const char *Argv[]);
 
   // Used by the resolver to parse .drectve section contents.
@@ -68,7 +71,8 @@ public:
   parseDirectives(StringRef S, std::vector<std::unique_ptr<InputFile>> *Res);
 
 private:
-  StringAllocator Alloc;
+  llvm::BumpPtrAllocator AllocAux;
+  llvm::BumpPtrStringSaver Alloc;
   ArgParser Parser;
 
   // Opens a file. Path has to be resolved already.
index b12e97a..22fdb8b 100644 (file)
@@ -16,7 +16,6 @@
 #include "Config.h"
 #include "Driver.h"
 #include "Error.h"
-#include "Memory.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
@@ -197,20 +196,9 @@ ArgParser::parse(int Argc, const char *Argv[]) {
   return parse(V);
 }
 
-namespace {
-class BumpPtrStringSaver : public llvm::cl::StringSaver {
-public:
-  BumpPtrStringSaver(lld::coff::StringAllocator *A) : Alloc(A) {}
-  const char *SaveString(const char *S) override {
-    return Alloc->save(S).data();
-  }
-  lld::coff::StringAllocator *Alloc;
-};
-}
-
 std::vector<const char *> ArgParser::tokenize(StringRef S) {
   SmallVector<const char *, 16> Tokens;
-  BumpPtrStringSaver Saver(&Alloc);
+  BumpPtrStringSaver Saver(AllocAux);
   llvm::cl::TokenizeWindowsCommandLine(S, Saver, Tokens);
   return std::vector<const char *>(Tokens.begin(), Tokens.end());
 }
@@ -220,7 +208,7 @@ std::vector<const char *> ArgParser::tokenize(StringRef S) {
 ErrorOr<std::vector<const char *>>
 ArgParser::replaceResponseFiles(std::vector<const char *> Argv) {
   SmallVector<const char *, 256> Tokens(&Argv[0], &Argv[0] + Argv.size());
-  BumpPtrStringSaver Saver(&Alloc);
+  BumpPtrStringSaver Saver(AllocAux);
   ExpandResponseFiles(Saver, TokenizeWindowsCommandLine, Tokens);
   return std::vector<const char *>(Tokens.begin(), Tokens.end());
 }
index 9b46e8f..389a603 100644 (file)
 #define LLD_COFF_INPUT_FILES_H
 
 #include "Chunks.h"
-#include "Memory.h"
 #include "Symbols.h"
 #include "lld/Core/LLVM.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/LTO/LTOModule.h"
 #include "llvm/Object/Archive.h"
 #include "llvm/Object/COFF.h"
+#include "llvm/Support/StringSaver.h"
 #include <memory>
 #include <set>
 #include <vector>
@@ -144,7 +144,8 @@ private:
 // for details about the format.
 class ImportFile : public InputFile {
 public:
-  explicit ImportFile(MemoryBufferRef M) : InputFile(ImportKind, M) {}
+  explicit ImportFile(MemoryBufferRef M)
+      : InputFile(ImportKind, M), StringAlloc(StringAllocAux) {}
   static bool classof(const InputFile *F) { return F->kind() == ImportKind; }
   std::vector<SymbolBody *> &getSymbols() override { return SymbolBodies; }
 
@@ -153,7 +154,8 @@ private:
 
   std::vector<SymbolBody *> SymbolBodies;
   llvm::BumpPtrAllocator Alloc;
-  StringAllocator StringAlloc;
+  llvm::BumpPtrAllocator StringAllocAux;
+  llvm::BumpPtrStringSaver StringAlloc;
 };
 
 // Used for LTO.
diff --git a/lld/COFF/Memory.h b/lld/COFF/Memory.h
deleted file mode 100644 (file)
index 8ff4a42..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-//===- Memory.h -----------------------------------------------------------===//
-//
-//                             The LLVM Linker
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef LLD_COFF_MEMORY_H
-#define LLD_COFF_MEMORY_H
-
-#include "lld/Core/LLVM.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
-#include "llvm/Support/Allocator.h"
-#include <memory>
-
-namespace lld {
-namespace coff {
-
-class StringAllocator {
-public:
-  // Returns a null-terminated copy of a string.
-  StringRef save(StringRef S) {
-    char *P = Alloc.Allocate<char>(S.size() + 1);
-    memcpy(P, S.data(), S.size());
-    P[S.size()] = '\0';
-    return StringRef(P, S.size());
-  }
-
-  StringRef save(Twine S) { return save(StringRef(S.str())); }
-  StringRef save(const char *S) { return save(StringRef(S)); }
-  StringRef save(std::string &S) { return save(StringRef(S)); }
-
-private:
-  llvm::BumpPtrAllocator Alloc;
-};
-
-} // namespace coff
-} // namespace lld
-
-#endif
index f50b816..df52982 100644 (file)
@@ -11,7 +11,6 @@
 #define LLD_COFF_SYMBOL_TABLE_H
 
 #include "InputFiles.h"
-#include "Memory.h"
 #include "llvm/Support/Allocator.h"
 #include <unordered_map>
 
index 2e19dd8..aadf2d6 100644 (file)
@@ -277,6 +277,8 @@ public:
     return is64Bit() ? "__delayLoadHelper2" : "___delayLoadHelper2@8";
   }
 
+  llvm::BumpPtrAllocator &getAllocator() { return _allocator; }
+
   StringRef allocate(StringRef ref) const {
     _allocMutex.lock();
     char *x = _allocator.Allocate<char>(ref.size() + 1);
index 0375ec8..935908b 100644 (file)
@@ -31,6 +31,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include <cstring>
@@ -74,20 +75,6 @@ public:
   GnuLdOptTable() : OptTable(infoTable, llvm::array_lengthof(infoTable)){}
 };
 
-class DriverStringSaver : public llvm::cl::StringSaver {
-public:
-  DriverStringSaver(BumpPtrAllocator &alloc) : _alloc(alloc) {}
-
-  const char *SaveString(const char *s) override {
-    char *p = _alloc.Allocate<char>(strlen(s) + 1);
-    strcpy(p, s);
-    return p;
-  }
-
-private:
-  BumpPtrAllocator &_alloc;
-};
-
 } // anonymous namespace
 
 // If a command line option starts with "@", the driver reads its suffix as a
@@ -101,7 +88,7 @@ maybeExpandResponseFiles(int argc, const char **argv, BumpPtrAllocator &alloc) {
   SmallVector<const char *, 256> smallvec;
   for (int i = 0; i < argc; ++i)
     smallvec.push_back(argv[i]);
-  DriverStringSaver saver(alloc);
+  llvm::BumpPtrStringSaver saver(alloc);
   llvm::cl::ExpandResponseFiles(saver, llvm::cl::TokenizeGNUCommandLine, smallvec);
 
   // Pack the results to a C-array and return it.
index 7bc26bb..80bd0b3 100644 (file)
@@ -29,6 +29,7 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Process.h"
 #include "llvm/Support/Program.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <cctype>
@@ -694,20 +695,6 @@ static void processLibEnv(PECOFFLinkingContext &ctx) {
       ctx.appendInputSearchPath(ctx.allocate(path));
 }
 
-namespace {
-class DriverStringSaver : public llvm::cl::StringSaver {
-public:
-  DriverStringSaver(PECOFFLinkingContext &ctx) : _ctx(ctx) {}
-
-  const char *SaveString(const char *s) override {
-    return _ctx.allocate(StringRef(s)).data();
-  }
-
-private:
-  PECOFFLinkingContext &_ctx;
-};
-}
-
 // Tokenize command line options in a given file and add them to result.
 static bool readResponseFile(StringRef path, PECOFFLinkingContext &ctx,
                              std::vector<const char *> &result) {
@@ -716,7 +703,7 @@ static bool readResponseFile(StringRef path, PECOFFLinkingContext &ctx,
     return false;
   StringRef contentsStr(reinterpret_cast<const char *>(contents.data()),
                         contents.size());
-  DriverStringSaver saver(ctx);
+  llvm::BumpPtrStringSaver saver(ctx.getAllocator());
   SmallVector<const char *, 0> args;
   llvm::cl::TokenizeWindowsCommandLine(contentsStr, saver, args);
   for (const char *s : args)
index 813580e..46cf15c 100644 (file)
@@ -29,6 +29,7 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
+#include "llvm/Support/StringSaver.h"
 #include "llvm/Support/raw_ostream.h"
 #include <algorithm>
 #include <map>
@@ -54,14 +55,12 @@ using namespace lld;
 
 namespace {
 
-class BumpPtrStringSaver : public llvm::cl::StringSaver {
+class BumpPtrStringSaver final : public llvm::StringSaver {
 public:
-  const char *SaveString(const char *str) override {
-    size_t len = strlen(str);
+  BumpPtrStringSaver() : llvm::StringSaver(_alloc) {}
+  const char *saveImpl(StringRef Str) override {
     std::lock_guard<std::mutex> lock(_allocMutex);
-    char *copy = _alloc.Allocate<char>(len + 1);
-    memcpy(copy, str, len + 1);
-    return copy;
+    return llvm::StringSaver::saveImpl(Str);
   }
 
 private: