Object: Factor out the code for creating the irsymtab for an arbitrary bitcode file.

This code now lives in lib/Object. The idea is that it can now be reused by
IRObjectFile among other things.

Differential Revision: https://reviews.llvm.org/D31921

llvm-svn: 304958
This commit is contained in:
Peter Collingbourne
2017-06-08 01:26:14 +00:00
parent 4f440e3af5
commit c00c2b246b
5 changed files with 96 additions and 45 deletions

View File

@@ -139,3 +139,26 @@ IRObjectFile::create(MemoryBufferRef Object, LLVMContext &Context) {
return std::unique_ptr<IRObjectFile>(
new IRObjectFile(*BCOrErr, std::move(Mods)));
}
Expected<IRSymtabFile> object::readIRSymtab(MemoryBufferRef MBRef) {
IRSymtabFile F;
ErrorOr<MemoryBufferRef> BCOrErr =
IRObjectFile::findBitcodeInMemBuffer(MBRef);
if (!BCOrErr)
return errorCodeToError(BCOrErr.getError());
Expected<std::vector<BitcodeModule>> BMsOrErr =
getBitcodeModuleList(*BCOrErr);
if (!BMsOrErr)
return BMsOrErr.takeError();
Expected<irsymtab::FileContents> FCOrErr = irsymtab::readBitcode(*BMsOrErr);
if (!FCOrErr)
return FCOrErr.takeError();
F.Mods = std::move(*BMsOrErr);
F.Symtab = std::move(FCOrErr->Symtab);
F.Strtab = std::move(FCOrErr->Strtab);
F.TheReader = std::move(FCOrErr->TheReader);
return std::move(F);
}