llvm.org GIT mirror llvm / d15bca6
Modernize the getStreamedBitcodeModule interface a bit. NFC. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@224499 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 4 years ago
4 changed file(s) with 29 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
6060 init(Start, End);
6161 }
6262
63 BitstreamReader(MemoryObject *bytes) : IgnoreBlockInfoNames(true) {
64 BitcodeBytes.reset(bytes);
65 }
63 BitstreamReader(std::unique_ptr BitcodeBytes)
64 : BitcodeBytes(std::move(BitcodeBytes)), IgnoreBlockInfoNames(true) {}
6665
6766 BitstreamReader(BitstreamReader &&Other) {
6867 *this = std::move(Other);
3232 ErrorOr getLazyBitcodeModule(std::unique_ptr &&Buffer,
3333 LLVMContext &Context);
3434
35 /// getStreamedBitcodeModule - Read the header of the specified stream
36 /// and prepare for lazy deserialization and streaming of function bodies.
37 /// On error, this returns null, and fills in *ErrMsg with an error
38 /// description if ErrMsg is non-null.
39 Module *getStreamedBitcodeModule(const std::string &name,
40 DataStreamer *streamer,
41 LLVMContext &Context,
42 std::string *ErrMsg = nullptr);
35 /// Read the header of the specified stream and prepare for lazy
36 /// deserialization and streaming of function bodies.
37 ErrorOr>
38 getStreamedBitcodeModule(StringRef Name, DataStreamer *Streamer,
39 LLVMContext &Context);
4340
4441 /// Read the header of the specified bitcode buffer and extract just the
4542 /// triple information. If successful, this returns a string. On error, this
35283528 std::error_code BitcodeReader::InitLazyStream() {
35293529 // Check and strip off the bitcode wrapper; BitstreamReader expects never to
35303530 // see it.
3531 StreamingMemoryObject *Bytes = new StreamingMemoryObject(LazyStreamer);
3532 StreamFile.reset(new BitstreamReader(Bytes));
3531 auto OwnedBytes = make_unique(LazyStreamer);
3532 StreamingMemoryObject &Bytes = *OwnedBytes;
3533 StreamFile = make_unique(std::move(OwnedBytes));
35333534 Stream.init(&*StreamFile);
35343535
35353536 unsigned char buf[16];
3536 if (Bytes->readBytes(buf, 16, 0) != 16)
3537 if (Bytes.readBytes(buf, 16, 0) != 16)
35373538 return Error(BitcodeError::InvalidBitcodeSignature);
35383539
35393540 if (!isBitcode(buf, buf + 16))
35433544 const unsigned char *bitcodeStart = buf;
35443545 const unsigned char *bitcodeEnd = buf + 16;
35453546 SkipBitcodeWrapperHeader(bitcodeStart, bitcodeEnd, false);
3546 Bytes->dropLeadingBytes(bitcodeStart - buf);
3547 Bytes->setKnownObjectSize(bitcodeEnd - bitcodeStart);
3547 Bytes.dropLeadingBytes(bitcodeStart - buf);
3548 Bytes.setKnownObjectSize(bitcodeEnd - bitcodeStart);
35483549 }
35493550 return std::error_code();
35503551 }
36503651 return getLazyBitcodeModuleImpl(std::move(Buffer), Context, false);
36513652 }
36523653
3653 Module *llvm::getStreamedBitcodeModule(const std::string &name,
3654 DataStreamer *streamer,
3655 LLVMContext &Context,
3656 std::string *ErrMsg) {
3657 Module *M = new Module(name, Context);
3658 BitcodeReader *R = new BitcodeReader(streamer, Context);
3654 ErrorOr>
3655 llvm::getStreamedBitcodeModule(StringRef Name, DataStreamer *Streamer,
3656 LLVMContext &Context) {
3657 std::unique_ptr M = make_unique(Name, Context);
3658 BitcodeReader *R = new BitcodeReader(Streamer, Context);
36593659 M->setMaterializer(R);
3660 if (std::error_code EC = R->ParseBitcodeInto(M)) {
3661 if (ErrMsg)
3662 *ErrMsg = EC.message();
3663 delete M; // Also deletes R.
3664 return nullptr;
3665 }
3666 return M;
3660 if (std::error_code EC = R->ParseBitcodeInto(M.get()))
3661 return EC;
3662 return std::move(M);
36673663 }
36683664
36693665 ErrorOr llvm::parseBitcodeFile(MemoryBufferRef Buffer,
126126 std::unique_ptr M;
127127
128128 // Use the bitcode streaming interface
129 DataStreamer *streamer = getDataFileStreamer(InputFilename, &ErrorMessage);
130 if (streamer) {
129 DataStreamer *Streamer = getDataFileStreamer(InputFilename, &ErrorMessage);
130 if (Streamer) {
131131 std::string DisplayFilename;
132132 if (InputFilename == "-")
133133 DisplayFilename = "";
134134 else
135135 DisplayFilename = InputFilename;
136 M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context,
137 &ErrorMessage));
136 ErrorOr> MOrErr =
137 getStreamedBitcodeModule(DisplayFilename, Streamer, Context);
138 if (std::error_code EC = MOrErr.getError())
139 ErrorMessage = EC.message();
140 else
141 M = std::move(*MOrErr);
138142 if(M.get()) {
139143 if (std::error_code EC = M->materializeAllPermanently()) {
140144 ErrorMessage = EC.message();