[TableGen] Correct Namespace lookup with AltNames in AsmWriterEmitter
[oota-llvm.git] / utils / TableGen / X86ModRMFilters.h
1 //===- X86ModRMFilters.h - Disassembler ModR/M filterss ---------*- 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 Emitter.
11 // It contains ModR/M filters that determine which values of the ModR/M byte
12 //  are valid for a partiuclar instruction.
13 // Documentation for the disassembler emitter in general can be found in
14 //  X86DisasemblerEmitter.h.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_UTILS_TABLEGEN_X86MODRMFILTERS_H
19 #define LLVM_UTILS_TABLEGEN_X86MODRMFILTERS_H
20
21 #include "llvm/Support/DataTypes.h"
22
23 namespace llvm {
24
25 namespace X86Disassembler {
26
27 /// ModRMFilter - Abstract base class for clases that recognize patterns in
28 ///   ModR/M bytes.
29 class ModRMFilter {
30   virtual void anchor();
31 public:
32   /// Destructor    - Override as necessary.
33   virtual ~ModRMFilter() { }
34
35   /// isDumb        - Indicates whether this filter returns the same value for
36   ///                 any value of the ModR/M byte.
37   ///
38   /// @result       - True if the filter returns the same value for any ModR/M
39   ///                 byte; false if not.
40   virtual bool isDumb() const { return false; }
41   
42   /// accepts       - Indicates whether the filter accepts a particular ModR/M
43   ///                 byte value.
44   ///
45   /// @result       - True if the filter accepts the ModR/M byte; false if not.
46   virtual bool accepts(uint8_t modRM) const = 0;
47 };
48
49 /// DumbFilter - Accepts any ModR/M byte.  Used for instructions that do not
50 ///   require a ModR/M byte or instructions where the entire ModR/M byte is used
51 ///   for operands.
52 class DumbFilter : public ModRMFilter {
53   void anchor() override;
54 public:
55   bool isDumb() const override {
56     return true;
57   }
58
59   bool accepts(uint8_t modRM) const override {
60     return true;
61   }
62 };
63
64 /// ModFilter - Filters based on the mod bits [bits 7-6] of the ModR/M byte.
65 ///   Some instructions are classified based on whether they are 11 or anything
66 ///   else.  This filter performs that classification.
67 class ModFilter : public ModRMFilter {
68   void anchor() override;
69   bool R;
70 public:
71   /// Constructor
72   ///
73   /// \param r        True if the mod bits of the ModR/M byte must be 11; false
74   ///                 otherwise.  The name r derives from the fact that the mod
75   ///                 bits indicate whether the R/M bits [bits 2-0] signify a
76   ///                 register or a memory operand.
77   ModFilter(bool r) :
78     ModRMFilter(),
79     R(r) {
80   }
81
82   bool accepts(uint8_t modRM) const override {
83     return (R == ((modRM & 0xc0) == 0xc0));
84   }
85 };
86
87 /// ExtendedFilter - Extended opcodes are classified based on the value of the
88 ///   mod field [bits 7-6] and the value of the nnn field [bits 5-3]. 
89 class ExtendedFilter : public ModRMFilter {
90   void anchor() override;
91   bool R;
92   uint8_t NNN;
93 public:
94   /// Constructor
95   ///
96   /// \param r   True if the mod field must be set to 11; false otherwise.
97   ///            The name is explained at ModFilter.
98   /// \param nnn The required value of the nnn field.
99   ExtendedFilter(bool r, uint8_t nnn) : 
100     ModRMFilter(),
101     R(r),
102     NNN(nnn) {
103   }
104
105   bool accepts(uint8_t modRM) const override {
106     return (((R  && ((modRM & 0xc0) == 0xc0)) ||
107              (!R && ((modRM & 0xc0) != 0xc0))) &&
108             (((modRM & 0x38) >> 3) == NNN));
109   }
110 };
111
112 /// ExactFilter - The occasional extended opcode (such as VMCALL or MONITOR)
113 ///   requires the ModR/M byte to have a specific value.
114 class ExactFilter : public ModRMFilter {
115   void anchor() override;
116   uint8_t ModRM;
117 public:
118   /// Constructor
119   ///
120   /// \param modRM The required value of the full ModR/M byte.
121   ExactFilter(uint8_t modRM) :
122     ModRMFilter(),
123     ModRM(modRM) {
124   }
125
126   bool accepts(uint8_t modRM) const override {
127     return (ModRM == modRM);
128   }
129 };
130
131 } // namespace X86Disassembler
132
133 } // namespace llvm
134
135 #endif