Introduce LLVMWriteBitcodeToMemoryBuffer C API function.

llvm-svn: 219643
This commit is contained in:
Peter Collingbourne 2014-10-14 00:30:59 +00:00
parent eb47d8a2c8
commit ba689eeb38
2 changed files with 11 additions and 0 deletions

View 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);
/** Writes a module to a new memory buffer and returns it. */
LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M);
/**
* @}
*/

View 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);
}
LLVMMemoryBufferRef LLVMWriteBitcodeToMemoryBuffer(LLVMModuleRef M) {
std::string Data;
raw_string_ostream OS(Data);
WriteBitcodeToFile(unwrap(M), OS);
return wrap(MemoryBuffer::getMemBufferCopy(OS.str()).release());
}