• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef LLVM_EDOPERAND_H
17 #define LLVM_EDOPERAND_H
18 
19 #include "llvm/Support/DataTypes.h"
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 
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);
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();
79 
80 #ifdef __BLOCKS__
81   typedef int (^EDRegisterBlock_t)(uint64_t *value, unsigned regID);
82 
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 
89 } // end namespace llvm
90 
91 #endif
92