Pass a MemoryBufferRef when we can avoid taking ownership.

The attached patch simplifies a few interfaces that don't need to take
ownership of a buffer.

For example, both parseAssembly and parseBitcodeFile will parse the
entire buffer before returning. There is no need to take ownership.

Using a MemoryBufferRef makes it obvious in the type signature that
there is no ownership transfer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@216488 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-08-26 21:49:01 +00:00
parent af07403c3e
commit 2292996e1a
16 changed files with 58 additions and 71 deletions

View File

@@ -15,11 +15,11 @@
#define LLVM_BITCODE_READERWRITER_H
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MemoryBuffer.h"
#include <string>
namespace llvm {
class BitstreamWriter;
class MemoryBuffer;
class DataStreamer;
class LLVMContext;
class Module;
@@ -42,14 +42,13 @@ namespace llvm {
std::string *ErrMsg = nullptr);
/// Read the header of the specified bitcode buffer and extract just the
/// triple information. If successful, this returns a string and *does not*
/// take ownership of 'buffer'. On error, this returns "".
std::string getBitcodeTargetTriple(MemoryBuffer *Buffer,
/// triple information. If successful, this returns a string. On error, this
/// returns "".
std::string getBitcodeTargetTriple(MemoryBufferRef Buffer,
LLVMContext &Context);
/// Read the specified bitcode file, returning the module.
/// This method *never* takes ownership of Buffer.
ErrorOr<Module *> parseBitcodeFile(MemoryBuffer *Buffer,
ErrorOr<Module *> parseBitcodeFile(MemoryBufferRef Buffer,
LLVMContext &Context);
/// WriteBitcodeToFile - Write the specified module to the specified