Use std::unique_ptr to manage memory. No functionality change.

llvm-svn: 212299
This commit is contained in:
Rafael Espindola 2014-07-03 22:43:03 +00:00
parent 33b8321c4c
commit 39ed527ccb
2 changed files with 17 additions and 16 deletions

View File

@ -63,7 +63,7 @@ private:
// Use mangler to add GlobalPrefix to names to match linker names.
Mangler _mangler;
LTOModule(Module *m, TargetMachine *t);
LTOModule(std::unique_ptr<Module> M, TargetMachine *TM);
public:
/// Returns 'true' if the file or memory contents is LLVM bitcode.
@ -205,8 +205,8 @@ private:
/// Create an LTOModule (private version). N.B. This method takes ownership of
/// the buffer.
static LTOModule *makeLTOModule(MemoryBuffer *buffer, TargetOptions options,
std::string &errMsg);
static LTOModule *makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
TargetOptions options, std::string &errMsg);
/// Create a MemoryBuffer from a memory range with an optional name.
static MemoryBuffer *makeBuffer(const void *mem, size_t length,

View File

@ -44,12 +44,13 @@
#include <system_error>
using namespace llvm;
LTOModule::LTOModule(llvm::Module *m, llvm::TargetMachine *t)
: _module(m), _target(t),
_context(_target->getMCAsmInfo(), _target->getRegisterInfo(), &ObjFileInfo),
_mangler(t->getDataLayout()) {
ObjFileInfo.InitMCObjectFileInfo(t->getTargetTriple(),
t->getRelocationModel(), t->getCodeModel(),
LTOModule::LTOModule(std::unique_ptr<Module> M, TargetMachine *TM)
: _module(std::move(M)), _target(TM),
_context(_target->getMCAsmInfo(), _target->getRegisterInfo(),
&ObjFileInfo),
_mangler(TM->getDataLayout()) {
ObjFileInfo.InitMCObjectFileInfo(TM->getTargetTriple(),
TM->getRelocationModel(), TM->getCodeModel(),
_context);
}
@ -102,7 +103,7 @@ LTOModule *LTOModule::makeLTOModule(const char *path, TargetOptions options,
errMsg = ec.message();
return nullptr;
}
return makeLTOModule(buffer.release(), options, errMsg);
return makeLTOModule(std::move(buffer), options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
@ -122,7 +123,7 @@ LTOModule *LTOModule::makeLTOModule(int fd, const char *path,
errMsg = ec.message();
return nullptr;
}
return makeLTOModule(buffer.release(), options, errMsg);
return makeLTOModule(std::move(buffer), options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
@ -131,20 +132,20 @@ LTOModule *LTOModule::makeLTOModule(const void *mem, size_t length,
std::unique_ptr<MemoryBuffer> buffer(makeBuffer(mem, length, path));
if (!buffer)
return nullptr;
return makeLTOModule(buffer.release(), options, errMsg);
return makeLTOModule(std::move(buffer), options, errMsg);
}
LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
LTOModule *LTOModule::makeLTOModule(std::unique_ptr<MemoryBuffer> Buffer,
TargetOptions options,
std::string &errMsg) {
// parse bitcode buffer
ErrorOr<Module *> ModuleOrErr =
getLazyBitcodeModule(buffer, getGlobalContext());
getLazyBitcodeModule(Buffer.get(), getGlobalContext());
if (std::error_code EC = ModuleOrErr.getError()) {
errMsg = EC.message();
delete buffer;
return nullptr;
}
Buffer.release();
std::unique_ptr<Module> m(ModuleOrErr.get());
std::string TripleStr = m->getTargetTriple();
@ -177,7 +178,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
options);
m->materializeAllPermanently();
LTOModule *Ret = new LTOModule(m.release(), target);
LTOModule *Ret = new LTOModule(std::move(m), target);
// We need a MCContext set up in order to get mangled names of private
// symbols. It is a bit odd that we need to report uses and definitions