1 //===------------- Disassembler.h - LLVM Disassembler -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the interface for the Disassembly library's disassembler
11 // context. The disassembler is responsible for producing strings for
12 // individual instructions according to a given architecture and disassembly
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_MC_DISASSEMBLER_H
18 #define LLVM_MC_DISASSEMBLER_H
20 #include "llvm-c/Disassembler.h"
22 #include "llvm/ADT/OwningPtr.h"
23 #include "llvm/ADT/SmallString.h"
24 #include "llvm/Support/raw_ostream.h"
35 // This is the disassembler context returned by LLVMCreateDisasm().
37 class LLVMDisasmContext {
40 // The passed parameters when the disassembler context is created.
42 // The TripleName for this disassembler.
43 std::string TripleName;
44 // The pointer to the caller's block of symbolic information.
46 // The Triple specific symbolic information type returned by GetOpInfo.
48 // The function to get the symbolic information for operands.
49 LLVMOpInfoCallback GetOpInfo;
50 // The function to look up a symbol name.
51 LLVMSymbolLookupCallback SymbolLookUp;
53 // The objects created and saved by LLVMCreateDisasm() then used by
54 // LLVMDisasmInstruction().
56 // The LLVM target corresponding to the disassembler.
57 // FIXME: using llvm::OwningPtr<const llvm::Target> causes a malloc error
58 // when this LLVMDisasmContext is deleted.
59 const Target *TheTarget;
60 // The assembly information for the target architecture.
61 llvm::OwningPtr<const llvm::MCAsmInfo> MAI;
62 // The register information for the target architecture.
63 llvm::OwningPtr<const llvm::MCRegisterInfo> MRI;
64 // The assembly context for creating symbols and MCExprs.
65 llvm::OwningPtr<const llvm::MCContext> Ctx;
66 // The disassembler for the target architecture.
67 llvm::OwningPtr<const llvm::MCDisassembler> DisAsm;
68 // The instruction printer for the target architecture.
69 llvm::OwningPtr<llvm::MCInstPrinter> IP;
72 // Comment stream and backing vector.
73 SmallString<128> CommentsToEmit;
74 raw_svector_ostream CommentStream;
76 LLVMDisasmContext(std::string tripleName, void *disInfo, int tagType,
77 LLVMOpInfoCallback getOpInfo,
78 LLVMSymbolLookupCallback symbolLookUp,
79 const Target *theTarget, const MCAsmInfo *mAI,
80 const MCRegisterInfo *mRI,
81 llvm::MCContext *ctx, const MCDisassembler *disAsm,
82 MCInstPrinter *iP) : TripleName(tripleName),
83 DisInfo(disInfo), TagType(tagType), GetOpInfo(getOpInfo),
84 SymbolLookUp(symbolLookUp), TheTarget(theTarget),
85 CommentStream(CommentsToEmit) {
92 const MCDisassembler *getDisAsm() const { return DisAsm.get(); }
93 const MCAsmInfo *getAsmInfo() const { return MAI.get(); }
94 MCInstPrinter *getIP() { return IP.get(); }