[PATCH][llvm-c] Create Memory Buffer with memory ranges

Moritz Maxeiner moritzmaxeiner at googlemail.com
Wed Feb 13 03:59:24 PST 2013


On 2/13/2013 5:46 AM, Chris Lattner wrote:
> On Feb 10, 2013, at 9:13 AM, Moritz Maxeiner 
> <moritzmaxeiner at googlemail.com> wrote:
>
>> Add two new functions to the C API:
>>
>> LLVMCreateMemoryBufferWithMemoryRange - exposes 
>> MemoryBuffer::getMemBuffer
>> LLVMCreateMemoryBufferWithMemoryRangeCopy - exposes 
>> MemoryBuffer::getMemBufferCopy
> These new APIs should take a "const char*" + length.  The memory 
> buffer may have embedded nul's in it.

Of course, my bad. I assume the BufferName may not contain nuls, so I 
added the lengths only for the
InputData, if that is not the case - i.e. the BufferName may contain 
nuls - I'll change that as well.
For now, here the patch with length added for the InputData:

Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp    (revision 175052)
+++ lib/IR/Core.cpp    (working copy)
@@ -2369,6 +2369,29 @@
    return 1;
  }

+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(
+    const char *InputData,
+    size_t InputDataLength,
+    const char *BufferName,
+    bool RequiresNullTerminator) {
+
+  return wrap(MemoryBuffer::getMemBuffer(
+      StringRef(InputData, InputDataLength),
+      StringRef(BufferName),
+      RequiresNullTerminator));
+}
+
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(
+    const char *InputData,
+    size_t InputDataLength,
+    const char *BufferName) {
+
+  return wrap(MemoryBuffer::getMemBufferCopy(
+      StringRef(InputData, InputDataLength),
+      StringRef(BufferName)));
+}
+
+
  void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
    delete unwrap(MemBuf);
  }
Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h    (revision 175052)
+++ include/llvm-c/Core.h    (working copy)
@@ -2548,6 +2548,13 @@
                                                    char **OutMessage);
  LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
                                           char **OutMessage);
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char 
*InputData,
+                                                          size_t 
InputDataLength,
+                                                          const char 
*BufferName,
+                                                          bool 
RequiresNullTerminator);
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const 
char *InputData,
+ size_t InputDataLength,
+ const char *BufferName);
  void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);

  /**

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130213/9b01c9f1/attachment.html>
-------------- next part --------------
Index: lib/IR/Core.cpp
===================================================================
--- lib/IR/Core.cpp	(revision 175052)
+++ lib/IR/Core.cpp	(working copy)
@@ -2369,6 +2369,29 @@
   return 1;
 }
 
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(
+    const char *InputData,
+    size_t InputDataLength,
+    const char *BufferName,
+    bool RequiresNullTerminator) {
+
+  return wrap(MemoryBuffer::getMemBuffer(
+      StringRef(InputData, InputDataLength),
+      StringRef(BufferName),
+      RequiresNullTerminator));
+}
+
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(
+    const char *InputData,
+    size_t InputDataLength,
+    const char *BufferName) {
+
+  return wrap(MemoryBuffer::getMemBufferCopy(
+      StringRef(InputData, InputDataLength),
+      StringRef(BufferName)));
+}
+
+
 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
   delete unwrap(MemBuf);
 }
Index: include/llvm-c/Core.h
===================================================================
--- include/llvm-c/Core.h	(revision 175052)
+++ include/llvm-c/Core.h	(working copy)
@@ -2548,6 +2548,13 @@
                                                   char **OutMessage);
 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
                                          char **OutMessage);
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(const char *InputData,
+                                                          size_t InputDataLength,
+                                                          const char *BufferName,
+                                                          bool RequiresNullTerminator);
+LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(const char *InputData,
+                                                              size_t InputDataLength,
+                                                              const char *BufferName);
 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf);
 
 /**


More information about the llvm-commits mailing list