Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 1 | //===- MILexer.cpp - Machine instructions lexer implementation ----------===// |
| 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 implements the lexing of machine instructions. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "MILexer.h" |
Alex Lorenz | b29554d | 2015-07-20 20:31:01 +0000 | [diff] [blame] | 15 | #include "llvm/ADT/StringExtras.h" |
Alex Lorenz | cb268d4 | 2015-07-06 23:07:26 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/StringSwitch.h" |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/Twine.h" |
| 18 | #include <cctype> |
| 19 | |
| 20 | using namespace llvm; |
| 21 | |
| 22 | namespace { |
| 23 | |
| 24 | /// This class provides a way to iterate and get characters from the source |
| 25 | /// string. |
| 26 | class Cursor { |
| 27 | const char *Ptr; |
| 28 | const char *End; |
| 29 | |
| 30 | public: |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 31 | Cursor(NoneType) : Ptr(nullptr), End(nullptr) {} |
| 32 | |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 33 | explicit Cursor(StringRef Str) { |
| 34 | Ptr = Str.data(); |
| 35 | End = Ptr + Str.size(); |
| 36 | } |
| 37 | |
| 38 | bool isEOF() const { return Ptr == End; } |
| 39 | |
NAKAMURA Takumi | c267b5f | 2015-06-24 06:40:09 +0000 | [diff] [blame] | 40 | char peek(int I = 0) const { return End - Ptr <= I ? 0 : Ptr[I]; } |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 41 | |
Alex Lorenz | 33f0aef | 2015-06-26 16:46:11 +0000 | [diff] [blame] | 42 | void advance(unsigned I = 1) { Ptr += I; } |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 43 | |
| 44 | StringRef remaining() const { return StringRef(Ptr, End - Ptr); } |
| 45 | |
| 46 | StringRef upto(Cursor C) const { |
| 47 | assert(C.Ptr >= Ptr && C.Ptr <= End); |
| 48 | return StringRef(Ptr, C.Ptr - Ptr); |
| 49 | } |
| 50 | |
| 51 | StringRef::iterator location() const { return Ptr; } |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 52 | |
| 53 | operator bool() const { return Ptr != nullptr; } |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | } // end anonymous namespace |
| 57 | |
| 58 | /// Skip the leading whitespace characters and return the updated cursor. |
| 59 | static Cursor skipWhitespace(Cursor C) { |
| 60 | while (isspace(C.peek())) |
| 61 | C.advance(); |
| 62 | return C; |
| 63 | } |
| 64 | |
Alex Lorenz | 484903e | 2015-07-17 22:48:04 +0000 | [diff] [blame] | 65 | /// Return true if the given character satisfies the following regular |
| 66 | /// expression: [-a-zA-Z$._0-9] |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 67 | static bool isIdentifierChar(char C) { |
Alex Lorenz | 484903e | 2015-07-17 22:48:04 +0000 | [diff] [blame] | 68 | return isalpha(C) || isdigit(C) || C == '_' || C == '-' || C == '.' || |
| 69 | C == '$'; |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Alex Lorenz | b29554d | 2015-07-20 20:31:01 +0000 | [diff] [blame] | 72 | void MIToken::unescapeQuotedStringValue(std::string &Str) const { |
| 73 | assert(isStringValueQuoted() && "String value isn't quoted"); |
| 74 | StringRef Value = Range.drop_front(StringOffset); |
| 75 | assert(Value.front() == '"' && Value.back() == '"'); |
| 76 | Cursor C = Cursor(Value.substr(1, Value.size() - 2)); |
| 77 | |
| 78 | Str.clear(); |
| 79 | Str.reserve(C.remaining().size()); |
| 80 | while (!C.isEOF()) { |
| 81 | char Char = C.peek(); |
| 82 | if (Char == '\\') { |
| 83 | if (C.peek(1) == '\\') { |
| 84 | // Two '\' become one |
| 85 | Str += '\\'; |
| 86 | C.advance(2); |
| 87 | continue; |
| 88 | } |
| 89 | if (isxdigit(C.peek(1)) && isxdigit(C.peek(2))) { |
| 90 | Str += hexDigitValue(C.peek(1)) * 16 + hexDigitValue(C.peek(2)); |
| 91 | C.advance(3); |
| 92 | continue; |
| 93 | } |
| 94 | } |
| 95 | Str += Char; |
| 96 | C.advance(); |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | /// Lex a string constant using the following regular expression: \"[^\"]*\" |
| 101 | static Cursor lexStringConstant( |
| 102 | Cursor C, |
| 103 | function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { |
| 104 | assert(C.peek() == '"'); |
| 105 | for (C.advance(); C.peek() != '"'; C.advance()) { |
| 106 | if (C.isEOF()) { |
| 107 | ErrorCallback( |
| 108 | C.location(), |
| 109 | "end of machine instruction reached before the closing '\"'"); |
| 110 | return None; |
| 111 | } |
| 112 | } |
| 113 | C.advance(); |
| 114 | return C; |
| 115 | } |
| 116 | |
Alex Lorenz | 82a1cfd | 2015-07-28 17:03:40 +0000 | [diff] [blame^] | 117 | static Cursor lexName( |
| 118 | Cursor C, MIToken &Token, MIToken::TokenKind Type, |
| 119 | MIToken::TokenKind QuotedType, unsigned PrefixLength, |
| 120 | function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { |
| 121 | auto Range = C; |
| 122 | C.advance(PrefixLength); |
| 123 | if (C.peek() == '"') { |
| 124 | if (Cursor R = lexStringConstant(C, ErrorCallback)) { |
| 125 | Token = MIToken(QuotedType, Range.upto(R), PrefixLength); |
| 126 | return R; |
| 127 | } |
| 128 | Token = MIToken(MIToken::Error, Range.remaining()); |
| 129 | return Range; |
| 130 | } |
| 131 | while (isIdentifierChar(C.peek())) |
| 132 | C.advance(); |
| 133 | Token = MIToken(Type, Range.upto(C), PrefixLength); |
| 134 | return C; |
| 135 | } |
| 136 | |
Alex Lorenz | cb268d4 | 2015-07-06 23:07:26 +0000 | [diff] [blame] | 137 | static MIToken::TokenKind getIdentifierKind(StringRef Identifier) { |
| 138 | return StringSwitch<MIToken::TokenKind>(Identifier) |
| 139 | .Case("_", MIToken::underscore) |
| 140 | .Case("implicit", MIToken::kw_implicit) |
| 141 | .Case("implicit-def", MIToken::kw_implicit_define) |
Alex Lorenz | cbbfd0b | 2015-07-07 20:34:53 +0000 | [diff] [blame] | 142 | .Case("dead", MIToken::kw_dead) |
Alex Lorenz | 495ad87 | 2015-07-08 21:23:34 +0000 | [diff] [blame] | 143 | .Case("killed", MIToken::kw_killed) |
Alex Lorenz | 4d026b89 | 2015-07-08 23:58:31 +0000 | [diff] [blame] | 144 | .Case("undef", MIToken::kw_undef) |
Alex Lorenz | e5a4466 | 2015-07-17 00:24:15 +0000 | [diff] [blame] | 145 | .Case("frame-setup", MIToken::kw_frame_setup) |
Alex Lorenz | 46d760d | 2015-07-22 21:15:11 +0000 | [diff] [blame] | 146 | .Case("debug-location", MIToken::kw_debug_location) |
Alex Lorenz | 8cfc686 | 2015-07-23 23:09:07 +0000 | [diff] [blame] | 147 | .Case(".cfi_offset", MIToken::kw_cfi_offset) |
Alex Lorenz | 5b0d5f6 | 2015-07-27 20:39:03 +0000 | [diff] [blame] | 148 | .Case(".cfi_def_cfa_register", MIToken::kw_cfi_def_cfa_register) |
Alex Lorenz | f4baeb5 | 2015-07-21 22:28:27 +0000 | [diff] [blame] | 149 | .Case(".cfi_def_cfa_offset", MIToken::kw_cfi_def_cfa_offset) |
Alex Lorenz | cb268d4 | 2015-07-06 23:07:26 +0000 | [diff] [blame] | 150 | .Default(MIToken::Identifier); |
| 151 | } |
| 152 | |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 153 | static Cursor maybeLexIdentifier(Cursor C, MIToken &Token) { |
Alex Lorenz | f4baeb5 | 2015-07-21 22:28:27 +0000 | [diff] [blame] | 154 | if (!isalpha(C.peek()) && C.peek() != '_' && C.peek() != '.') |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 155 | return None; |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 156 | auto Range = C; |
| 157 | while (isIdentifierChar(C.peek())) |
| 158 | C.advance(); |
Alex Lorenz | 12b554e | 2015-06-24 17:34:58 +0000 | [diff] [blame] | 159 | auto Identifier = Range.upto(C); |
Alex Lorenz | cb268d4 | 2015-07-06 23:07:26 +0000 | [diff] [blame] | 160 | Token = MIToken(getIdentifierKind(Identifier), Identifier); |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 161 | return C; |
| 162 | } |
| 163 | |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 164 | static Cursor maybeLexMachineBasicBlock( |
Alex Lorenz | 33f0aef | 2015-06-26 16:46:11 +0000 | [diff] [blame] | 165 | Cursor C, MIToken &Token, |
| 166 | function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 167 | if (!C.remaining().startswith("%bb.")) |
| 168 | return None; |
Alex Lorenz | 33f0aef | 2015-06-26 16:46:11 +0000 | [diff] [blame] | 169 | auto Range = C; |
| 170 | C.advance(4); // Skip '%bb.' |
| 171 | if (!isdigit(C.peek())) { |
| 172 | Token = MIToken(MIToken::Error, C.remaining()); |
| 173 | ErrorCallback(C.location(), "expected a number after '%bb.'"); |
| 174 | return C; |
| 175 | } |
| 176 | auto NumberRange = C; |
| 177 | while (isdigit(C.peek())) |
| 178 | C.advance(); |
| 179 | StringRef Number = NumberRange.upto(C); |
| 180 | unsigned StringOffset = 4 + Number.size(); // Drop '%bb.<id>' |
| 181 | if (C.peek() == '.') { |
| 182 | C.advance(); // Skip '.' |
| 183 | ++StringOffset; |
| 184 | while (isIdentifierChar(C.peek())) |
| 185 | C.advance(); |
| 186 | } |
| 187 | Token = MIToken(MIToken::MachineBasicBlock, Range.upto(C), APSInt(Number), |
| 188 | StringOffset); |
| 189 | return C; |
| 190 | } |
| 191 | |
Alex Lorenz | 31d7068 | 2015-07-15 23:38:35 +0000 | [diff] [blame] | 192 | static Cursor maybeLexIndex(Cursor C, MIToken &Token, StringRef Rule, |
| 193 | MIToken::TokenKind Kind) { |
| 194 | if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size()))) |
| 195 | return None; |
| 196 | auto Range = C; |
| 197 | C.advance(Rule.size()); |
| 198 | auto NumberRange = C; |
| 199 | while (isdigit(C.peek())) |
| 200 | C.advance(); |
| 201 | Token = MIToken(Kind, Range.upto(C), APSInt(NumberRange.upto(C))); |
| 202 | return C; |
| 203 | } |
| 204 | |
Alex Lorenz | 7feaf7c | 2015-07-16 23:37:45 +0000 | [diff] [blame] | 205 | static Cursor maybeLexIndexAndName(Cursor C, MIToken &Token, StringRef Rule, |
| 206 | MIToken::TokenKind Kind) { |
| 207 | if (!C.remaining().startswith(Rule) || !isdigit(C.peek(Rule.size()))) |
| 208 | return None; |
| 209 | auto Range = C; |
| 210 | C.advance(Rule.size()); |
| 211 | auto NumberRange = C; |
| 212 | while (isdigit(C.peek())) |
| 213 | C.advance(); |
| 214 | StringRef Number = NumberRange.upto(C); |
| 215 | unsigned StringOffset = Rule.size() + Number.size(); |
| 216 | if (C.peek() == '.') { |
| 217 | C.advance(); |
| 218 | ++StringOffset; |
| 219 | while (isIdentifierChar(C.peek())) |
| 220 | C.advance(); |
| 221 | } |
| 222 | Token = MIToken(Kind, Range.upto(C), APSInt(Number), StringOffset); |
| 223 | return C; |
| 224 | } |
| 225 | |
Alex Lorenz | 31d7068 | 2015-07-15 23:38:35 +0000 | [diff] [blame] | 226 | static Cursor maybeLexJumpTableIndex(Cursor C, MIToken &Token) { |
| 227 | return maybeLexIndex(C, Token, "%jump-table.", MIToken::JumpTableIndex); |
| 228 | } |
| 229 | |
Alex Lorenz | 7feaf7c | 2015-07-16 23:37:45 +0000 | [diff] [blame] | 230 | static Cursor maybeLexStackObject(Cursor C, MIToken &Token) { |
| 231 | return maybeLexIndexAndName(C, Token, "%stack.", MIToken::StackObject); |
| 232 | } |
| 233 | |
| 234 | static Cursor maybeLexFixedStackObject(Cursor C, MIToken &Token) { |
| 235 | return maybeLexIndex(C, Token, "%fixed-stack.", MIToken::FixedStackObject); |
| 236 | } |
| 237 | |
Alex Lorenz | ab98049 | 2015-07-20 20:51:18 +0000 | [diff] [blame] | 238 | static Cursor maybeLexConstantPoolItem(Cursor C, MIToken &Token) { |
| 239 | return maybeLexIndex(C, Token, "%const.", MIToken::ConstantPoolItem); |
| 240 | } |
| 241 | |
Alex Lorenz | 8a1915b | 2015-07-27 22:42:41 +0000 | [diff] [blame] | 242 | static Cursor maybeLexIRBlock(Cursor C, MIToken &Token) { |
| 243 | return maybeLexIndex(C, Token, "%ir-block.", MIToken::IRBlock); |
| 244 | } |
| 245 | |
Alex Lorenz | 5346451 | 2015-07-10 22:51:20 +0000 | [diff] [blame] | 246 | static Cursor lexVirtualRegister(Cursor C, MIToken &Token) { |
| 247 | auto Range = C; |
| 248 | C.advance(); // Skip '%' |
| 249 | auto NumberRange = C; |
| 250 | while (isdigit(C.peek())) |
| 251 | C.advance(); |
| 252 | Token = MIToken(MIToken::VirtualRegister, Range.upto(C), |
| 253 | APSInt(NumberRange.upto(C))); |
| 254 | return C; |
| 255 | } |
| 256 | |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 257 | static Cursor maybeLexRegister(Cursor C, MIToken &Token) { |
| 258 | if (C.peek() != '%') |
| 259 | return None; |
Alex Lorenz | 5346451 | 2015-07-10 22:51:20 +0000 | [diff] [blame] | 260 | if (isdigit(C.peek(1))) |
| 261 | return lexVirtualRegister(C, Token); |
Alex Lorenz | f3db51de | 2015-06-23 16:35:26 +0000 | [diff] [blame] | 262 | auto Range = C; |
| 263 | C.advance(); // Skip '%' |
| 264 | while (isIdentifierChar(C.peek())) |
| 265 | C.advance(); |
Alex Lorenz | 33f0aef | 2015-06-26 16:46:11 +0000 | [diff] [blame] | 266 | Token = MIToken(MIToken::NamedRegister, Range.upto(C), |
| 267 | /*StringOffset=*/1); // Drop the '%' |
Alex Lorenz | f3db51de | 2015-06-23 16:35:26 +0000 | [diff] [blame] | 268 | return C; |
| 269 | } |
| 270 | |
Alex Lorenz | c1fbb35 | 2015-07-21 21:23:08 +0000 | [diff] [blame] | 271 | static Cursor maybeLexGlobalValue( |
| 272 | Cursor C, MIToken &Token, |
| 273 | function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { |
| 274 | if (C.peek() != '@') |
| 275 | return None; |
| 276 | if (!isdigit(C.peek(1))) |
| 277 | return lexName(C, Token, MIToken::NamedGlobalValue, |
| 278 | MIToken::QuotedNamedGlobalValue, /*PrefixLength=*/1, |
| 279 | ErrorCallback); |
| 280 | auto Range = C; |
| 281 | C.advance(1); // Skip the '@' |
| 282 | auto NumberRange = C; |
| 283 | while (isdigit(C.peek())) |
| 284 | C.advance(); |
| 285 | Token = |
| 286 | MIToken(MIToken::GlobalValue, Range.upto(C), APSInt(NumberRange.upto(C))); |
| 287 | return C; |
| 288 | } |
| 289 | |
Alex Lorenz | 6ede374 | 2015-07-21 16:59:53 +0000 | [diff] [blame] | 290 | static Cursor maybeLexExternalSymbol( |
| 291 | Cursor C, MIToken &Token, |
| 292 | function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { |
| 293 | if (C.peek() != '$') |
| 294 | return None; |
| 295 | return lexName(C, Token, MIToken::ExternalSymbol, |
| 296 | MIToken::QuotedExternalSymbol, |
| 297 | /*PrefixLength=*/1, ErrorCallback); |
| 298 | } |
| 299 | |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 300 | static Cursor maybeLexIntegerLiteral(Cursor C, MIToken &Token) { |
| 301 | if (!isdigit(C.peek()) && (C.peek() != '-' || !isdigit(C.peek(1)))) |
| 302 | return None; |
Alex Lorenz | 240fc1e | 2015-06-23 23:42:28 +0000 | [diff] [blame] | 303 | auto Range = C; |
| 304 | C.advance(); |
| 305 | while (isdigit(C.peek())) |
| 306 | C.advance(); |
| 307 | StringRef StrVal = Range.upto(C); |
| 308 | Token = MIToken(MIToken::IntegerLiteral, StrVal, APSInt(StrVal)); |
| 309 | return C; |
| 310 | } |
| 311 | |
Alex Lorenz | f3db51de | 2015-06-23 16:35:26 +0000 | [diff] [blame] | 312 | static MIToken::TokenKind symbolToken(char C) { |
| 313 | switch (C) { |
| 314 | case ',': |
| 315 | return MIToken::comma; |
| 316 | case '=': |
| 317 | return MIToken::equal; |
Alex Lorenz | 2eacca8 | 2015-07-13 23:24:34 +0000 | [diff] [blame] | 318 | case ':': |
| 319 | return MIToken::colon; |
Alex Lorenz | 35e4446 | 2015-07-22 17:58:46 +0000 | [diff] [blame] | 320 | case '!': |
| 321 | return MIToken::exclaim; |
Alex Lorenz | f3db51de | 2015-06-23 16:35:26 +0000 | [diff] [blame] | 322 | default: |
| 323 | return MIToken::Error; |
| 324 | } |
| 325 | } |
| 326 | |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 327 | static Cursor maybeLexSymbol(Cursor C, MIToken &Token) { |
| 328 | auto Kind = symbolToken(C.peek()); |
| 329 | if (Kind == MIToken::Error) |
| 330 | return None; |
Alex Lorenz | f3db51de | 2015-06-23 16:35:26 +0000 | [diff] [blame] | 331 | auto Range = C; |
| 332 | C.advance(); |
| 333 | Token = MIToken(Kind, Range.upto(C)); |
| 334 | return C; |
| 335 | } |
| 336 | |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 337 | StringRef llvm::lexMIToken( |
| 338 | StringRef Source, MIToken &Token, |
| 339 | function_ref<void(StringRef::iterator Loc, const Twine &)> ErrorCallback) { |
| 340 | auto C = skipWhitespace(Cursor(Source)); |
| 341 | if (C.isEOF()) { |
| 342 | Token = MIToken(MIToken::Eof, C.remaining()); |
| 343 | return C.remaining(); |
| 344 | } |
| 345 | |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 346 | if (Cursor R = maybeLexIdentifier(C, Token)) |
| 347 | return R.remaining(); |
| 348 | if (Cursor R = maybeLexMachineBasicBlock(C, Token, ErrorCallback)) |
| 349 | return R.remaining(); |
Alex Lorenz | 31d7068 | 2015-07-15 23:38:35 +0000 | [diff] [blame] | 350 | if (Cursor R = maybeLexJumpTableIndex(C, Token)) |
| 351 | return R.remaining(); |
Alex Lorenz | 7feaf7c | 2015-07-16 23:37:45 +0000 | [diff] [blame] | 352 | if (Cursor R = maybeLexStackObject(C, Token)) |
| 353 | return R.remaining(); |
| 354 | if (Cursor R = maybeLexFixedStackObject(C, Token)) |
| 355 | return R.remaining(); |
Alex Lorenz | ab98049 | 2015-07-20 20:51:18 +0000 | [diff] [blame] | 356 | if (Cursor R = maybeLexConstantPoolItem(C, Token)) |
| 357 | return R.remaining(); |
Alex Lorenz | 8a1915b | 2015-07-27 22:42:41 +0000 | [diff] [blame] | 358 | if (Cursor R = maybeLexIRBlock(C, Token)) |
| 359 | return R.remaining(); |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 360 | if (Cursor R = maybeLexRegister(C, Token)) |
| 361 | return R.remaining(); |
Alex Lorenz | b29554d | 2015-07-20 20:31:01 +0000 | [diff] [blame] | 362 | if (Cursor R = maybeLexGlobalValue(C, Token, ErrorCallback)) |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 363 | return R.remaining(); |
Alex Lorenz | 6ede374 | 2015-07-21 16:59:53 +0000 | [diff] [blame] | 364 | if (Cursor R = maybeLexExternalSymbol(C, Token, ErrorCallback)) |
| 365 | return R.remaining(); |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 366 | if (Cursor R = maybeLexIntegerLiteral(C, Token)) |
| 367 | return R.remaining(); |
| 368 | if (Cursor R = maybeLexSymbol(C, Token)) |
| 369 | return R.remaining(); |
| 370 | |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 371 | Token = MIToken(MIToken::Error, C.remaining()); |
| 372 | ErrorCallback(C.location(), |
Alex Lorenz | 6c6c46e | 2015-06-30 16:51:29 +0000 | [diff] [blame] | 373 | Twine("unexpected character '") + Twine(C.peek()) + "'"); |
Alex Lorenz | 91370c5 | 2015-06-22 20:37:46 +0000 | [diff] [blame] | 374 | return C.remaining(); |
| 375 | } |