MCDisassembler.h revision bd3327654b5708f1ba92aff3ab25b1bbf5034797
1//===-- llvm/MC/MCDisassembler.h - Disassembler interface -------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9#ifndef MCDISASSEMBLER_H
10#define MCDISASSEMBLER_H
11
12#include "llvm/Support/DataTypes.h"
13#include "llvm-c/Disassembler.h"
14
15namespace llvm {
16
17class MCInst;
18class MemoryObject;
19class raw_ostream;
20class MCContext;
21
22struct EDInstInfo;
23
24/// MCDisassembler - Superclass for all disassemblers.  Consumes a memory region
25///   and provides an array of assembly instructions.
26class MCDisassembler {
27public:
28  /// Constructor     - Performs initial setup for the disassembler.
29  MCDisassembler() : GetOpInfo(0), DisInfo(0), Ctx(0) {}
30
31  virtual ~MCDisassembler();
32
33  /// getInstruction  - Returns the disassembly of a single instruction.
34  ///
35  /// @param instr    - An MCInst to populate with the contents of the
36  ///                   instruction.
37  /// @param size     - A value to populate with the size of the instruction, or
38  ///                   the number of bytes consumed while attempting to decode
39  ///                   an invalid instruction.
40  /// @param region   - The memory object to use as a source for machine code.
41  /// @param address  - The address, in the memory space of region, of the first
42  ///                   byte of the instruction.
43  /// @param vStream  - The stream to print warnings and diagnostic messages on.
44  /// @return         - True if the instruction is valid; false otherwise.
45  virtual bool          getInstruction(MCInst& instr,
46                                       uint64_t& size,
47                                       const MemoryObject &region,
48                                       uint64_t address,
49                                       raw_ostream &vStream) const = 0;
50
51  /// getEDInfo - Returns the enhanced instruction information corresponding to
52  ///   the disassembler.
53  ///
54  /// @return         - An array of instruction information, with one entry for
55  ///                   each MCInst opcode this disassembler returns.
56  ///                   NULL if there is no info for this target.
57  virtual EDInstInfo   *getEDInfo() const { return (EDInstInfo*)0; }
58
59private:
60  //
61  // Hooks for symbolic disassembly via the public 'C' interface.
62  //
63  // The function to get the symbolic information for operands.
64  LLVMOpInfoCallback GetOpInfo;
65  // The pointer to the block of symbolic information for above call back.
66  void *DisInfo;
67  // The assembly context for creating symbols and MCExprs in place of
68  // immediate operands when there is symbolic information.
69  MCContext *Ctx;
70
71public:
72  void setupForSymbolicDisassembly(LLVMOpInfoCallback getOpInfo,
73                                   void *disInfo,
74                                   MCContext *ctx) {
75    GetOpInfo = getOpInfo;
76    DisInfo = disInfo;
77    Ctx = ctx;
78  }
79  LLVMOpInfoCallback getLLVMOpInfoCallback() const { return GetOpInfo; }
80  void *getDisInfoBlock() const { return DisInfo; }
81  MCContext *getMCContext() const { return Ctx; }
82};
83
84} // namespace llvm
85
86#endif
87