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
|
|
|
|
|
|
|
#ifndef LLVM_MC_DISASSEMBLER_H
|
|
|
|
#define LLVM_MC_DISASSEMBLER_H
|
|
|
|
|
2011-03-29 02:25:07 +08:00
|
|
|
#include "llvm-c/Disassembler.h"
|
|
|
|
#include <string>
|
|
|
|
#include "llvm/ADT/OwningPtr.h"
|
2011-09-16 02:37:20 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2011-03-29 02:25:07 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
class MCContext;
|
|
|
|
class MCAsmInfo;
|
|
|
|
class MCDisassembler;
|
|
|
|
class MCInstPrinter;
|
2011-07-19 04:57:22 +08:00
|
|
|
class MCRegisterInfo;
|
2011-03-29 02:25:07 +08:00
|
|
|
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.
|
|
|
|
// FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
|
|
|
|
// when this LLVMDisasmContext is deleted.
|
|
|
|
const Target *TheTarget;
|
|
|
|
// The assembly information for the target architecture.
|
|
|
|
llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
|
2011-07-19 04:57:22 +08:00
|
|
|
// The register information for the target architecture.
|
|
|
|
llvm::OwningPtr<const llvm::MCRegisterInfo> MRI;
|
2011-03-29 02:25:07 +08:00
|
|
|
// The assembly context for creating symbols and MCExprs.
|
|
|
|
llvm::OwningPtr<const llvm::MCContext> Ctx;
|
|
|
|
// The disassembler for the target architecture.
|
|
|
|
llvm::OwningPtr<const llvm::MCDisassembler> DisAsm;
|
|
|
|
// The instruction printer for the target architecture.
|
|
|
|
llvm::OwningPtr<llvm::MCInstPrinter> IP;
|
|
|
|
|
|
|
|
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,
|
2011-07-19 04:57:22 +08:00
|
|
|
const MCRegisterInfo *mRI,
|
2011-03-29 02:25:07 +08:00
|
|
|
llvm::MCContext *ctx, const MCDisassembler *disAsm,
|
|
|
|
MCInstPrinter *iP) : TripleName(tripleName),
|
|
|
|
DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
|
2011-09-16 02:37:20 +08:00
|
|
|
SymbolLookUp(symbolLookUp), TheTarget(theTarget),
|
|
|
|
CommentStream(CommentsToEmit) {
|
2011-03-29 02:25:07 +08:00
|
|
|
MAI.reset(mAI);
|
2011-07-19 04:57:22 +08:00
|
|
|
MRI.reset(mRI);
|
2011-03-29 02:25:07 +08:00
|
|
|
Ctx.reset(ctx);
|
|
|
|
DisAsm.reset(disAsm);
|
|
|
|
IP.reset(iP);
|
|
|
|
}
|
|
|
|
const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
|
2011-09-16 02:37:20 +08:00
|
|
|
const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
|
2011-03-29 02:25:07 +08:00
|
|
|
MCInstPrinter *getIP() { return IP.get(); }
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace llvm
|
2011-04-24 23:46:56 +08:00
|
|
|
|
|
|
|
#endif
|