Don't define llvm::X86Disassembler::InstructionSpecifier in different ways in
[oota-llvm.git] / lib / Target / X86 / Disassembler / X86DisassemblerDecoder.h
1 //===-- X86DisassemblerDecoderInternal.h - Disassembler decoder -*- 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 is part of the X86 Disassembler.
11 // It contains the public interface of the instruction decoder.
12 // Documentation for the disassembler can be found in X86Disassembler.h.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #ifndef X86DISASSEMBLERDECODER_H
17 #define X86DISASSEMBLERDECODER_H
18
19 #define INSTRUCTION_IDS     \
20   uint16_t instructionIDs;
21
22 #include "X86DisassemblerDecoderCommon.h"
23
24 #undef INSTRUCTION_SPECIFIER_FIELDS
25 #undef INSTRUCTION_IDS
26
27 namespace llvm {
28 namespace X86Disassembler {
29
30 /*
31  * Accessor functions for various fields of an Intel instruction
32  */
33 #define modFromModRM(modRM)  (((modRM) & 0xc0) >> 6)
34 #define regFromModRM(modRM)  (((modRM) & 0x38) >> 3)
35 #define rmFromModRM(modRM)   ((modRM) & 0x7)
36 #define scaleFromSIB(sib)    (((sib) & 0xc0) >> 6)
37 #define indexFromSIB(sib)    (((sib) & 0x38) >> 3)
38 #define baseFromSIB(sib)     ((sib) & 0x7)
39 #define wFromREX(rex)        (((rex) & 0x8) >> 3)
40 #define rFromREX(rex)        (((rex) & 0x4) >> 2)
41 #define xFromREX(rex)        (((rex) & 0x2) >> 1)
42 #define bFromREX(rex)        ((rex) & 0x1)
43
44 #define rFromEVEX2of4(evex)     (((~(evex)) & 0x80) >> 7)
45 #define xFromEVEX2of4(evex)     (((~(evex)) & 0x40) >> 6)
46 #define bFromEVEX2of4(evex)     (((~(evex)) & 0x20) >> 5)
47 #define r2FromEVEX2of4(evex)    (((~(evex)) & 0x10) >> 4)
48 #define mmFromEVEX2of4(evex)    ((evex) & 0x3)
49 #define wFromEVEX3of4(evex)     (((evex) & 0x80) >> 7)
50 #define vvvvFromEVEX3of4(evex)  (((~(evex)) & 0x78) >> 3)
51 #define ppFromEVEX3of4(evex)    ((evex) & 0x3)
52 #define zFromEVEX4of4(evex)     (((evex) & 0x80) >> 7)
53 #define l2FromEVEX4of4(evex)    (((evex) & 0x40) >> 6)
54 #define lFromEVEX4of4(evex)     (((evex) & 0x20) >> 5)
55 #define bFromEVEX4of4(evex)     (((evex) & 0x10) >> 4)
56 #define v2FromEVEX4of4(evex)    (((~evex) & 0x8) >> 3)
57 #define aaaFromEVEX4of4(evex)   ((evex) & 0x7)
58
59 #define rFromVEX2of3(vex)       (((~(vex)) & 0x80) >> 7)
60 #define xFromVEX2of3(vex)       (((~(vex)) & 0x40) >> 6)
61 #define bFromVEX2of3(vex)       (((~(vex)) & 0x20) >> 5)
62 #define mmmmmFromVEX2of3(vex)   ((vex) & 0x1f)
63 #define wFromVEX3of3(vex)       (((vex) & 0x80) >> 7)
64 #define vvvvFromVEX3of3(vex)    (((~(vex)) & 0x78) >> 3)
65 #define lFromVEX3of3(vex)       (((vex) & 0x4) >> 2)
66 #define ppFromVEX3of3(vex)      ((vex) & 0x3)
67
68 #define rFromVEX2of2(vex)       (((~(vex)) & 0x80) >> 7)
69 #define vvvvFromVEX2of2(vex)    (((~(vex)) & 0x78) >> 3)
70 #define lFromVEX2of2(vex)       (((vex) & 0x4) >> 2)
71 #define ppFromVEX2of2(vex)      ((vex) & 0x3)
72
73 #define rFromXOP2of3(xop)       (((~(xop)) & 0x80) >> 7)
74 #define xFromXOP2of3(xop)       (((~(xop)) & 0x40) >> 6)
75 #define bFromXOP2of3(xop)       (((~(xop)) & 0x20) >> 5)
76 #define mmmmmFromXOP2of3(xop)   ((xop) & 0x1f)
77 #define wFromXOP3of3(xop)       (((xop) & 0x80) >> 7)
78 #define vvvvFromXOP3of3(vex)    (((~(vex)) & 0x78) >> 3)
79 #define lFromXOP3of3(xop)       (((xop) & 0x4) >> 2)
80 #define ppFromXOP3of3(xop)      ((xop) & 0x3)
81
82 /*
83  * These enums represent Intel registers for use by the decoder.
84  */
85
86 #define REGS_8BIT     \
87   ENTRY(AL)           \
88   ENTRY(CL)           \
89   ENTRY(DL)           \
90   ENTRY(BL)           \
91   ENTRY(AH)           \
92   ENTRY(CH)           \
93   ENTRY(DH)           \
94   ENTRY(BH)           \
95   ENTRY(R8B)          \
96   ENTRY(R9B)          \
97   ENTRY(R10B)         \
98   ENTRY(R11B)         \
99   ENTRY(R12B)         \
100   ENTRY(R13B)         \
101   ENTRY(R14B)         \
102   ENTRY(R15B)         \
103   ENTRY(SPL)          \
104   ENTRY(BPL)          \
105   ENTRY(SIL)          \
106   ENTRY(DIL)
107
108 #define EA_BASES_16BIT  \
109   ENTRY(BX_SI)          \
110   ENTRY(BX_DI)          \
111   ENTRY(BP_SI)          \
112   ENTRY(BP_DI)          \
113   ENTRY(SI)             \
114   ENTRY(DI)             \
115   ENTRY(BP)             \
116   ENTRY(BX)             \
117   ENTRY(R8W)            \
118   ENTRY(R9W)            \
119   ENTRY(R10W)           \
120   ENTRY(R11W)           \
121   ENTRY(R12W)           \
122   ENTRY(R13W)           \
123   ENTRY(R14W)           \
124   ENTRY(R15W)
125
126 #define REGS_16BIT    \
127   ENTRY(AX)           \
128   ENTRY(CX)           \
129   ENTRY(DX)           \
130   ENTRY(BX)           \
131   ENTRY(SP)           \
132   ENTRY(BP)           \
133   ENTRY(SI)           \
134   ENTRY(DI)           \
135   ENTRY(R8W)          \
136   ENTRY(R9W)          \
137   ENTRY(R10W)         \
138   ENTRY(R11W)         \
139   ENTRY(R12W)         \
140   ENTRY(R13W)         \
141   ENTRY(R14W)         \
142   ENTRY(R15W)
143
144 #define EA_BASES_32BIT  \
145   ENTRY(EAX)            \
146   ENTRY(ECX)            \
147   ENTRY(EDX)            \
148   ENTRY(EBX)            \
149   ENTRY(sib)            \
150   ENTRY(EBP)            \
151   ENTRY(ESI)            \
152   ENTRY(EDI)            \
153   ENTRY(R8D)            \
154   ENTRY(R9D)            \
155   ENTRY(R10D)           \
156   ENTRY(R11D)           \
157   ENTRY(R12D)           \
158   ENTRY(R13D)           \
159   ENTRY(R14D)           \
160   ENTRY(R15D)
161
162 #define REGS_32BIT  \
163   ENTRY(EAX)        \
164   ENTRY(ECX)        \
165   ENTRY(EDX)        \
166   ENTRY(EBX)        \
167   ENTRY(ESP)        \
168   ENTRY(EBP)        \
169   ENTRY(ESI)        \
170   ENTRY(EDI)        \
171   ENTRY(R8D)        \
172   ENTRY(R9D)        \
173   ENTRY(R10D)       \
174   ENTRY(R11D)       \
175   ENTRY(R12D)       \
176   ENTRY(R13D)       \
177   ENTRY(R14D)       \
178   ENTRY(R15D)
179
180 #define EA_BASES_64BIT  \
181   ENTRY(RAX)            \
182   ENTRY(RCX)            \
183   ENTRY(RDX)            \
184   ENTRY(RBX)            \
185   ENTRY(sib64)          \
186   ENTRY(RBP)            \
187   ENTRY(RSI)            \
188   ENTRY(RDI)            \
189   ENTRY(R8)             \
190   ENTRY(R9)             \
191   ENTRY(R10)            \
192   ENTRY(R11)            \
193   ENTRY(R12)            \
194   ENTRY(R13)            \
195   ENTRY(R14)            \
196   ENTRY(R15)
197
198 #define REGS_64BIT  \
199   ENTRY(RAX)        \
200   ENTRY(RCX)        \
201   ENTRY(RDX)        \
202   ENTRY(RBX)        \
203   ENTRY(RSP)        \
204   ENTRY(RBP)        \
205   ENTRY(RSI)        \
206   ENTRY(RDI)        \
207   ENTRY(R8)         \
208   ENTRY(R9)         \
209   ENTRY(R10)        \
210   ENTRY(R11)        \
211   ENTRY(R12)        \
212   ENTRY(R13)        \
213   ENTRY(R14)        \
214   ENTRY(R15)
215
216 #define REGS_MMX  \
217   ENTRY(MM0)      \
218   ENTRY(MM1)      \
219   ENTRY(MM2)      \
220   ENTRY(MM3)      \
221   ENTRY(MM4)      \
222   ENTRY(MM5)      \
223   ENTRY(MM6)      \
224   ENTRY(MM7)
225
226 #define REGS_XMM  \
227   ENTRY(XMM0)     \
228   ENTRY(XMM1)     \
229   ENTRY(XMM2)     \
230   ENTRY(XMM3)     \
231   ENTRY(XMM4)     \
232   ENTRY(XMM5)     \
233   ENTRY(XMM6)     \
234   ENTRY(XMM7)     \
235   ENTRY(XMM8)     \
236   ENTRY(XMM9)     \
237   ENTRY(XMM10)    \
238   ENTRY(XMM11)    \
239   ENTRY(XMM12)    \
240   ENTRY(XMM13)    \
241   ENTRY(XMM14)    \
242   ENTRY(XMM15)    \
243   ENTRY(XMM16)    \
244   ENTRY(XMM17)    \
245   ENTRY(XMM18)    \
246   ENTRY(XMM19)    \
247   ENTRY(XMM20)    \
248   ENTRY(XMM21)    \
249   ENTRY(XMM22)    \
250   ENTRY(XMM23)    \
251   ENTRY(XMM24)    \
252   ENTRY(XMM25)    \
253   ENTRY(XMM26)    \
254   ENTRY(XMM27)    \
255   ENTRY(XMM28)    \
256   ENTRY(XMM29)    \
257   ENTRY(XMM30)    \
258   ENTRY(XMM31)
259
260 #define REGS_YMM  \
261   ENTRY(YMM0)     \
262   ENTRY(YMM1)     \
263   ENTRY(YMM2)     \
264   ENTRY(YMM3)     \
265   ENTRY(YMM4)     \
266   ENTRY(YMM5)     \
267   ENTRY(YMM6)     \
268   ENTRY(YMM7)     \
269   ENTRY(YMM8)     \
270   ENTRY(YMM9)     \
271   ENTRY(YMM10)    \
272   ENTRY(YMM11)    \
273   ENTRY(YMM12)    \
274   ENTRY(YMM13)    \
275   ENTRY(YMM14)    \
276   ENTRY(YMM15)    \
277   ENTRY(YMM16)    \
278   ENTRY(YMM17)    \
279   ENTRY(YMM18)    \
280   ENTRY(YMM19)    \
281   ENTRY(YMM20)    \
282   ENTRY(YMM21)    \
283   ENTRY(YMM22)    \
284   ENTRY(YMM23)    \
285   ENTRY(YMM24)    \
286   ENTRY(YMM25)    \
287   ENTRY(YMM26)    \
288   ENTRY(YMM27)    \
289   ENTRY(YMM28)    \
290   ENTRY(YMM29)    \
291   ENTRY(YMM30)    \
292   ENTRY(YMM31)
293
294 #define REGS_ZMM  \
295   ENTRY(ZMM0)     \
296   ENTRY(ZMM1)     \
297   ENTRY(ZMM2)     \
298   ENTRY(ZMM3)     \
299   ENTRY(ZMM4)     \
300   ENTRY(ZMM5)     \
301   ENTRY(ZMM6)     \
302   ENTRY(ZMM7)     \
303   ENTRY(ZMM8)     \
304   ENTRY(ZMM9)     \
305   ENTRY(ZMM10)    \
306   ENTRY(ZMM11)    \
307   ENTRY(ZMM12)    \
308   ENTRY(ZMM13)    \
309   ENTRY(ZMM14)    \
310   ENTRY(ZMM15)    \
311   ENTRY(ZMM16)    \
312   ENTRY(ZMM17)    \
313   ENTRY(ZMM18)    \
314   ENTRY(ZMM19)    \
315   ENTRY(ZMM20)    \
316   ENTRY(ZMM21)    \
317   ENTRY(ZMM22)    \
318   ENTRY(ZMM23)    \
319   ENTRY(ZMM24)    \
320   ENTRY(ZMM25)    \
321   ENTRY(ZMM26)    \
322   ENTRY(ZMM27)    \
323   ENTRY(ZMM28)    \
324   ENTRY(ZMM29)    \
325   ENTRY(ZMM30)    \
326   ENTRY(ZMM31)
327
328 #define REGS_MASKS \
329   ENTRY(K0)        \
330   ENTRY(K1)        \
331   ENTRY(K2)        \
332   ENTRY(K3)        \
333   ENTRY(K4)        \
334   ENTRY(K5)        \
335   ENTRY(K6)        \
336   ENTRY(K7)
337
338 #define REGS_SEGMENT \
339   ENTRY(ES)          \
340   ENTRY(CS)          \
341   ENTRY(SS)          \
342   ENTRY(DS)          \
343   ENTRY(FS)          \
344   ENTRY(GS)
345
346 #define REGS_DEBUG  \
347   ENTRY(DR0)        \
348   ENTRY(DR1)        \
349   ENTRY(DR2)        \
350   ENTRY(DR3)        \
351   ENTRY(DR4)        \
352   ENTRY(DR5)        \
353   ENTRY(DR6)        \
354   ENTRY(DR7)
355
356 #define REGS_CONTROL  \
357   ENTRY(CR0)          \
358   ENTRY(CR1)          \
359   ENTRY(CR2)          \
360   ENTRY(CR3)          \
361   ENTRY(CR4)          \
362   ENTRY(CR5)          \
363   ENTRY(CR6)          \
364   ENTRY(CR7)          \
365   ENTRY(CR8)
366
367 #define ALL_EA_BASES  \
368   EA_BASES_16BIT      \
369   EA_BASES_32BIT      \
370   EA_BASES_64BIT
371
372 #define ALL_SIB_BASES \
373   REGS_32BIT          \
374   REGS_64BIT
375
376 #define ALL_REGS      \
377   REGS_8BIT           \
378   REGS_16BIT          \
379   REGS_32BIT          \
380   REGS_64BIT          \
381   REGS_MMX            \
382   REGS_XMM            \
383   REGS_YMM            \
384   REGS_ZMM            \
385   REGS_MASKS          \
386   REGS_SEGMENT        \
387   REGS_DEBUG          \
388   REGS_CONTROL        \
389   ENTRY(RIP)
390
391 /*
392  * EABase - All possible values of the base field for effective-address
393  *   computations, a.k.a. the Mod and R/M fields of the ModR/M byte.  We
394  *   distinguish between bases (EA_BASE_*) and registers that just happen to be
395  *   referred to when Mod == 0b11 (EA_REG_*).
396  */
397 typedef enum {
398   EA_BASE_NONE,
399 #define ENTRY(x) EA_BASE_##x,
400   ALL_EA_BASES
401 #undef ENTRY
402 #define ENTRY(x) EA_REG_##x,
403   ALL_REGS
404 #undef ENTRY
405   EA_max
406 } EABase;
407
408 /*
409  * SIBIndex - All possible values of the SIB index field.
410  *   Borrows entries from ALL_EA_BASES with the special case that
411  *   sib is synonymous with NONE.
412  * Vector SIB: index can be XMM or YMM.
413  */
414 typedef enum {
415   SIB_INDEX_NONE,
416 #define ENTRY(x) SIB_INDEX_##x,
417   ALL_EA_BASES
418   REGS_XMM
419   REGS_YMM
420   REGS_ZMM
421 #undef ENTRY
422   SIB_INDEX_max
423 } SIBIndex;
424
425 /*
426  * SIBBase - All possible values of the SIB base field.
427  */
428 typedef enum {
429   SIB_BASE_NONE,
430 #define ENTRY(x) SIB_BASE_##x,
431   ALL_SIB_BASES
432 #undef ENTRY
433   SIB_BASE_max
434 } SIBBase;
435
436 /*
437  * EADisplacement - Possible displacement types for effective-address
438  *   computations.
439  */
440 typedef enum {
441   EA_DISP_NONE,
442   EA_DISP_8,
443   EA_DISP_16,
444   EA_DISP_32
445 } EADisplacement;
446
447 /*
448  * Reg - All possible values of the reg field in the ModR/M byte.
449  */
450 typedef enum {
451 #define ENTRY(x) MODRM_REG_##x,
452   ALL_REGS
453 #undef ENTRY
454   MODRM_REG_max
455 } Reg;
456
457 /*
458  * SegmentOverride - All possible segment overrides.
459  */
460 typedef enum {
461   SEG_OVERRIDE_NONE,
462   SEG_OVERRIDE_CS,
463   SEG_OVERRIDE_SS,
464   SEG_OVERRIDE_DS,
465   SEG_OVERRIDE_ES,
466   SEG_OVERRIDE_FS,
467   SEG_OVERRIDE_GS,
468   SEG_OVERRIDE_max
469 } SegmentOverride;
470
471 /*
472  * VEXLeadingOpcodeByte - Possible values for the VEX.m-mmmm field
473  */
474
475 typedef enum {
476   VEX_LOB_0F = 0x1,
477   VEX_LOB_0F38 = 0x2,
478   VEX_LOB_0F3A = 0x3
479 } VEXLeadingOpcodeByte;
480
481 typedef enum {
482   XOP_MAP_SELECT_8 = 0x8,
483   XOP_MAP_SELECT_9 = 0x9,
484   XOP_MAP_SELECT_A = 0xA
485 } XOPMapSelect;
486
487 /*
488  * VEXPrefixCode - Possible values for the VEX.pp/EVEX.pp field
489  */
490
491 typedef enum {
492   VEX_PREFIX_NONE = 0x0,
493   VEX_PREFIX_66 = 0x1,
494   VEX_PREFIX_F3 = 0x2,
495   VEX_PREFIX_F2 = 0x3
496 } VEXPrefixCode;
497
498 typedef enum {
499   TYPE_NO_VEX_XOP   = 0x0,
500   TYPE_VEX_2B       = 0x1,
501   TYPE_VEX_3B       = 0x2,
502   TYPE_EVEX         = 0x3,
503   TYPE_XOP          = 0x4
504 } VectorExtensionType;
505
506 typedef uint8_t BOOL;
507
508 /*
509  * byteReader_t - Type for the byte reader that the consumer must provide to
510  *   the decoder.  Reads a single byte from the instruction's address space.
511  * @param arg     - A baton that the consumer can associate with any internal
512  *                  state that it needs.
513  * @param byte    - A pointer to a single byte in memory that should be set to
514  *                  contain the value at address.
515  * @param address - The address in the instruction's address space that should
516  *                  be read from.
517  * @return        - -1 if the byte cannot be read for any reason; 0 otherwise.
518  */
519 typedef int (*byteReader_t)(const void* arg, uint8_t* byte, uint64_t address);
520
521 /*
522  * dlog_t - Type for the logging function that the consumer can provide to
523  *   get debugging output from the decoder.
524  * @param arg     - A baton that the consumer can associate with any internal
525  *                  state that it needs.
526  * @param log     - A string that contains the message.  Will be reused after
527  *                  the logger returns.
528  */
529 typedef void (*dlog_t)(void* arg, const char *log);
530
531 /*
532  * The specification for how to extract and interpret a full instruction and
533  * its operands.
534  */
535 struct InstructionSpecifier {
536   uint16_t operands;
537 };
538
539 /*
540  * The x86 internal instruction, which is produced by the decoder.
541  */
542 struct InternalInstruction {
543   /* Reader interface (C) */
544   byteReader_t reader;
545   /* Opaque value passed to the reader */
546   const void* readerArg;
547   /* The address of the next byte to read via the reader */
548   uint64_t readerCursor;
549
550   /* Logger interface (C) */
551   dlog_t dlog;
552   /* Opaque value passed to the logger */
553   void* dlogArg;
554
555   /* General instruction information */
556
557   /* The mode to disassemble for (64-bit, protected, real) */
558   DisassemblerMode mode;
559   /* The start of the instruction, usable with the reader */
560   uint64_t startLocation;
561   /* The length of the instruction, in bytes */
562   size_t length;
563
564   /* Prefix state */
565
566   /* 1 if the prefix byte corresponding to the entry is present; 0 if not */
567   uint8_t prefixPresent[0x100];
568   /* contains the location (for use with the reader) of the prefix byte */
569   uint64_t prefixLocations[0x100];
570   /* The value of the vector extension prefix(EVEX/VEX/XOP), if present */
571   uint8_t vectorExtensionPrefix[4];
572   /* The type of the vector extension prefix */
573   VectorExtensionType vectorExtensionType;
574   /* The value of the REX prefix, if present */
575   uint8_t rexPrefix;
576   /* The location where a mandatory prefix would have to be (i.e., right before
577      the opcode, or right before the REX prefix if one is present) */
578   uint64_t necessaryPrefixLocation;
579   /* The segment override type */
580   SegmentOverride segmentOverride;
581   /* 1 if the prefix byte, 0xf2 or 0xf3 is xacquire or xrelease */
582   BOOL xAcquireRelease;
583
584   /* Sizes of various critical pieces of data, in bytes */
585   uint8_t registerSize;
586   uint8_t addressSize;
587   uint8_t displacementSize;
588   uint8_t immediateSize;
589
590   /* Offsets from the start of the instruction to the pieces of data, which is
591      needed to find relocation entries for adding symbolic operands */
592   uint8_t displacementOffset;
593   uint8_t immediateOffset;
594
595   /* opcode state */
596
597   /* The last byte of the opcode, not counting any ModR/M extension */
598   uint8_t opcode;
599   /* The ModR/M byte of the instruction, if it is an opcode extension */
600   uint8_t modRMExtension;
601
602   /* decode state */
603
604   /* The type of opcode, used for indexing into the array of decode tables */
605   OpcodeType opcodeType;
606   /* The instruction ID, extracted from the decode table */
607   uint16_t instructionID;
608   /* The specifier for the instruction, from the instruction info table */
609   const struct InstructionSpecifier *spec;
610
611   /* state for additional bytes, consumed during operand decode.  Pattern:
612      consumed___ indicates that the byte was already consumed and does not
613      need to be consumed again */
614
615   /* The VEX.vvvv field, which contains a third register operand for some AVX
616      instructions */
617   Reg                           vvvv;
618
619   /* The writemask for AVX-512 instructions which is contained in EVEX.aaa */
620   Reg                           writemask;
621
622   /* The ModR/M byte, which contains most register operands and some portion of
623      all memory operands */
624   BOOL                          consumedModRM;
625   uint8_t                       modRM;
626
627   /* The SIB byte, used for more complex 32- or 64-bit memory operands */
628   BOOL                          consumedSIB;
629   uint8_t                       sib;
630
631   /* The displacement, used for memory operands */
632   BOOL                          consumedDisplacement;
633   int32_t                       displacement;
634
635   /* Immediates.  There can be two in some cases */
636   uint8_t                       numImmediatesConsumed;
637   uint8_t                       numImmediatesTranslated;
638   uint64_t                      immediates[2];
639
640   /* A register or immediate operand encoded into the opcode */
641   Reg                           opcodeRegister;
642
643   /* Portions of the ModR/M byte */
644
645   /* These fields determine the allowable values for the ModR/M fields, which
646      depend on operand and address widths */
647   EABase                        eaBaseBase;
648   EABase                        eaRegBase;
649   Reg                           regBase;
650
651   /* The Mod and R/M fields can encode a base for an effective address, or a
652      register.  These are separated into two fields here */
653   EABase                        eaBase;
654   EADisplacement                eaDisplacement;
655   /* The reg field always encodes a register */
656   Reg                           reg;
657
658   /* SIB state */
659   SIBIndex                      sibIndex;
660   uint8_t                       sibScale;
661   SIBBase                       sibBase;
662
663   const struct OperandSpecifier *operands;
664 };
665
666 /* decodeInstruction - Decode one instruction and store the decoding results in
667  *   a buffer provided by the consumer.
668  * @param insn      - The buffer to store the instruction in.  Allocated by the
669  *                    consumer.
670  * @param reader    - The byteReader_t for the bytes to be read.
671  * @param readerArg - An argument to pass to the reader for storing context
672  *                    specific to the consumer.  May be NULL.
673  * @param logger    - The dlog_t to be used in printing status messages from the
674  *                    disassembler.  May be NULL.
675  * @param loggerArg - An argument to pass to the logger for storing context
676  *                    specific to the logger.  May be NULL.
677  * @param startLoc  - The address (in the reader's address space) of the first
678  *                    byte in the instruction.
679  * @param mode      - The mode (16-bit, 32-bit, 64-bit) to decode in.
680  * @return          - Nonzero if there was an error during decode, 0 otherwise.
681  */
682 int decodeInstruction(struct InternalInstruction* insn,
683                       byteReader_t reader,
684                       const void* readerArg,
685                       dlog_t logger,
686                       void* loggerArg,
687                       const void* miiArg,
688                       uint64_t startLoc,
689                       DisassemblerMode mode);
690
691 /* \brief Debug - Print a message to debugs()
692  * @param file  - The name of the file printing the debug message.
693  * @param line  - The line number that printed the debug message.
694  * @param s     - The message to print.
695  */
696
697 void Debug(const char *file, unsigned line, const char *s);
698
699 const char *GetInstrName(unsigned Opcode, const void *mii);
700
701 } // namespace X86Disassembler
702 } // namespace llvm
703
704 #endif