]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/include/llvm/MC/MCDisassembler.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / include / llvm / MC / MCDisassembler.h
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
15 namespace llvm {
16   
17 class MCInst;
18 class MemoryObject;
19 class raw_ostream;
20 class MCContext;
21   
22 struct EDInstInfo;
23
24 /// MCDisassembler - Superclass for all disassemblers.  Consumes a memory region
25 ///   and provides an array of assembly instructions.
26 class MCDisassembler {
27 public:
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
59 private:
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
71 public:
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