OLD | NEW |
1 //===- BitcodeReader.cpp - Internal BitcodeReader implementation ----------===// | 1 //===- BitcodeReader.cpp - Internal BitcodeReader implementation ----------===// |
2 // | 2 // |
3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 | 9 |
10 #include "llvm/Bitcode/ReaderWriter.h" | 10 #include "llvm/Bitcode/ReaderWriter.h" |
(...skipping 3408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3419 | 3419 |
3420 StreamFile.reset(new BitstreamReader(BufPtr, BufEnd)); | 3420 StreamFile.reset(new BitstreamReader(BufPtr, BufEnd)); |
3421 Stream.init(&*StreamFile); | 3421 Stream.init(&*StreamFile); |
3422 | 3422 |
3423 return std::error_code(); | 3423 return std::error_code(); |
3424 } | 3424 } |
3425 | 3425 |
3426 std::error_code BitcodeReader::InitLazyStream() { | 3426 std::error_code BitcodeReader::InitLazyStream() { |
3427 // Check and strip off the bitcode wrapper; BitstreamReader expects never to | 3427 // Check and strip off the bitcode wrapper; BitstreamReader expects never to |
3428 // see it. | 3428 // see it. |
3429 StreamingMemoryObject *Bytes = new StreamingMemoryObject(LazyStreamer); | 3429 // @LOCALMOD Bytes -> LazyStreamer |
3430 StreamFile.reset(new BitstreamReader(Bytes)); | 3430 StreamFile.reset(new BitstreamReader(LazyStreamer)); |
3431 Stream.init(&*StreamFile); | 3431 Stream.init(&*StreamFile); |
3432 | 3432 |
3433 unsigned char buf[16]; | 3433 unsigned char buf[16]; |
3434 if (Bytes->readBytes(buf, 16, 0) != 16) | 3434 if (LazyStreamer->readBytes(buf, 16, 0) != 16) |
3435 return Error(BitcodeError::InvalidBitcodeSignature); | 3435 return Error(BitcodeError::InvalidBitcodeSignature); |
3436 | 3436 |
3437 if (!isBitcode(buf, buf + 16)) | 3437 if (!isBitcode(buf, buf + 16)) |
3438 return Error(BitcodeError::InvalidBitcodeSignature); | 3438 return Error(BitcodeError::InvalidBitcodeSignature); |
3439 | 3439 |
3440 if (isBitcodeWrapper(buf, buf + 4)) { | 3440 if (isBitcodeWrapper(buf, buf + 4)) { |
3441 const unsigned char *bitcodeStart = buf; | 3441 const unsigned char *bitcodeStart = buf; |
3442 const unsigned char *bitcodeEnd = buf + 16; | 3442 const unsigned char *bitcodeEnd = buf + 16; |
3443 SkipBitcodeWrapperHeader(bitcodeStart, bitcodeEnd, false); | 3443 SkipBitcodeWrapperHeader(bitcodeStart, bitcodeEnd, false); |
3444 Bytes->dropLeadingBytes(bitcodeStart - buf); | 3444 LazyStreamer->dropLeadingBytes(bitcodeStart - buf); |
3445 Bytes->setKnownObjectSize(bitcodeEnd - bitcodeStart); | 3445 LazyStreamer->setKnownObjectSize(bitcodeEnd - bitcodeStart); |
3446 } | 3446 } |
3447 return std::error_code(); | 3447 return std::error_code(); |
3448 } | 3448 } |
3449 | 3449 |
3450 namespace { | 3450 namespace { |
3451 class BitcodeErrorCategoryType : public std::error_category { | 3451 class BitcodeErrorCategoryType : public std::error_category { |
3452 const char *name() const LLVM_NOEXCEPT override { | 3452 const char *name() const LLVM_NOEXCEPT override { |
3453 return "llvm.bitcode"; | 3453 return "llvm.bitcode"; |
3454 } | 3454 } |
3455 std::string message(int IE) const override { | 3455 std::string message(int IE) const override { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3542 return M; | 3542 return M; |
3543 } | 3543 } |
3544 | 3544 |
3545 ErrorOr<Module *> | 3545 ErrorOr<Module *> |
3546 llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer, | 3546 llvm::getLazyBitcodeModule(std::unique_ptr<MemoryBuffer> &&Buffer, |
3547 LLVMContext &Context) { | 3547 LLVMContext &Context) { |
3548 return getLazyBitcodeModuleImpl(std::move(Buffer), Context, false); | 3548 return getLazyBitcodeModuleImpl(std::move(Buffer), Context, false); |
3549 } | 3549 } |
3550 | 3550 |
3551 Module *llvm::getStreamedBitcodeModule(const std::string &name, | 3551 Module *llvm::getStreamedBitcodeModule(const std::string &name, |
3552 DataStreamer *streamer, | 3552 // @LOCALMOD |
| 3553 StreamingMemoryObject *streamer, |
3553 LLVMContext &Context, | 3554 LLVMContext &Context, |
3554 std::string *ErrMsg) { | 3555 std::string *ErrMsg) { |
3555 Module *M = new Module(name, Context); | 3556 Module *M = new Module(name, Context); |
3556 BitcodeReader *R = new BitcodeReader(streamer, Context); | 3557 BitcodeReader *R = new BitcodeReader(streamer, Context); |
3557 M->setMaterializer(R); | 3558 M->setMaterializer(R); |
3558 if (std::error_code EC = R->ParseBitcodeInto(M)) { | 3559 if (std::error_code EC = R->ParseBitcodeInto(M)) { |
3559 if (ErrMsg) | 3560 if (ErrMsg) |
3560 *ErrMsg = EC.message(); | 3561 *ErrMsg = EC.message(); |
3561 delete M; // Also deletes R. | 3562 delete M; // Also deletes R. |
3562 return nullptr; | 3563 return nullptr; |
(...skipping 23 matching lines...) Expand all Loading... |
3586 | 3587 |
3587 std::string llvm::getBitcodeTargetTriple(MemoryBufferRef Buffer, | 3588 std::string llvm::getBitcodeTargetTriple(MemoryBufferRef Buffer, |
3588 LLVMContext &Context) { | 3589 LLVMContext &Context) { |
3589 std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false); | 3590 std::unique_ptr<MemoryBuffer> Buf = MemoryBuffer::getMemBuffer(Buffer, false); |
3590 auto R = llvm::make_unique<BitcodeReader>(Buf.release(), Context); | 3591 auto R = llvm::make_unique<BitcodeReader>(Buf.release(), Context); |
3591 ErrorOr<std::string> Triple = R->parseTriple(); | 3592 ErrorOr<std::string> Triple = R->parseTriple(); |
3592 if (Triple.getError()) | 3593 if (Triple.getError()) |
3593 return ""; | 3594 return ""; |
3594 return Triple.get(); | 3595 return Triple.get(); |
3595 } | 3596 } |
OLD | NEW |