From d7f75eeffc289dcb877dea8cf4fafaef8e3c46e9 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Thu, 3 Jul 2014 23:49:28 +0000 Subject: [PATCH] Modify LTOModule::isTargetMatch to take a StringRef instead of a MemoryBuffer. llvm-svn: 212305 --- llvm/include/llvm/LTO/LTOModule.h | 4 ++-- llvm/lib/LTO/LTOModule.cpp | 16 ++++++++-------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/llvm/include/llvm/LTO/LTOModule.h b/llvm/include/llvm/LTO/LTOModule.h index 46cb034..64c066e 100644 --- a/llvm/include/llvm/LTO/LTOModule.h +++ b/llvm/include/llvm/LTO/LTOModule.h @@ -202,8 +202,8 @@ private: /// 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. diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp index 7d3446e..6ba99ed 100644 --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -75,7 +75,7 @@ bool LTOModule::isBitcodeFileForTarget(const void *mem, size_t length, 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, @@ -83,15 +83,15 @@ bool LTOModule::isBitcodeFileForTarget(const char *path, std::unique_ptr 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 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, -- 2.7.4