mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-22 10:42:39 +01:00
Object: Make IRObjectFile own multiple modules and enumerate symbols from all modules.
This implements multi-module support in IRObjectFile. Differential Revision: https://reviews.llvm.org/D26951 llvm-svn: 289578
This commit is contained in:
parent
c4f16cfe6c
commit
87a2fe46d9
@ -28,9 +28,10 @@ namespace object {
|
||||
class ObjectFile;
|
||||
|
||||
class IRObjectFile : public SymbolicFile {
|
||||
std::unique_ptr<Module> M;
|
||||
std::vector<std::unique_ptr<Module>> Mods;
|
||||
ModuleSymbolTable SymTab;
|
||||
IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> M);
|
||||
IRObjectFile(MemoryBufferRef Object,
|
||||
std::vector<std::unique_ptr<Module>> Mods);
|
||||
|
||||
public:
|
||||
~IRObjectFile() override;
|
||||
|
@ -35,9 +35,11 @@
|
||||
using namespace llvm;
|
||||
using namespace object;
|
||||
|
||||
IRObjectFile::IRObjectFile(MemoryBufferRef Object, std::unique_ptr<Module> Mod)
|
||||
: SymbolicFile(Binary::ID_IR, Object), M(std::move(Mod)) {
|
||||
SymTab.addModule(M.get());
|
||||
IRObjectFile::IRObjectFile(MemoryBufferRef Object,
|
||||
std::vector<std::unique_ptr<Module>> Mods)
|
||||
: SymbolicFile(Binary::ID_IR, Object), Mods(std::move(Mods)) {
|
||||
for (auto &M : this->Mods)
|
||||
SymTab.addModule(M.get());
|
||||
}
|
||||
|
||||
IRObjectFile::~IRObjectFile() {}
|
||||
@ -73,7 +75,11 @@ basic_symbol_iterator IRObjectFile::symbol_end() const {
|
||||
return basic_symbol_iterator(BasicSymbolRef(Ret, this));
|
||||
}
|
||||
|
||||
StringRef IRObjectFile::getTargetTriple() const { return M->getTargetTriple(); }
|
||||
StringRef IRObjectFile::getTargetTriple() const {
|
||||
// Each module must have the same target triple, so we arbitrarily access the
|
||||
// first one.
|
||||
return Mods[0]->getTargetTriple();
|
||||
}
|
||||
|
||||
ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInObject(const ObjectFile &Obj) {
|
||||
for (const SectionRef &Sec : Obj.sections()) {
|
||||
@ -108,19 +114,26 @@ ErrorOr<MemoryBufferRef> IRObjectFile::findBitcodeInMemBuffer(MemoryBufferRef Ob
|
||||
}
|
||||
|
||||
Expected<std::unique_ptr<IRObjectFile>>
|
||||
llvm::object::IRObjectFile::create(MemoryBufferRef Object,
|
||||
LLVMContext &Context) {
|
||||
IRObjectFile::create(MemoryBufferRef Object, LLVMContext &Context) {
|
||||
ErrorOr<MemoryBufferRef> BCOrErr = findBitcodeInMemBuffer(Object);
|
||||
if (!BCOrErr)
|
||||
return errorCodeToError(BCOrErr.getError());
|
||||
|
||||
Expected<std::unique_ptr<Module>> MOrErr =
|
||||
getLazyBitcodeModule(*BCOrErr, Context,
|
||||
/*ShouldLazyLoadMetadata*/ true);
|
||||
if (!MOrErr)
|
||||
return MOrErr.takeError();
|
||||
Expected<std::vector<BitcodeModule>> BMsOrErr =
|
||||
getBitcodeModuleList(*BCOrErr);
|
||||
if (!BMsOrErr)
|
||||
return BMsOrErr.takeError();
|
||||
|
||||
std::vector<std::unique_ptr<Module>> Mods;
|
||||
for (auto BM : *BMsOrErr) {
|
||||
Expected<std::unique_ptr<Module>> MOrErr =
|
||||
BM.getLazyModule(Context, /*ShouldLazyLoadMetadata*/ true);
|
||||
if (!MOrErr)
|
||||
return MOrErr.takeError();
|
||||
|
||||
Mods.push_back(std::move(*MOrErr));
|
||||
}
|
||||
|
||||
std::unique_ptr<Module> &M = MOrErr.get();
|
||||
return std::unique_ptr<IRObjectFile>(
|
||||
new IRObjectFile(*BCOrErr, std::move(M)));
|
||||
new IRObjectFile(*BCOrErr, std::move(Mods)));
|
||||
}
|
||||
|
3
test/Object/Inputs/multi-module.ll
Normal file
3
test/Object/Inputs/multi-module.ll
Normal file
@ -0,0 +1,3 @@
|
||||
define void @f2() {
|
||||
ret void
|
||||
}
|
8
test/Object/multi-module.ll
Normal file
8
test/Object/multi-module.ll
Normal file
@ -0,0 +1,8 @@
|
||||
; RUN: llvm-cat -o - %s %S/Inputs/multi-module.ll | llvm-nm - | FileCheck %s
|
||||
|
||||
; CHECK: T f1
|
||||
; CHECK: T f2
|
||||
|
||||
define void @f1() {
|
||||
ret void
|
||||
}
|
Loading…
Reference in New Issue
Block a user