blob: 50260ec965a6459cb99c39e7aa245b2331efeb42 [file] [log] [blame]
Sean Callananee5dfd42010-02-01 08:49:35 +00001//===-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 Lattner847da552010-07-20 18:25:19 +000016#ifndef LLVM_EDOPERAND_H
17#define LLVM_EDOPERAND_H
Sean Callananee5dfd42010-02-01 08:49:35 +000018
Michael J. Spencer1f6efa32010-11-29 18:16:10 +000019#include "llvm/Support/DataTypes.h"
Chris Lattner847da552010-07-20 18:25:19 +000020
21namespace llvm {
22
23struct EDDisassembler;
24struct EDInst;
25
26typedef int (*EDRegisterReaderCallback)(uint64_t *value, unsigned regID,
27 void* arg);
28
Sean Callananee5dfd42010-02-01 08:49:35 +000029
30/// EDOperand - Encapsulates a single operand, which can be evaluated by the
31/// client
32struct 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 Callanan76706582010-02-04 01:43:08 +000066
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 Callananee5dfd42010-02-01 08:49:35 +000079
80#ifdef __BLOCKS__
Chris Lattner847da552010-07-20 18:25:19 +000081 typedef int (^EDRegisterBlock_t)(uint64_t *value, unsigned regID);
82
Sean Callananee5dfd42010-02-01 08:49:35 +000083 /// 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 Lattner847da552010-07-20 18:25:19 +000089} // end namespace llvm
90
Sean Callananee5dfd42010-02-01 08:49:35 +000091#endif