[llvm-branch-commits] [llvm-branch] r101505 - in /llvm/branches/Apple/Morbo: include/llvm/Support/MemoryBuffer.h lib/AsmParser/Parser.cpp lib/Support/MemoryBuffer.cpp tools/lto/LTOModule.cpp utils/FileCheck/FileCheck.cpp

Daniel Dunbar daniel at zuster.org
Fri Apr 16 11:33:25 PDT 2010


Author: ddunbar
Date: Fri Apr 16 13:33:25 2010
New Revision: 101505

URL: http://llvm.org/viewvc/llvm-project?rev=101505&view=rev
Log:
stringref-ize the MemoryBuffer::get apis. This requires a co-committed clang patch.

Modified:
    llvm/branches/Apple/Morbo/include/llvm/Support/MemoryBuffer.h
    llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp
    llvm/branches/Apple/Morbo/lib/Support/MemoryBuffer.cpp
    llvm/branches/Apple/Morbo/tools/lto/LTOModule.cpp
    llvm/branches/Apple/Morbo/utils/FileCheck/FileCheck.cpp

Modified: llvm/branches/Apple/Morbo/include/llvm/Support/MemoryBuffer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/include/llvm/Support/MemoryBuffer.h?rev=101505&r1=101504&r2=101505&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/include/llvm/Support/MemoryBuffer.h (original)
+++ llvm/branches/Apple/Morbo/include/llvm/Support/MemoryBuffer.h Fri Apr 16 13:33:25 2010
@@ -65,13 +65,13 @@
 
   /// getMemBuffer - Open the specified memory range as a MemoryBuffer.  Note
   /// that EndPtr[0] must be a null byte and be accessible!
