Modify LTOModule::isTargetMatch to take a StringRef instead of a MemoryBuffer.
authorPeter Collingbourne <peter@pcc.me.uk>
Thu, 3 Jul 2014 23:49:28 +0000 (23:49 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Thu, 3 Jul 2014 23:49:28 +0000 (23:49 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@212305 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/LTO/LTOModule.h
lib/LTO/LTOModule.cpp

index 46cb034cb6ea3510688cd76b7d974ca01abecf5a..64c066e6520e6750c8172b5e01a520660001626e 100644 (file)
@@ -202,8 +202,8 @@ private:
   /// Get string that the data pointer points to.
   bool objcClassNameFromExpression(const Constant *c, std::string &name);
 
   /// Get string that the data pointer points to.
   bool objcClassNameFromExpression(const Constant *c, std::string &name);
 
-  /// Returns 'true' if the memory buffer is for the specified target triple.
-  static bool isTargetMatch(MemoryBuffer *memBuffer, const char *triplePrefix);
+  /// Returns 'true' if the bitcode BC is for the specified target triple.
+  static bool isTargetMatch(StringRef BC, const char *TriplePrefix);
 
   /// Create an LTOModule (private version). N.B. This method takes ownership of
   /// the buffer.
 
   /// Create an LTOModule (private version). N.B. This method takes ownership of
   /// the buffer.
index 7d3446ebc177e2159818eb9f0cbcd15a1fc1f086..6ba99eda219f81ab025c1015b7ebc5a02c6f87e8 100644 (file)
@@ -75,7 +75,7 @@ bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length,
   MemoryBuffer *buffer = makeBuffer(mem, length);
   if (!buffer)
     return false;
   MemoryBuffer *buffer = makeBuffer(mem, length);
   if (!buffer)
     return false;
-  return isTargetMatch(buffer, triplePrefix);
+  return isTargetMatch(StringRef((const char *)mem, length), triplePrefix);
 }
 
 bool LTOModule::isBitcodeFileForTarget(const char *path,
 }
 
 bool LTOModule::isBitcodeFileForTarget(const char *path,
@@ -83,15 +83,15 @@ bool LTOModule::isBitcodeFileForTarget(const char *path,
   std::unique_ptr<MemoryBuffer> buffer;
   if (MemoryBuffer::getFile(path, buffer))
     return false;
   std::unique_ptr<MemoryBuffer> buffer;
   if (MemoryBuffer::getFile(path, buffer))
     return false;
-  return isTargetMatch(buffer.release(), triplePrefix);
+  return isTargetMatch(buffer->getBuffer(), triplePrefix);
 }
 
 }
 
-/// isTargetMatch - Returns 'true' if the memory buffer is for the specified
-/// target triple.
-bool LTOModule::isTargetMatch(MemoryBuffer *buffer, const char *triplePrefix) {
-  std::string Triple = getBitcodeTargetTriple(buffer, getGlobalContext());
-  delete buffer;
-  return strncmp(Triple.c_str(), triplePrefix, strlen(triplePrefix)) == 0;
+/// Returns 'true' if the bitcode BC is for the specified target triple.
+bool LTOModule::isTargetMatch(StringRef BC, const char *TriplePrefix) {
+  std::unique_ptr<MemoryBuffer> Buffer(
+      MemoryBuffer::getMemBuffer(BC, "", false));
+  std::string Triple = getBitcodeTargetTriple(Buffer.get(), getGlobalContext());
+  return strncmp(Triple.c_str(), TriplePrefix, strlen(TriplePrefix)) == 0;
 }
 
 LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,
 }
 
 LTOModule *LTOModule::createFromFile(const char *path, TargetOptions options,