blob: ad9345b758bded5290a04dd4625d07098d9a4143 [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
16#ifndef EDOperand_
17#define EDOperand_
18
19#include "llvm-c/EnhancedDisassembly.h"
20
21/// EDOperand - Encapsulates a single operand, which can be evaluated by the
22/// client
23struct EDOperand {
24 /// The parent disassembler
25 const EDDisassembler &Disassembler;
26 /// The parent instruction
27 const EDInst &Inst;
28
29 /// The index of the operand in the EDInst
30 unsigned int OpIndex;
31 /// The index of the first component of the operand in the MCInst
32 unsigned int MCOpIndex;
33
34 /// Constructor - Initializes an EDOperand
35 ///
36 /// @arg disassembler - The disassembler responsible for the operand
37 /// @arg inst - The instruction containing this operand
38 /// @arg opIndex - The index of the operand in inst
39 /// @arg mcOpIndex - The index of the operand in the original MCInst
40 EDOperand(const EDDisassembler &disassembler,
41 const EDInst &inst,
42 unsigned int opIndex,
43 unsigned int &mcOpIndex);
44 ~EDOperand();
45
46 /// evaluate - Returns the numeric value of an operand to the extent possible,
47 /// returning 0 on success or -1 if there was some problem (such as a
48 /// register not being readable)
49 ///
50 /// @arg result - A reference whose target is filled in with the value of
51 /// the operand (the address if it is a memory operand)
52 /// @arg callback - A function to call to obtain register values
53 /// @arg arg - An opaque argument to pass to callback
54 int evaluate(uint64_t &result,
55 EDRegisterReaderCallback callback,
56 void *arg);
Sean Callanan76706582010-02-04 01:43:08 +000057
58 /// isRegister - Returns 1 if the operand is a register or 0 otherwise
59 int isRegister();
60 /// regVal - Returns the register value.
61 unsigned regVal();
62
63 /// isImmediate - Returns 1 if the operand is an immediate or 0 otherwise
64 int isImmediate();
65 /// immediateVal - Returns the immediate value.
66 uint64_t immediateVal();
67
68 /// isMemory - Returns 1 if the operand is a memory location or 0 otherwise
69 int isMemory();
Sean Callananee5dfd42010-02-01 08:49:35 +000070
71#ifdef __BLOCKS__
72 /// evaluate - Like evaluate for a callback, but uses a block instead
73 int evaluate(uint64_t &result,
74 EDRegisterBlock_t regBlock);
75#endif
76};
77
78#endif