/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/CodeGen/MIRParser/MILexer.h
Line | Count | Source |
1 | | //===- MILexer.h - Lexer for machine instructions ---------------*- 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 declares the function that lexes the machine instruction source |
11 | | // string. |
12 | | // |
13 | | //===----------------------------------------------------------------------===// |
14 | | |
15 | | #ifndef LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H |
16 | | #define LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H |
17 | | |
18 | | #include "llvm/ADT/APSInt.h" |
19 | | #include "llvm/ADT/STLExtras.h" |
20 | | #include "llvm/ADT/StringRef.h" |
21 | | #include <string> |
22 | | |
23 | | namespace llvm { |
24 | | |
25 | | class Twine; |
26 | | |
27 | | /// A token produced by the machine instruction lexer. |
28 | | struct MIToken { |
29 | | enum TokenKind { |
30 | | // Markers |
31 | | Eof, |
32 | | Error, |
33 | | Newline, |
34 | | |
35 | | // Tokens with no info. |
36 | | comma, |
37 | | equal, |
38 | | underscore, |
39 | | colon, |
40 | | coloncolon, |
41 | | dot, |
42 | | exclaim, |
43 | | lparen, |
44 | | rparen, |
45 | | lbrace, |
46 | | rbrace, |
47 | | plus, |
48 | | minus, |
49 | | less, |
50 | | greater, |
51 | | |
52 | | // Keywords |
53 | | kw_implicit, |
54 | | kw_implicit_define, |
55 | | kw_def, |
56 | | kw_dead, |
57 | | kw_dereferenceable, |
58 | | kw_killed, |
59 | | kw_undef, |
60 | | kw_internal, |
61 | | kw_early_clobber, |
62 | | kw_debug_use, |
63 | | kw_tied_def, |
64 | | kw_frame_setup, |
65 | | kw_debug_location, |
66 | | kw_cfi_same_value, |
67 | | kw_cfi_offset, |
68 | | kw_cfi_def_cfa_register, |
69 | | kw_cfi_def_cfa_offset, |
70 | | kw_cfi_def_cfa, |
71 | | kw_blockaddress, |
72 | | kw_intrinsic, |
73 | | kw_target_index, |
74 | | kw_half, |
75 | | kw_float, |
76 | | kw_double, |
77 | | kw_x86_fp80, |
78 | | kw_fp128, |
79 | | kw_ppc_fp128, |
80 | | kw_target_flags, |
81 | | kw_volatile, |
82 | | kw_non_temporal, |
83 | | kw_invariant, |
84 | | kw_align, |
85 | | kw_stack, |
86 | | kw_got, |
87 | | kw_jump_table, |
88 | | kw_constant_pool, |
89 | | kw_call_entry, |
90 | | kw_liveout, |
91 | | kw_address_taken, |
92 | | kw_landing_pad, |
93 | | kw_liveins, |
94 | | kw_successors, |
95 | | kw_floatpred, |
96 | | kw_intpred, |
97 | | |
98 | | // Named metadata keywords |
99 | | md_tbaa, |
100 | | md_alias_scope, |
101 | | md_noalias, |
102 | | md_range, |
103 | | md_diexpr, |
104 | | |
105 | | // Identifier tokens |
106 | | Identifier, |
107 | | IntegerType, |
108 | | NamedRegister, |
109 | | MachineBasicBlockLabel, |
110 | | MachineBasicBlock, |
111 | | PointerType, |
112 | | ScalarType, |
113 | | StackObject, |
114 | | FixedStackObject, |
115 | | NamedGlobalValue, |
116 | | GlobalValue, |
117 | | ExternalSymbol, |
118 | | |
119 | | // Other tokens |
120 | | IntegerLiteral, |
121 | | FloatingPointLiteral, |
122 | | HexLiteral, |
123 | | VirtualRegister, |
124 | | ConstantPoolItem, |
125 | | JumpTableIndex, |
126 | | NamedIRBlock, |
127 | | IRBlock, |
128 | | NamedIRValue, |
129 | | IRValue, |
130 | | QuotedIRValue, // `<constant value>` |
131 | | SubRegisterIndex, |
132 | | StringConstant |
133 | | }; |
134 | | |
135 | | private: |
136 | | TokenKind Kind = Error; |
137 | | StringRef Range; |
138 | | StringRef StringValue; |
139 | | std::string StringValueStorage; |
140 | | APSInt IntVal; |
141 | | |
142 | | public: |
143 | 6.21k | MIToken() = default; |
144 | | |
145 | | MIToken &reset(TokenKind Kind, StringRef Range); |
146 | | |
147 | | MIToken &setStringValue(StringRef StrVal); |
148 | | MIToken &setOwnedStringValue(std::string StrVal); |
149 | | MIToken &setIntegerValue(APSInt IntVal); |
150 | | |
151 | 92.9k | TokenKind kind() const { return Kind; } |
152 | | |
153 | 22.8k | bool isError() const { return Kind == Error; } |
154 | | |
155 | 87.7k | bool isNewlineOrEOF() const { return Kind == Newline || 87.7k Kind == Eof68.6k ; } |
156 | | |
157 | 214k | bool isErrorOrEOF() const { return Kind == Error || 214k Kind == Eof214k ; } |
158 | | |
159 | 57.9k | bool isRegister() const { |
160 | 30.3k | return Kind == NamedRegister || Kind == underscore || |
161 | 26.2k | Kind == VirtualRegister; |
162 | 57.9k | } |
163 | | |
164 | 54.5k | bool isRegisterFlag() const { |
165 | 50.9k | return Kind == kw_implicit || Kind == kw_implicit_define || |
166 | 54.5k | Kind == kw_def49.1k || Kind == kw_dead49.1k || Kind == kw_killed48.1k || |
167 | 54.5k | Kind == kw_undef46.1k || Kind == kw_internal45.7k || |
168 | 54.5k | Kind == kw_early_clobber45.7k || Kind == kw_debug_use45.6k ; |
169 | 54.5k | } |
170 | | |
171 | 1.30k | bool isMemoryOperandFlag() const { |
172 | 1.21k | return Kind == kw_volatile || Kind == kw_non_temporal || |
173 | 1.30k | Kind == kw_dereferenceable1.16k || Kind == kw_invariant1.07k || |
174 | 1.01k | Kind == StringConstant; |
175 | 1.30k | } |
176 | | |
177 | 1.08M | bool is(TokenKind K) const { return Kind == K; } |
178 | | |
179 | 555k | bool isNot(TokenKind K) const { return Kind != K; } |
180 | | |
181 | 157k | StringRef::iterator location() const { return Range.begin(); } |
182 | | |
183 | 7.89k | StringRef range() const { return Range; } |
184 | | |
185 | | /// Return the token's string value. |
186 | 60.9k | StringRef stringValue() const { return StringValue; } |
187 | | |
188 | 38.3k | const APSInt &integerValue() const { return IntVal; } |
189 | | |
190 | 26.2k | bool hasIntegerValue() const { |
191 | 24.2k | return Kind == IntegerLiteral || Kind == MachineBasicBlock || |
192 | 26.2k | Kind == MachineBasicBlockLabel22.6k || Kind == StackObject16.0k || |
193 | 26.2k | Kind == FixedStackObject16.0k || Kind == GlobalValue15.9k || |
194 | 26.2k | Kind == VirtualRegister15.9k || Kind == ConstantPoolItem1.18k || |
195 | 26.2k | Kind == JumpTableIndex1.16k || Kind == IRBlock1.15k || Kind == IRValue422 ; |
196 | 26.2k | } |
197 | | }; |
198 | | |
199 | | /// Consume a single machine instruction token in the given source and return |
200 | | /// the remaining source string. |
201 | | StringRef lexMIToken( |
202 | | StringRef Source, MIToken &Token, |
203 | | function_ref<void(StringRef::iterator, const Twine &)> ErrorCallback); |
204 | | |
205 | | } // end namespace llvm |
206 | | |
207 | | #endif // LLVM_LIB_CODEGEN_MIRPARSER_MILEXER_H |