| Sean Callanan | ee5dfd4 | 2010-02-01 08:49:35 +0000 | [diff] [blame] | 1 | //===-EDOperand.h - LLVM Enhanced Disassembler ------------------*- 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 | // | 
 | 10 | // This file defines the interface for the Enhanced Disassembly library's  | 
 | 11 | // operand class.  The operand is responsible for allowing evaluation given a | 
 | 12 | // particular register context. | 
 | 13 | // | 
 | 14 | //===----------------------------------------------------------------------===// | 
 | 15 |  | 
| Chris Lattner | 847da55 | 2010-07-20 18:25:19 +0000 | [diff] [blame] | 16 | #ifndef LLVM_EDOPERAND_H | 
 | 17 | #define LLVM_EDOPERAND_H | 
| Sean Callanan | ee5dfd4 | 2010-02-01 08:49:35 +0000 | [diff] [blame] | 18 |  | 
| Michael J. Spencer | 1f6efa3 | 2010-11-29 18:16:10 +0000 | [diff] [blame] | 19 | #include "llvm/Support/DataTypes.h" | 
| Chris Lattner | 847da55 | 2010-07-20 18:25:19 +0000 | [diff] [blame] | 20 |  | 
 | 21 | namespace llvm { | 
 | 22 |  | 
 | 23 | struct EDDisassembler; | 
 | 24 | struct EDInst; | 
 | 25 |    | 
 | 26 | typedef int (*EDRegisterReaderCallback)(uint64_t *value, unsigned regID,  | 
 | 27 |                                         void* arg); | 
 | 28 |  | 
| Sean Callanan | ee5dfd4 | 2010-02-01 08:49:35 +0000 | [diff] [blame] | 29 |  | 
 | 30 | /// EDOperand - Encapsulates a single operand, which can be evaluated by the | 
 | 31 | ///   client | 
 | 32 | struct EDOperand { | 
 | 33 |   /// The parent disassembler | 
 | 34 |   const EDDisassembler &Disassembler; | 
 | 35 |   /// The parent instruction | 
 | 36 |   const EDInst &Inst; | 
 | 37 |    | 
 | 38 |   /// The index of the operand in the EDInst | 
 | 39 |   unsigned int OpIndex; | 
 | 40 |   /// The index of the first component of the operand in the MCInst | 
 | 41 |   unsigned int MCOpIndex; | 
 | 42 |    | 
 | 43 |   /// Constructor - Initializes an EDOperand | 
 | 44 |   /// | 
 | 45 |   /// @arg disassembler - The disassembler responsible for the operand | 
 | 46 |   /// @arg inst         - The instruction containing this operand | 
 | 47 |   /// @arg opIndex      - The index of the operand in inst | 
 | 48 |   /// @arg mcOpIndex    - The index of the operand in the original MCInst | 
 | 49 |   EDOperand(const EDDisassembler &disassembler, | 
 | 50 |             const EDInst &inst, | 
 | 51 |             unsigned int opIndex, | 
 | 52 |             unsigned int &mcOpIndex); | 
 | 53 |   ~EDOperand(); | 
 | 54 |    | 
 | 55 |   /// evaluate - Returns the numeric value of an operand to the extent possible, | 
 | 56 |   ///   returning 0 on success or -1 if there was some problem (such as a  | 
 | 57 |   ///   register not being readable) | 
 | 58 |   /// | 
 | 59 |   /// @arg result   - A reference whose target is filled in with the value of | 
 | 60 |   ///                 the operand (the address if it is a memory operand) | 
 | 61 |   /// @arg callback - A function to call to obtain register values | 
 | 62 |   /// @arg arg      - An opaque argument to pass to callback | 
 | 63 |   int evaluate(uint64_t &result, | 
 | 64 |                EDRegisterReaderCallback callback, | 
 | 65 |                void *arg); | 
| Sean Callanan | 7670658 | 2010-02-04 01:43:08 +0000 | [diff] [blame] | 66 |  | 
 | 67 |   /// isRegister - Returns 1 if the operand is a register or 0 otherwise | 
 | 68 |   int isRegister(); | 
 | 69 |   /// regVal - Returns the register value. | 
 | 70 |   unsigned regVal(); | 
 | 71 |    | 
 | 72 |   /// isImmediate - Returns 1 if the operand is an immediate or 0 otherwise | 
 | 73 |   int isImmediate(); | 
 | 74 |   /// immediateVal - Returns the immediate value. | 
 | 75 |   uint64_t immediateVal(); | 
 | 76 |    | 
 | 77 |   /// isMemory - Returns 1 if the operand is a memory location or 0 otherwise | 
 | 78 |   int isMemory(); | 
| Sean Callanan | ee5dfd4 | 2010-02-01 08:49:35 +0000 | [diff] [blame] | 79 |    | 
 | 80 | #ifdef __BLOCKS__ | 
| Chris Lattner | 847da55 | 2010-07-20 18:25:19 +0000 | [diff] [blame] | 81 |   typedef int (^EDRegisterBlock_t)(uint64_t *value, unsigned regID); | 
 | 82 |  | 
| Sean Callanan | ee5dfd4 | 2010-02-01 08:49:35 +0000 | [diff] [blame] | 83 |   /// evaluate - Like evaluate for a callback, but uses a block instead | 
 | 84 |   int evaluate(uint64_t &result, | 
 | 85 |                EDRegisterBlock_t regBlock); | 
 | 86 | #endif | 
 | 87 | }; | 
 | 88 |  | 
| Chris Lattner | 847da55 | 2010-07-20 18:25:19 +0000 | [diff] [blame] | 89 | } // end namespace llvm | 
 | 90 |  | 
| Sean Callanan | ee5dfd4 | 2010-02-01 08:49:35 +0000 | [diff] [blame] | 91 | #endif |