2011-03-29 02:25:07 +08:00
|
|
|
//===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the interface for the Disassembly library's disassembler
|
|
|
|
// context. The disassembler is responsible for producing strings for
|
|
|
|
// individual instructions according to a given architecture and disassembly
|
|
|
|
// syntax.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2011-04-24 23:46:56 +08:00
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
|
|
|
|
#define LLVM_LIB_MC_MCDISASSEMBLER_DISASSEMBLER_H
|
2011-04-24 23:46:56 +08:00
|
|
|
|
2011-03-29 02:25:07 +08:00
|
|
|
#include "llvm-c/Disassembler.h"
|
2011-09-16 02:37:20 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
2016-01-28 03:29:56 +08:00
|
|
|
#include "llvm/MC/MCAsmInfo.h"
|
|
|
|
#include "llvm/MC/MCContext.h"
|
|
|
|
#include "llvm/MC/MCDisassembler/MCDisassembler.h"
|
|
|
|
#include "llvm/MC/MCInstPrinter.h"
|
|
|
|
#include "llvm/MC/MCInstrInfo.h"
|
|
|
|
#include "llvm/MC/MCRegisterInfo.h"
|
|
|
|
#include "llvm/MC/MCSubtargetInfo.h"
|
2011-09-16 02:37:20 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2012-12-04 15:12:27 +08:00
|
|
|
#include <string>
|
2016-05-27 22:27:24 +08:00
|
|
|
#include <utility>
|
2011-03-29 02:25:07 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class Target;
|
|
|
|
|
|
|
|
//
|
|
|
|
// This is the disassembler context returned by LLVMCreateDisasm().
|
|
|
|
//
|
|
|
|
class LLVMDisasmContext {
|
|
|
|
private:
|
|
|
|
//
|
|
|
|
// The passed parameters when the disassembler context is created.
|
|
|
|
//
|
|
|
|
// The TripleName for this disassembler.
|
|
|
|
std::string TripleName;
|
|
|
|
// The pointer to the caller's block of symbolic information.
|
|
|
|
void *DisInfo;
|
|
|
|
// The Triple specific symbolic information type returned by GetOpInfo.
|
|
|
|
int TagType;
|
|
|
|
// The function to get the symbolic information for operands.
|
|
|
|
LLVMOpInfoCallback GetOpInfo;
|
|
|
|
// The function to look up a symbol name.
|
|
|
|
LLVMSymbolLookupCallback SymbolLookUp;
|
|
|
|
//
|
|
|
|
// The objects created and saved by LLVMCreateDisasm() then used by
|
|
|
|
// LLVMDisasmInstruction().
|
|
|
|
//
|
|
|
|
// The LLVM target corresponding to the disassembler.
|
2014-03-06 13:51:42 +08:00
|
|
|
// FIXME: using std::unique_ptr<const llvm::Target> causes a malloc error
|
2011-03-29 02:25:07 +08:00
|
|
|
// when this LLVMDisasmContext is deleted.
|
|
|
|
const Target *TheTarget;
|
|
|
|
// The assembly information for the target architecture.
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<const llvm::MCAsmInfo> MAI;
|
2011-07-19 04:57:22 +08:00
|
|
|
// The register information for the target architecture.
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<const llvm::MCRegisterInfo> MRI;
|
2012-04-07 02:21:09 +08:00
|
|
|
// The subtarget information for the target architecture.
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<const llvm::MCSubtargetInfo> MSI;
|
2012-04-07 02:21:09 +08:00
|
|
|
// The instruction information for the target architecture.
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<const llvm::MCInstrInfo> MII;
|
2011-03-29 02:25:07 +08:00
|
|
|
// The assembly context for creating symbols and MCExprs.
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<const llvm::MCContext> Ctx;
|
2011-03-29 02:25:07 +08:00
|
|
|
// The disassembler for the target architecture.
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<const llvm::MCDisassembler> DisAsm;
|
2011-03-29 02:25:07 +08:00
|
|
|
// The instruction printer for the target architecture.
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<llvm::MCInstPrinter> IP;
|
2013-10-03 06:07:57 +08:00
|
|
|
// The options used to set up the disassembler.
|
|
|
|
uint64_t Options;
|
2013-10-04 01:51:49 +08:00
|
|
|
// The CPU string.
|
|
|
|
std::string CPU;
|
2011-03-29 02:25:07 +08:00
|
|
|
|
|
|
|
public:
|
2011-09-16 02:37:20 +08:00
|
|
|
// Comment stream and backing vector.
|
|
|
|
SmallString<128> CommentsToEmit;
|
|
|
|
raw_svector_ostream CommentStream;
|
|
|
|
|
2011-03-29 02:25:07 +08:00
|
|
|
LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
|
2011-04-12 02:08:50 +08:00
|
|
|
LLVMOpInfoCallback getOpInfo,
|
2011-03-29 02:25:07 +08:00
|
|
|
LLVMSymbolLookupCallback symbolLookUp,
|
|
|
|
const Target *theTarget, const MCAsmInfo *mAI,
|
2016-05-27 22:27:24 +08:00
|
|
|
const MCRegisterInfo *mRI, const MCSubtargetInfo *mSI,
|
|
|
|
const MCInstrInfo *mII, llvm::MCContext *ctx,
|
|
|
|
const MCDisassembler *disAsm, MCInstPrinter *iP)
|
|
|
|
: TripleName(std::move(tripleName)), DisInfo(disInfo), TagType(tagType),
|
|
|
|
GetOpInfo(getOpInfo), SymbolLookUp(symbolLookUp), TheTarget(theTarget),
|
|
|
|
Options(0), CommentStream(CommentsToEmit) {
|
2011-03-29 02:25:07 +08:00
|
|
|
MAI.reset(mAI);
|
2011-07-19 04:57:22 +08:00
|
|
|
MRI.reset(mRI);
|
2012-04-07 02:21:09 +08:00
|
|
|
MSI.reset(mSI);
|
|
|
|
MII.reset(mII);
|
2011-03-29 02:25:07 +08:00
|
|
|
Ctx.reset(ctx);
|
|
|
|
DisAsm.reset(disAsm);
|
|
|
|
IP.reset(iP);
|
|
|
|
}
|
2012-06-07 04:45:10 +08:00
|
|
|
const std::string &getTripleName() const { return TripleName; }
|
|
|
|
void *getDisInfo() const { return DisInfo; }
|
|
|
|
int getTagType() const { return TagType; }
|
|
|
|
LLVMOpInfoCallback getGetOpInfo() const { return GetOpInfo; }
|
|
|
|
LLVMSymbolLookupCallback getSymbolLookupCallback() const {
|
|
|
|
return SymbolLookUp;
|
|
|
|
}
|
|
|
|
const Target *getTarget() const { return TheTarget; }
|
2011-03-29 02:25:07 +08:00
|
|
|
const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
|
2011-09-16 02:37:20 +08:00
|
|
|
const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
|
2012-12-19 07:47:28 +08:00
|
|
|
const MCInstrInfo *getInstrInfo() const { return MII.get(); }
|
|
|
|
const MCRegisterInfo *getRegisterInfo() const { return MRI.get(); }
|
|
|
|
const MCSubtargetInfo *getSubtargetInfo() const { return MSI.get(); }
|
2011-03-29 02:25:07 +08:00
|
|
|
MCInstPrinter *getIP() { return IP.get(); }
|
2012-12-19 07:47:28 +08:00
|
|
|
void setIP(MCInstPrinter *NewIP) { IP.reset(NewIP); }
|
2013-10-03 06:07:57 +08:00
|
|
|
uint64_t getOptions() const { return Options; }
|
|
|
|
void addOptions(uint64_t Options) { this->Options |= Options; }
|
2013-10-04 01:51:49 +08:00
|
|
|
StringRef getCPU() const { return CPU; }
|
|
|
|
void setCPU(const char *CPU) { this->CPU = CPU; }
|
2011-03-29 02:25:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llvm
|
2011-04-24 23:46:56 +08:00
|
|
|
|
|
|
|
#endif
|