diff options
Diffstat (limited to 'contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp')
-rw-r--r-- | contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp | 73 |
1 files changed, 27 insertions, 46 deletions
diff --git a/contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp b/contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp index 0530c26..d27d83b 100644 --- a/contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp +++ b/contrib/llvm/lib/MC/MCDisassembler/Disassembler.cpp @@ -21,7 +21,6 @@ #include "llvm/MC/MCSymbolizer.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" -#include "llvm/Support/MemoryObject.h" #include "llvm/Support/TargetRegistry.h" using namespace llvm; @@ -33,10 +32,11 @@ using namespace llvm; // functions can all be passed as NULL. If successful, this returns a // disassembler context. If not, it returns NULL. // -LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU, - void *DisInfo, int TagType, - LLVMOpInfoCallback GetOpInfo, - LLVMSymbolLookupCallback SymbolLookUp){ +LLVMDisasmContextRef +LLVMCreateDisasmCPUFeatures(const char *Triple, const char *CPU, + const char *Features, void *DisInfo, int TagType, + LLVMOpInfoCallback GetOpInfo, + LLVMSymbolLookupCallback SymbolLookUp) { // Get the target. std::string Error; const Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error); @@ -56,11 +56,8 @@ LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU, if (!MII) return nullptr; - // Package up features to be passed to target/subtarget - std::string FeaturesStr; - const MCSubtargetInfo *STI = TheTarget->createMCSubtargetInfo(Triple, CPU, - FeaturesStr); + Features); if (!STI) return nullptr; @@ -101,11 +98,19 @@ LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU, return DC; } +LLVMDisasmContextRef LLVMCreateDisasmCPU(const char *Triple, const char *CPU, + void *DisInfo, int TagType, + LLVMOpInfoCallback GetOpInfo, + LLVMSymbolLookupCallback SymbolLookUp){ + return LLVMCreateDisasmCPUFeatures(Triple, CPU, "", DisInfo, TagType, + GetOpInfo, SymbolLookUp); +} + LLVMDisasmContextRef LLVMCreateDisasm(const char *Triple, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp) { - return LLVMCreateDisasmCPU(Triple, "", DisInfo, TagType, GetOpInfo, - SymbolLookUp); + return LLVMCreateDisasmCPUFeatures(Triple, "", "", DisInfo, TagType, + GetOpInfo, SymbolLookUp); } // @@ -116,30 +121,6 @@ void LLVMDisasmDispose(LLVMDisasmContextRef DCR){ delete DC; } -namespace { -// -// The memory object created by LLVMDisasmInstruction(). -// -class DisasmMemoryObject : public MemoryObject { - uint8_t *Bytes; - uint64_t Size; - uint64_t BasePC; -public: - DisasmMemoryObject(uint8_t *bytes, uint64_t size, uint64_t basePC) : - Bytes(bytes), Size(size), BasePC(basePC) {} - - uint64_t getBase() const override { return BasePC; } - uint64_t getExtent() const override { return Size; } - - int readByte(uint64_t Addr, uint8_t *Byte) const override { - if (Addr - BasePC >= Size) - return -1; - *Byte = Bytes[Addr - BasePC]; - return 0; - } -}; -} // end anonymous namespace - /// \brief Emits the comments that are stored in \p DC comment stream. /// Each comment in the comment stream must end with a newline. static void emitComments(LLVMDisasmContext *DC, @@ -170,10 +151,10 @@ static void emitComments(LLVMDisasmContext *DC, DC->CommentStream.resync(); } -/// \brief Gets latency information for \p Inst form the itinerary +/// \brief Gets latency information for \p Inst from the itinerary /// scheduling model, based on \p DC information. /// \return The maximum expected latency over all the operands or -1 -/// if no information are available. +/// if no information is available. static int getItineraryLatency(LLVMDisasmContext *DC, const MCInst &Inst) { const int NoInformationAvailable = -1; @@ -198,23 +179,23 @@ static int getItineraryLatency(LLVMDisasmContext *DC, const MCInst &Inst) { /// \brief Gets latency information for \p Inst, based on \p DC information. /// \return The maximum expected latency over all the definitions or -1 -/// if no information are available. +/// if no information is available. static int getLatency(LLVMDisasmContext *DC, const MCInst &Inst) { // Try to compute scheduling information. const MCSubtargetInfo *STI = DC->getSubtargetInfo(); - const MCSchedModel *SCModel = STI->getSchedModel(); + const MCSchedModel SCModel = STI->getSchedModel(); const int NoInformationAvailable = -1; // Check if we have a scheduling model for instructions. - if (!SCModel || !SCModel->hasInstrSchedModel()) - // Try to fall back to the itinerary model if we do not have a - // scheduling model. + if (!SCModel.hasInstrSchedModel()) + // Try to fall back to the itinerary model if the scheduling model doesn't + // have a scheduling table. Note the default does not have a table. return getItineraryLatency(DC, Inst); // Get the scheduling class of the requested instruction. const MCInstrDesc& Desc = DC->getInstrInfo()->get(Inst.getOpcode()); unsigned SCClass = Desc.getSchedClass(); - const MCSchedClassDesc *SCDesc = SCModel->getSchedClassDesc(SCClass); + const MCSchedClassDesc *SCDesc = SCModel.getSchedClassDesc(SCClass); // Resolving the variant SchedClass requires an MI to pass to // SubTargetInfo::resolveSchedClass. if (!SCDesc || !SCDesc->isValid() || SCDesc->isVariant()) @@ -239,7 +220,7 @@ static int getLatency(LLVMDisasmContext *DC, const MCInst &Inst) { static void emitLatency(LLVMDisasmContext *DC, const MCInst &Inst) { int Latency = getLatency(DC, Inst); - // Report only interesting latency. + // Report only interesting latencies. if (Latency < 2) return; @@ -263,7 +244,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, size_t OutStringSize){ LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR; // Wrap the pointer to the Bytes, BytesSize and PC in a MemoryObject. - DisasmMemoryObject MemoryObject(Bytes, BytesSize, PC); + ArrayRef<uint8_t> Data(Bytes, BytesSize); uint64_t Size; MCInst Inst; @@ -272,7 +253,7 @@ size_t LLVMDisasmInstruction(LLVMDisasmContextRef DCR, uint8_t *Bytes, MCDisassembler::DecodeStatus S; SmallVector<char, 64> InsnStr; raw_svector_ostream Annotations(InsnStr); - S = DisAsm->getInstruction(Inst, Size, MemoryObject, PC, + S = DisAsm->getInstruction(Inst, Size, Data, PC, /*REMOVE*/ nulls(), Annotations); switch (S) { case MCDisassembler::Fail: |