-  static MemoryBuffer *getMemBuffer(const char *StartPtr, const char *EndPtr,
+  static MemoryBuffer *getMemBuffer(StringRef InputData,
                                     const char *BufferName = "");
 
   /// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
   /// copying the contents and taking ownership of it.  This has no requirements
   /// on EndPtr[0].
-  static MemoryBuffer *getMemBufferCopy(const char *StartPtr,const char *EndPtr,
+  static MemoryBuffer *getMemBufferCopy(StringRef InputData,
                                         const char *BufferName = "");
 
   /// getNewMemBuffer - Allocate a new MemoryBuffer of the specified size that

Modified: llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp?rev=101505&r1=101504&r2=101505&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/AsmParser/Parser.cpp Fri Apr 16 13:33:25 2010
@@ -56,7 +56,7 @@
 Module *llvm::ParseAssemblyString(const char *AsmString, Module *M,
                                   SMDiagnostic &Err, LLVMContext &Context) {
   MemoryBuffer *F =
-    MemoryBuffer::getMemBuffer(AsmString, AsmString+strlen(AsmString),
+    MemoryBuffer::getMemBuffer(StringRef(AsmString, strlen(AsmString)),
                                "<string>");
 
   return ParseAssembly(F, M, Err, Context);

Modified: llvm/branches/Apple/Morbo/lib/Support/MemoryBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/lib/Support/MemoryBuffer.cpp?rev=101505&r1=101504&r2=101505&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/branches/Apple/Morbo/lib/Support/MemoryBuffer.cpp Fri Apr 16 13:33:25 2010
@@ -70,13 +70,12 @@
 class MemoryBufferMem : public MemoryBuffer {
   std::string FileID;
 public:
-  MemoryBufferMem(const char *Start, const char *End, StringRef FID,
-                  bool Copy = false)
+  MemoryBufferMem(StringRef InputData, StringRef FID, bool Copy = false)
   : FileID(FID) {
     if (!Copy)
-      init(Start, End);
+      init(InputData.data(), InputData.data()+InputData.size());
     else
-      initCopyOf(Start, End);
+      initCopyOf(InputData.data(), InputData.data()+InputData.size());
   }
   
   virtual const char *getBufferIdentifier() const {
@@ -87,19 +86,17 @@
 
 /// getMemBuffer - Open the specified memory range as a MemoryBuffer.  Note
 /// that EndPtr[0] must be a null byte and be accessible!
-MemoryBuffer *MemoryBuffer::getMemBuffer(const char *StartPtr, 
-                                         const char *EndPtr,
+MemoryBuffer *MemoryBuffer::getMemBuffer(StringRef InputData,
                                          const char *BufferName) {
-  return new MemoryBufferMem(StartPtr, EndPtr, BufferName);
+  return new MemoryBufferMem(InputData, BufferName);
 }
 
 /// getMemBufferCopy - Open the specified memory range as a MemoryBuffer,
 /// copying the contents and taking ownership of it.  This has no requirements
 /// on EndPtr[0].
-MemoryBuffer *MemoryBuffer::getMemBufferCopy(const char *StartPtr, 
-                                             const char *EndPtr,
+MemoryBuffer *MemoryBuffer::getMemBufferCopy(StringRef InputData,
                                              const char *BufferName) {
-  return new MemoryBufferMem(StartPtr, EndPtr, BufferName, true);
+  return new MemoryBufferMem(InputData, BufferName, true);
 }
 
 /// getNewUninitMemBuffer - Allocate a new MemoryBuffer of the specified size
@@ -111,7 +108,7 @@
   char *Buf = (char *)malloc(Size+1);
   if (!Buf) return 0;
   Buf[Size] = 0;
-  MemoryBufferMem *SB = new MemoryBufferMem(Buf, Buf+Size, BufferName);
+  MemoryBufferMem *SB = new MemoryBufferMem(StringRef(Buf, Size), BufferName);
   // The memory for this buffer is owned by the MemoryBuffer.
   SB->MustDeleteBuffer = true;
   return SB;

Modified: llvm/branches/Apple/Morbo/tools/lto/LTOModule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/tools/lto/LTOModule.cpp?rev=101505&r1=101504&r2=101505&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/tools/lto/LTOModule.cpp (original)
+++ llvm/branches/Apple/Morbo/tools/lto/LTOModule.cpp Fri Apr 16 13:33:25 2010
@@ -101,13 +101,13 @@
 /// Also if next byte is on a different page, don't assume it is readable.
 MemoryBuffer* LTOModule::makeBuffer(const void* mem, size_t length)
 {
-    const char* startPtr = (char*)mem;
-    const char* endPtr = startPtr+length;
-    if ((((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0) 
-        || (*endPtr != 0)) 
-        return MemoryBuffer::getMemBufferCopy(startPtr, endPtr);
-    else
-        return MemoryBuffer::getMemBuffer(startPtr, endPtr);
+    const char *startPtr = (char*)mem;
+    const char *endPtr = startPtr+length;
+    if (((uintptr_t)endPtr & (sys::Process::GetPageSize()-1)) == 0 ||
+        *endPtr != 0) 
+        return MemoryBuffer::getMemBufferCopy(StringRef(startPtr, length));
+  
+    return MemoryBuffer::getMemBuffer(StringRef(startPtr, length));
 }
 
 

Modified: llvm/branches/Apple/Morbo/utils/FileCheck/FileCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Morbo/utils/FileCheck/FileCheck.cpp?rev=101505&r1=101504&r2=101505&view=diff
==============================================================================
--- llvm/branches/Apple/Morbo/utils/FileCheck/FileCheck.cpp (original)
+++ llvm/branches/Apple/Morbo/utils/FileCheck/FileCheck.cpp Fri Apr 16 13:33:25 2010
@@ -440,7 +440,7 @@
 /// CanonicalizeInputFile - Remove duplicate horizontal space from the specified
 /// memory buffer, free it, and return a new one.
 static MemoryBuffer *CanonicalizeInputFile(MemoryBuffer *MB) {
-  SmallVector<char, 16> NewFile;
+  SmallString<128> NewFile;
   NewFile.reserve(MB->getBufferSize());
   
   for (const char *Ptr = MB->getBufferStart(), *End = MB->getBufferEnd();
@@ -460,9 +460,7 @@
   
   // Free the old buffer and return a new one.
   MemoryBuffer *MB2 =
-    MemoryBuffer::getMemBufferCopy(NewFile.data(), 
-                                   NewFile.data() + NewFile.size(),
-                                   MB->getBufferIdentifier());
+    MemoryBuffer::getMemBufferCopy(NewFile.str(), MB->getBufferIdentifier());
   
   delete MB;
   return MB2;





More information about the llvm-branch-commits mailing list