diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2017-06-08 22:00:24 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2017-06-08 22:00:24 +0000 |
commit | 8dde4cba4ce76a9efc663e997735e96325be7902 (patch) | |
tree | 92b358855a607ca28e5a8a0091900488875107c6 /llvm/lib/Object | |
parent | 108ca94fa8dd35e969720c7605531a75f84558ce (diff) | |
download | bcm5719-llvm-8dde4cba4ce76a9efc663e997735e96325be7902.tar.gz bcm5719-llvm-8dde4cba4ce76a9efc663e997735e96325be7902.zip |
Bitcode: Introduce a BitcodeFileContents data type. NFCI.
This data type includes the contents of a bitcode file.
Right now a bitcode file can only contain modules, but
a later change will add a symbol table.
Differential Revision: https://reviews.llvm.org/D33969
llvm-svn: 305019
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r-- | llvm/lib/Object/IRObjectFile.cpp | 11 | ||||
-rw-r--r-- | llvm/lib/Object/IRSymtab.cpp | 17 |
2 files changed, 18 insertions, 10 deletions
diff --git a/llvm/lib/Object/IRObjectFile.cpp b/llvm/lib/Object/IRObjectFile.cpp index 9996661fbde..e7807b03833 100644 --- a/llvm/lib/Object/IRObjectFile.cpp +++ b/llvm/lib/Object/IRObjectFile.cpp @@ -147,16 +147,15 @@ Expected<IRSymtabFile> object::readIRSymtab(MemoryBufferRef MBRef) { if (!BCOrErr) return errorCodeToError(BCOrErr.getError()); - Expected<std::vector<BitcodeModule>> BMsOrErr = - getBitcodeModuleList(*BCOrErr); - if (!BMsOrErr) - return BMsOrErr.takeError(); + Expected<BitcodeFileContents> BFCOrErr = getBitcodeFileContents(*BCOrErr); + if (!BFCOrErr) + return BFCOrErr.takeError(); - Expected<irsymtab::FileContents> FCOrErr = irsymtab::readBitcode(*BMsOrErr); + Expected<irsymtab::FileContents> FCOrErr = irsymtab::readBitcode(*BFCOrErr); if (!FCOrErr) return FCOrErr.takeError(); - F.Mods = std::move(*BMsOrErr); + F.Mods = std::move(BFCOrErr->Mods); F.Symtab = std::move(FCOrErr->Symtab); F.Strtab = std::move(FCOrErr->Strtab); F.TheReader = std::move(FCOrErr->TheReader); diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp index fa343618caf..94f13490939 100644 --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -262,11 +262,10 @@ Error irsymtab::build(ArrayRef<Module *> Mods, SmallVector<char, 0> &Symtab, return Builder(Symtab, Strtab).build(Mods); } -Expected<FileContents> irsymtab::readBitcode(ArrayRef<BitcodeModule> BMs) { +// Upgrade a vector of bitcode modules created by an old version of LLVM by +// creating an irsymtab for them in the current format. +static Expected<FileContents> upgrade(ArrayRef<BitcodeModule> BMs) { FileContents FC; - if (BMs.empty()) - return make_error<StringError>("Bitcode file does not contain any modules", - inconvertibleErrorCode()); LLVMContext Ctx; std::vector<Module *> Mods; @@ -293,3 +292,13 @@ Expected<FileContents> irsymtab::readBitcode(ArrayRef<BitcodeModule> BMs) { {FC.Strtab.data(), FC.Strtab.size()}}; return std::move(FC); } + +Expected<FileContents> irsymtab::readBitcode(const BitcodeFileContents &BFC) { + if (BFC.Mods.empty()) + return make_error<StringError>("Bitcode file does not contain any modules", + inconvertibleErrorCode()); + + // Right now we have no on-disk representation of symbol tables, so we always + // upgrade. + return upgrade(BFC.Mods); +} |