36 using namespace object;
42 const std::string &
InlineAsm = M->getModuleInlineAsm();
43 if (InlineAsm.empty())
46 Triple TT(M->getTargetTriple());
60 std::unique_ptr<MCSubtargetInfo> STI(
70 MCContext MCCtx(MAI.get(), MRI.get(), &MOFI);
72 std::unique_ptr<RecordStreamer> Streamer(
new RecordStreamer(MCCtx));
78 std::unique_ptr<MCAsmParser> Parser(
82 std::unique_ptr<MCTargetAsmParser> TAP(
87 Parser->setTargetParser(*TAP);
88 if (Parser->Run(
false))
91 for (
auto &KV : *Streamer) {
109 AsmSymbols.push_back(
110 std::make_pair<std::string, uint32_t>(Key, std::move(Res)));
118 if ((Symb.
p & 3) == 3)
121 return reinterpret_cast<GlobalValue*
>(Symb.
p & ~uintptr_t(3));
128 return reinterpret_cast<uintptr_t
>(GV) | 2;
135 return reinterpret_cast<uintptr_t
>(GV) | 1;
142 return reinterpret_cast<uintptr_t
>(GV) | 0;
146 assert((Symb.
p & uintptr_t(3)) == 3);
147 uintptr_t Index = Symb.
p & ~uintptr_t(3);
156 switch (Symb.
p & 3) {
177 assert(Index < AsmSymbols.size());
179 Res = (Index << 2) | 3;
194 assert(Index <= AsmSymbols.size());
195 OS << AsmSymbols[Index].first;
196 return std::error_code();
203 Mang->getNameWithPrefix(OS, GV,
false);
207 return std::error_code();
215 assert(Index <= AsmSymbols.size());
216 return AsmSymbols[Index].second;
233 else if (
auto *Var = dyn_cast<GlobalVariable>(GV)) {
234 if (Var->getSection() ==
StringRef(
"llvm.metadata"))
254 uint64_t NumAsm = AsmSymbols.size();
263 if (std::error_code EC = Sec.getName(SecName))
265 if (SecName ==
".llvmbc") {
267 if (std::error_code EC = Sec.getContents(SecContents))
302 std::unique_ptr<MemoryBuffer> Buff(
308 if (std::error_code EC = MOrErr.
getError())
311 std::unique_ptr<Module> &M = MOrErr.
get();
312 return llvm::make_unique<IRObjectFile>(Object, std::move(M));
basic_symbol_iterator symbol_begin_impl() const override
basic_symbol_iterator symbol_end_impl() const override
std::error_code getError() const
Represents either an error or a value T.
IRObjectFile(MemoryBufferRef Object, std::unique_ptr< Module > M)
A Module instance is used to store all the information related to an LLVM module. ...
static std::unique_ptr< MemoryBuffer > getMemBuffer(StringRef InputData, StringRef BufferName="", bool RequiresNullTerminator=true)
Open the specified memory range as a MemoryBuffer.
MCRegisterInfo * createMCRegInfo(StringRef TT) const
createMCRegInfo - Create a MCRegisterInfo implementation.
static GlobalValue * getGV(DataRefImpl &Symb)
This class is the base class for all object file types.
ELF Relocatable object file.
static const Target * lookupTarget(const std::string &Triple, std::string &Error)
lookupTarget - Lookup a target based on a target triple.
StringRef getName() const
Return a constant reference to the value's name.
MCInstrInfo * createMCInstrInfo() const
createMCInstrInfo - Create a MCInstrInfo implementation.
MCSubtargetInfo * createMCSubtargetInfo(StringRef TheTriple, StringRef CPU, StringRef Features) const
createMCSubtargetInfo - Create a MCSubtargetInfo implementation.
GlobalValue * getSymbolGV(DataRefImpl Symb)
bool hasCommonLinkage() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
static ErrorOr< std::unique_ptr< IRObjectFile > > create(MemoryBufferRef Object, LLVMContext &Context)
std::unique_ptr< Module > takeModule()
bool hasPrivateLinkage() const
global_iterator global_begin()
Context object for machine code objects.
static unsigned getAsmSymIndex(DataRefImpl Symb)
unsigned AddNewSourceBuffer(std::unique_ptr< MemoryBuffer > F, SMLoc IncludeLoc)
Add a new source buffer to this source manager.
MCTargetAsmParser * createMCAsmParser(MCSubtargetInfo &STI, MCAsmParser &Parser, const MCInstrInfo &MII, const MCTargetOptions &Options) const
createMCAsmParser - Create a target specific assembly parser.
static ErrorOr< MemoryBufferRef > findBitcodeInMemBuffer(MemoryBufferRef Object)
Finds and returns bitcode in the given memory buffer (which may be either a bitcode file or a native ...
std::error_code printSymbolName(raw_ostream &OS, DataRefImpl Symb) const override
static uintptr_t skipEmpty(Module::const_alias_iterator I, const Module &M)
MCAsmInfo * createMCAsmInfo(const MCRegisterInfo &MRI, StringRef TheTriple) const
createMCAsmInfo - Create a MCAsmInfo implementation for the specified target triple.
alias_iterator alias_end()
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
MCAsmParser * createMCAsmParser(SourceMgr &, MCContext &, MCStreamer &, const MCAsmInfo &)
Create an MCAsmParser instance.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling...
section_iterator_range sections() const
bool hasWeakLinkage() const
StringRef getFileName() const
Triple - Helper class for working with autoconf configuration names.
file_magic identify_magic(StringRef magic)
Identify the type of a binary file based on how magical it is.
global_iterator global_end()
content_iterator< BasicSymbolRef > basic_symbol_iterator
bool hasDLLImportStorageClass() const
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
StringRef getBuffer() const
Module.h This file contains the declarations for the Module class.
MCTargetStreamer * createNullTargetStreamer(MCStreamer &S) const
alias_iterator alias_begin()
void InitMCObjectFileInfo(const Triple &TT, Reloc::Model RM, CodeModel::Model CM, MCContext &ctx)
Target - Wrapper for Target specific information.
bool hasLinkOnceLinkage() const
void moveSymbolNext(DataRefImpl &Symb) const override
file_magic - An "enum class" enumeration of file types based on magic (the first N bytes of the file)...
This is a value type class that represents a single symbol in the list of symbols in the object file...
bool hasLocalLinkage() const
static ErrorOr< MemoryBufferRef > findBitcodeInObject(const ObjectFile &Obj)
Finds and returns bitcode embedded in the given object file, or an error code if not found...
LLVM Value Representation.
ErrorOr< std::unique_ptr< Module > > getLazyBitcodeModule(std::unique_ptr< MemoryBuffer > &&Buffer, LLVMContext &Context, DiagnosticHandlerFunction DiagnosticHandler=nullptr, bool ShouldLazyLoadMetadata=false)
Read the header of the specified bitcode buffer and prepare for lazy deserialization of function bodi...
This class implements an extremely fast bulk output stream that can only output to a stream...
static ErrorOr< OwningBinary< ObjectFile > > createObjectFile(StringRef ObjectPath)
Create ObjectFile from path.
StringRef - Represent a constant reference to a string, i.e.
Represents a location in source code.
bool isDeclarationForLinker() const
This is a value type class that represents a single section in the list of sections in the object fil...
uint32_t getSymbolFlags(DataRefImpl Symb) const override