mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-12 13:38:21 +00:00
Update getLazyBitcodeModule to use ErrorOr for error handling.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199125 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -51,15 +51,18 @@ LLVMBool LLVMGetBitcodeModuleInContext(LLVMContextRef ContextRef,
|
||||
LLVMModuleRef *OutM,
|
||||
char **OutMessage) {
|
||||
std::string Message;
|
||||
ErrorOr<Module *> ModuleOrErr =
|
||||
getLazyBitcodeModule(unwrap(MemBuf), *unwrap(ContextRef));
|
||||
|
||||
*OutM = wrap(getLazyBitcodeModule(unwrap(MemBuf), *unwrap(ContextRef),
|
||||
&Message));
|
||||
if (!*OutM) {
|
||||
if (error_code EC = ModuleOrErr.getError()) {
|
||||
*OutM = wrap((Module *)NULL);
|
||||
if (OutMessage)
|
||||
*OutMessage = strdup(Message.c_str());
|
||||
*OutMessage = strdup(EC.message().c_str());
|
||||
return 1;
|
||||
}
|
||||
|
||||
*OutM = wrap(ModuleOrErr.get());
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
@ -3274,18 +3274,14 @@ const error_category &BitcodeReader::BitcodeErrorCategory() {
|
||||
|
||||
/// getLazyBitcodeModule - lazy function-at-a-time loading from a file.
|
||||
///
|
||||
Module *llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
|
||||
LLVMContext& Context,
|
||||
std::string *ErrMsg) {
|
||||
ErrorOr<Module *> llvm::getLazyBitcodeModule(MemoryBuffer *Buffer,
|
||||
LLVMContext &Context) {
|
||||
Module *M = new Module(Buffer->getBufferIdentifier(), Context);
|
||||
BitcodeReader *R = new BitcodeReader(Buffer, Context);
|
||||
M->setMaterializer(R);
|
||||
if (error_code EC = R->ParseBitcodeInto(M)) {
|
||||
if (ErrMsg)
|
||||
*ErrMsg = EC.message();
|
||||
|
||||
delete M; // Also deletes R.
|
||||
return 0;
|
||||
return EC;
|
||||
}
|
||||
// Have the BitcodeReader dtor delete 'Buffer'.
|
||||
R->setBufferOwned(true);
|
||||
@ -3317,8 +3313,13 @@ Module *llvm::getStreamedBitcodeModule(const std::string &name,
|
||||
/// If an error occurs, return null and fill in *ErrMsg if non-null.
|
||||
Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
|
||||
std::string *ErrMsg){
|
||||
Module *M = getLazyBitcodeModule(Buffer, Context, ErrMsg);
|
||||
if (!M) return 0;
|
||||
ErrorOr<Module *> ModuleOrErr = getLazyBitcodeModule(Buffer, Context);
|
||||
if (error_code EC = ModuleOrErr.getError()) {
|
||||
if (ErrMsg)
|
||||
*ErrMsg = EC.message();
|
||||
return 0;
|
||||
}
|
||||
Module *M = ModuleOrErr.get();
|
||||
|
||||
// Don't let the BitcodeReader dtor delete 'Buffer', regardless of whether
|
||||
// there was an error.
|
||||
|
Reference in New Issue
Block a user