Introduce LLVMWriteBitcodeToMemoryBuffer C API function.
authorPeter Collingbourne <peter@pcc.me.uk>
Tue, 14 Oct 2014 00:30:59 +0000 (00:30 +0000)
committerPeter Collingbourne <peter@pcc.me.uk>
Tue, 14 Oct 2014 00:30:59 +0000 (00:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@219643 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm-c/BitWriter.h
lib/Bitcode/Writer/BitWriter.cpp

index 0ec8e752dcc4d2d194d8947ad7e3a7b82dc677e4..f25ad3a445f5893d2095572882f9eee49c2568f2 100644 (file)
@@ -45,6 +45,9 @@ int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
     descriptor. Returns 0 on success. Closes the Handle. */
 int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int Handle);
 
     descriptor. Returns 0 on success. Closes the Handle. */
 int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int Handle);
 
+/** Writes a module to a new memory buffer and returns it. */
+LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M);
+
 /**
  * @}
  */
 /**
  * @}
  */
index 6c9f7b3276fdaa883c6413c26d697ade7075d1a9..7218ea05bb5bdd651c0816429789a73fe88bba6e 100644 (file)
@@ -39,3 +39,11 @@ int LLVMWriteBitcodeToFD(LLVMModuleRef M, int FD, int ShouldClose,
 int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
   return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
 }
 int LLVMWriteBitcodeToFileHandle(LLVMModuleRef M, int FileHandle) {
   return LLVMWriteBitcodeToFD(M, FileHandle, true, false);
 }
+
+LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M) {
+  std::string Data;
+  raw_string_ostream OS(Data);
+
+  WriteBitcodeToFile(unwrap(M), OS);
+  return wrap(MemoryBuffer::getMemBufferCopy(OS.str()).release());
+}