LLLexer.cpp 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. //===- LLLexer.cpp - Lexer for .ll Files ----------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // Implement the Lexer for .ll files.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "llvm/AsmParser/LLLexer.h"
  13. #include "llvm/ADT/APInt.h"
  14. #include "llvm/ADT/STLExtras.h"
  15. #include "llvm/ADT/StringExtras.h"
  16. #include "llvm/ADT/Twine.h"
  17. #include "llvm/IR/DerivedTypes.h"
  18. #include "llvm/IR/Instruction.h"
  19. #include "llvm/Support/ErrorHandling.h"
  20. #include "llvm/Support/SourceMgr.h"
  21. #include <cassert>
  22. #include <cctype>
  23. #include <cstdio>
  24. using namespace llvm;
  25. bool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
  26. ErrorInfo = SM.GetMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
  27. return true;
  28. }
  29. void LLLexer::Warning(LocTy WarningLoc, const Twine &Msg) const {
  30. SM.PrintMessage(WarningLoc, SourceMgr::DK_Warning, Msg);
  31. }
  32. //===----------------------------------------------------------------------===//
  33. // Helper functions.
  34. //===----------------------------------------------------------------------===//
  35. // atoull - Convert an ascii string of decimal digits into the unsigned long
  36. // long representation... this does not have to do input error checking,
  37. // because we know that the input will be matched by a suitable regex...
  38. //
  39. uint64_t LLLexer::atoull(const char *Buffer, const char *End) {
  40. uint64_t Result = 0;
  41. for (; Buffer != End; Buffer++) {
  42. uint64_t OldRes = Result;
  43. Result *= 10;
  44. Result += *Buffer-'0';
  45. if (Result < OldRes) { // Uh, oh, overflow detected!!!
  46. Error("constant bigger than 64 bits detected!");
  47. return 0;
  48. }
  49. }
  50. return Result;
  51. }
  52. uint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
  53. uint64_t Result = 0;
  54. for (; Buffer != End; ++Buffer) {
  55. uint64_t OldRes = Result;
  56. Result *= 16;
  57. Result += hexDigitValue(*Buffer);
  58. if (Result < OldRes) { // Uh, oh, overflow detected!!!
  59. Error("constant bigger than 64 bits detected!");
  60. return 0;
  61. }
  62. }
  63. return Result;
  64. }
  65. void LLLexer::HexToIntPair(const char *Buffer, const char *End,
  66. uint64_t Pair[2]) {
  67. Pair[0] = 0;
  68. if (End - Buffer >= 16) {
  69. for (int i = 0; i < 16; i++, Buffer++) {
  70. assert(Buffer != End);
  71. Pair[0] *= 16;
  72. Pair[0] += hexDigitValue(*Buffer);
  73. }
  74. }
  75. Pair[1] = 0;
  76. for (int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
  77. Pair[1] *= 16;
  78. Pair[1] += hexDigitValue(*Buffer);
  79. }
  80. if (Buffer != End)
  81. Error("constant bigger than 128 bits detected!");
  82. }
  83. /// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
  84. /// { low64, high16 } as usual for an APInt.
  85. void LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
  86. uint64_t Pair[2]) {
  87. Pair[1] = 0;
  88. for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
  89. assert(Buffer != End);
  90. Pair[1] *= 16;
  91. Pair[1] += hexDigitValue(*Buffer);
  92. }
  93. Pair[0] = 0;
  94. for (int i = 0; i < 16 && Buffer != End; i++, Buffer++) {
  95. Pair[0] *= 16;
  96. Pair[0] += hexDigitValue(*Buffer);
  97. }
  98. if (Buffer != End)
  99. Error("constant bigger than 128 bits detected!");
  100. }
  101. // UnEscapeLexed - Run through the specified buffer and change \xx codes to the
  102. // appropriate character.
  103. static void UnEscapeLexed(std::string &Str) {
  104. if (Str.empty()) return;
  105. char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
  106. char *BOut = Buffer;
  107. for (char *BIn = Buffer; BIn != EndBuffer; ) {
  108. if (BIn[0] == '\\') {
  109. if (BIn < EndBuffer-1 && BIn[1] == '\\') {
  110. *BOut++ = '\\'; // Two \ becomes one
  111. BIn += 2;
  112. } else if (BIn < EndBuffer-2 &&
  113. isxdigit(static_cast<unsigned char>(BIn[1])) &&
  114. isxdigit(static_cast<unsigned char>(BIn[2]))) {
  115. *BOut = hexDigitValue(BIn[1]) * 16 + hexDigitValue(BIn[2]);
  116. BIn += 3; // Skip over handled chars
  117. ++BOut;
  118. } else {
  119. *BOut++ = *BIn++;
  120. }
  121. } else {
  122. *BOut++ = *BIn++;
  123. }
  124. }
  125. Str.resize(BOut-Buffer);
  126. }
  127. /// isLabelChar - Return true for [-a-zA-Z$._0-9].
  128. static bool isLabelChar(char C) {
  129. return isalnum(static_cast<unsigned char>(C)) || C == '-' || C == '$' ||
  130. C == '.' || C == '_';
  131. }
  132. /// isLabelTail - Return true if this pointer points to a valid end of a label.
  133. static const char *isLabelTail(const char *CurPtr) {
  134. while (true) {
  135. if (CurPtr[0] == ':') return CurPtr+1;
  136. if (!isLabelChar(CurPtr[0])) return nullptr;
  137. ++CurPtr;
  138. }
  139. }
  140. //===----------------------------------------------------------------------===//
  141. // Lexer definition.
  142. //===----------------------------------------------------------------------===//
  143. LLLexer::LLLexer(StringRef StartBuf, SourceMgr &SM, SMDiagnostic &Err,
  144. LLVMContext &C)
  145. : CurBuf(StartBuf), ErrorInfo(Err), SM(SM), Context(C), APFloatVal(0.0),
  146. IgnoreColonInIdentifiers(false) {
  147. CurPtr = CurBuf.begin();
  148. }
  149. int LLLexer::getNextChar() {
  150. char CurChar = *CurPtr++;
  151. switch (CurChar) {
  152. default: return (unsigned char)CurChar;
  153. case 0:
  154. // A nul character in the stream is either the end of the current buffer or
  155. // a random nul in the file. Disambiguate that here.
  156. if (CurPtr-1 != CurBuf.end())
  157. return 0; // Just whitespace.
  158. // Otherwise, return end of file.
  159. --CurPtr; // Another call to lex will return EOF again.
  160. return EOF;
  161. }
  162. }
  163. lltok::Kind LLLexer::LexToken() {
  164. while (true) {
  165. TokStart = CurPtr;
  166. int CurChar = getNextChar();
  167. switch (CurChar) {
  168. default:
  169. // Handle letters: [a-zA-Z_]
  170. if (isalpha(static_cast<unsigned char>(CurChar)) || CurChar == '_')
  171. return LexIdentifier();
  172. return lltok::Error;
  173. case EOF: return lltok::Eof;
  174. case 0:
  175. case ' ':
  176. case '\t':
  177. case '\n':
  178. case '\r':
  179. // Ignore whitespace.
  180. continue;
  181. case '+': return LexPositive();
  182. case '@': return LexAt();
  183. case '$': return LexDollar();
  184. case '%': return LexPercent();
  185. case '"': return LexQuote();
  186. case '.':
  187. if (const char *Ptr = isLabelTail(CurPtr)) {
  188. CurPtr = Ptr;
  189. StrVal.assign(TokStart, CurPtr-1);
  190. return lltok::LabelStr;
  191. }
  192. if (CurPtr[0] == '.' && CurPtr[1] == '.') {
  193. CurPtr += 2;
  194. return lltok::dotdotdot;
  195. }
  196. return lltok::Error;
  197. case ';':
  198. SkipLineComment();
  199. continue;
  200. case '!': return LexExclaim();
  201. case '^':
  202. return LexCaret();
  203. case ':':
  204. return lltok::colon;
  205. case '#': return LexHash();
  206. case '0': case '1': case '2': case '3': case '4':
  207. case '5': case '6': case '7': case '8': case '9':
  208. case '-':
  209. return LexDigitOrNegative();
  210. case '=': return lltok::equal;
  211. case '[': return lltok::lsquare;
  212. case ']': return lltok::rsquare;
  213. case '{': return lltok::lbrace;
  214. case '}': return lltok::rbrace;
  215. case '<': return lltok::less;
  216. case '>': return lltok::greater;
  217. case '(': return lltok::lparen;
  218. case ')': return lltok::rparen;
  219. case ',': return lltok::comma;
  220. case '*': return lltok::star;
  221. case '|': return lltok::bar;
  222. }
  223. }
  224. }
  225. void LLLexer::SkipLineComment() {
  226. while (true) {
  227. if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
  228. return;
  229. }
  230. }
  231. /// Lex all tokens that start with an @ character.
  232. /// GlobalVar @\"[^\"]*\"
  233. /// GlobalVar @[-a-zA-Z$._][-a-zA-Z$._0-9]*
  234. /// GlobalVarID @[0-9]+
  235. lltok::Kind LLLexer::LexAt() {
  236. return LexVar(lltok::GlobalVar, lltok::GlobalID);
  237. }
  238. lltok::Kind LLLexer::LexDollar() {
  239. if (const char *Ptr = isLabelTail(TokStart)) {
  240. CurPtr = Ptr;
  241. StrVal.assign(TokStart, CurPtr - 1);
  242. return lltok::LabelStr;
  243. }
  244. // Handle DollarStringConstant: $\"[^\"]*\"
  245. if (CurPtr[0] == '"') {
  246. ++CurPtr;
  247. while (true) {
  248. int CurChar = getNextChar();
  249. if (CurChar == EOF) {
  250. Error("end of file in COMDAT variable name");
  251. return lltok::Error;
  252. }
  253. if (CurChar == '"') {
  254. StrVal.assign(TokStart + 2, CurPtr - 1);
  255. UnEscapeLexed(StrVal);
  256. if (StringRef(StrVal).find_first_of(0) != StringRef::npos) {
  257. Error("Null bytes are not allowed in names");
  258. return lltok::Error;
  259. }
  260. return lltok::ComdatVar;
  261. }
  262. }
  263. }
  264. // Handle ComdatVarName: $[-a-zA-Z$._][-a-zA-Z$._0-9]*
  265. if (ReadVarName())
  266. return lltok::ComdatVar;
  267. return lltok::Error;
  268. }
  269. /// ReadString - Read a string until the closing quote.
  270. lltok::Kind LLLexer::ReadString(lltok::Kind kind) {
  271. const char *Start = CurPtr;
  272. while (true) {
  273. int CurChar = getNextChar();
  274. if (CurChar == EOF) {
  275. Error("end of file in string constant");
  276. return lltok::Error;
  277. }
  278. if (CurChar == '"') {
  279. StrVal.assign(Start, CurPtr-1);
  280. UnEscapeLexed(StrVal);
  281. return kind;
  282. }
  283. }
  284. }
  285. /// ReadVarName - Read the rest of a token containing a variable name.
  286. bool LLLexer::ReadVarName() {
  287. const char *NameStart = CurPtr;
  288. if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
  289. CurPtr[0] == '-' || CurPtr[0] == '$' ||
  290. CurPtr[0] == '.' || CurPtr[0] == '_') {
  291. ++CurPtr;
  292. while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
  293. CurPtr[0] == '-' || CurPtr[0] == '$' ||
  294. CurPtr[0] == '.' || CurPtr[0] == '_')
  295. ++CurPtr;
  296. StrVal.assign(NameStart, CurPtr);
  297. return true;
  298. }
  299. return false;
  300. }
  301. // Lex an ID: [0-9]+. On success, the ID is stored in UIntVal and Token is
  302. // returned, otherwise the Error token is returned.
  303. lltok::Kind LLLexer::LexUIntID(lltok::Kind Token) {
  304. if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
  305. return lltok::Error;
  306. for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
  307. /*empty*/;
  308. uint64_t Val = atoull(TokStart + 1, CurPtr);
  309. if ((unsigned)Val != Val)
  310. Error("invalid value number (too large)!");
  311. UIntVal = unsigned(Val);
  312. return Token;
  313. }
  314. lltok::Kind LLLexer::LexVar(lltok::Kind Var, lltok::Kind VarID) {
  315. // Handle StringConstant: \"[^\"]*\"
  316. if (CurPtr[0] == '"') {
  317. ++CurPtr;
  318. while (true) {
  319. int CurChar = getNextChar();
  320. if (CurChar == EOF) {
  321. Error("end of file in global variable name");
  322. return lltok::Error;
  323. }
  324. if (CurChar == '"') {
  325. StrVal.assign(TokStart+2, CurPtr-1);
  326. UnEscapeLexed(StrVal);
  327. if (StringRef(StrVal).find_first_of(0) != StringRef::npos) {
  328. Error("Null bytes are not allowed in names");
  329. return lltok::Error;
  330. }
  331. return Var;
  332. }
  333. }
  334. }
  335. // Handle VarName: [-a-zA-Z$._][-a-zA-Z$._0-9]*
  336. if (ReadVarName())
  337. return Var;
  338. // Handle VarID: [0-9]+
  339. return LexUIntID(VarID);
  340. }
  341. /// Lex all tokens that start with a % character.
  342. /// LocalVar ::= %\"[^\"]*\"
  343. /// LocalVar ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
  344. /// LocalVarID ::= %[0-9]+
  345. lltok::Kind LLLexer::LexPercent() {
  346. return LexVar(lltok::LocalVar, lltok::LocalVarID);
  347. }
  348. /// Lex all tokens that start with a " character.
  349. /// QuoteLabel "[^"]+":
  350. /// StringConstant "[^"]*"
  351. lltok::Kind LLLexer::LexQuote() {
  352. lltok::Kind kind = ReadString(lltok::StringConstant);
  353. if (kind == lltok::Error || kind == lltok::Eof)
  354. return kind;
  355. if (CurPtr[0] == ':') {
  356. ++CurPtr;
  357. if (StringRef(StrVal).find_first_of(0) != StringRef::npos) {
  358. Error("Null bytes are not allowed in names");
  359. kind = lltok::Error;
  360. } else {
  361. kind = lltok::LabelStr;
  362. }
  363. }
  364. return kind;
  365. }
  366. /// Lex all tokens that start with a ! character.
  367. /// !foo
  368. /// !
  369. lltok::Kind LLLexer::LexExclaim() {
  370. // Lex a metadata name as a MetadataVar.
  371. if (isalpha(static_cast<unsigned char>(CurPtr[0])) ||
  372. CurPtr[0] == '-' || CurPtr[0] == '$' ||
  373. CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\') {
  374. ++CurPtr;
  375. while (isalnum(static_cast<unsigned char>(CurPtr[0])) ||
  376. CurPtr[0] == '-' || CurPtr[0] == '$' ||
  377. CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\')
  378. ++CurPtr;
  379. StrVal.assign(TokStart+1, CurPtr); // Skip !
  380. UnEscapeLexed(StrVal);
  381. return lltok::MetadataVar;
  382. }
  383. return lltok::exclaim;
  384. }
  385. /// Lex all tokens that start with a ^ character.
  386. /// SummaryID ::= ^[0-9]+
  387. lltok::Kind LLLexer::LexCaret() {
  388. // Handle SummaryID: ^[0-9]+
  389. return LexUIntID(lltok::SummaryID);
  390. }
  391. /// Lex all tokens that start with a # character.
  392. /// AttrGrpID ::= #[0-9]+
  393. lltok::Kind LLLexer::LexHash() {
  394. // Handle AttrGrpID: #[0-9]+
  395. return LexUIntID(lltok::AttrGrpID);
  396. }
  397. /// Lex a label, integer type, keyword, or hexadecimal integer constant.
  398. /// Label [-a-zA-Z$._0-9]+:
  399. /// IntegerType i[0-9]+
  400. /// Keyword sdiv, float, ...
  401. /// HexIntConstant [us]0x[0-9A-Fa-f]+
  402. lltok::Kind LLLexer::LexIdentifier() {
  403. const char *StartChar = CurPtr;
  404. const char *IntEnd = CurPtr[-1] == 'i' ? nullptr : StartChar;
  405. const char *KeywordEnd = nullptr;
  406. for (; isLabelChar(*CurPtr); ++CurPtr) {
  407. // If we decide this is an integer, remember the end of the sequence.
  408. if (!IntEnd && !isdigit(static_cast<unsigned char>(*CurPtr)))
  409. IntEnd = CurPtr;
  410. if (!KeywordEnd && !isalnum(static_cast<unsigned char>(*CurPtr)) &&
  411. *CurPtr != '_')
  412. KeywordEnd = CurPtr;
  413. }
  414. // If we stopped due to a colon, unless we were directed to ignore it,
  415. // this really is a label.
  416. if (!IgnoreColonInIdentifiers && *CurPtr == ':') {
  417. StrVal.assign(StartChar-1, CurPtr++);
  418. return lltok::LabelStr;
  419. }
  420. // Otherwise, this wasn't a label. If this was valid as an integer type,
  421. // return it.
  422. if (!IntEnd) IntEnd = CurPtr;
  423. if (IntEnd != StartChar) {
  424. CurPtr = IntEnd;
  425. uint64_t NumBits = atoull(StartChar, CurPtr);
  426. if (NumBits < IntegerType::MIN_INT_BITS ||
  427. NumBits > IntegerType::MAX_INT_BITS) {
  428. Error("bitwidth for integer type out of range!");
  429. return lltok::Error;
  430. }
  431. TyVal = IntegerType::get(Context, NumBits);
  432. return lltok::Type;
  433. }
  434. // Otherwise, this was a letter sequence. See which keyword this is.
  435. if (!KeywordEnd) KeywordEnd = CurPtr;
  436. CurPtr = KeywordEnd;
  437. --StartChar;
  438. StringRef Keyword(StartChar, CurPtr - StartChar);
  439. #define KEYWORD(STR) \
  440. do { \
  441. if (Keyword == #STR) \
  442. return lltok::kw_##STR; \
  443. } while (false)
  444. KEYWORD(true); KEYWORD(false);
  445. KEYWORD(declare); KEYWORD(define);
  446. KEYWORD(global); KEYWORD(constant);
  447. KEYWORD(dso_local);
  448. KEYWORD(dso_preemptable);
  449. KEYWORD(private);
  450. KEYWORD(internal);
  451. KEYWORD(available_externally);
  452. KEYWORD(linkonce);
  453. KEYWORD(linkonce_odr);
  454. KEYWORD(weak); // Use as a linkage, and a modifier for "cmpxchg".
  455. KEYWORD(weak_odr);
  456. KEYWORD(appending);
  457. KEYWORD(dllimport);
  458. KEYWORD(dllexport);
  459. KEYWORD(common);
  460. KEYWORD(default);
  461. KEYWORD(hidden);
  462. KEYWORD(protected);
  463. KEYWORD(unnamed_addr);
  464. KEYWORD(local_unnamed_addr);
  465. KEYWORD(externally_initialized);
  466. KEYWORD(extern_weak);
  467. KEYWORD(external);
  468. KEYWORD(thread_local);
  469. KEYWORD(localdynamic);
  470. KEYWORD(initialexec);
  471. KEYWORD(localexec);
  472. KEYWORD(zeroinitializer);
  473. KEYWORD(undef);
  474. KEYWORD(null);
  475. KEYWORD(none);
  476. KEYWORD(poison);
  477. KEYWORD(to);
  478. KEYWORD(caller);
  479. KEYWORD(within);
  480. KEYWORD(from);
  481. KEYWORD(tail);
  482. KEYWORD(musttail);
  483. KEYWORD(notail);
  484. KEYWORD(target);
  485. KEYWORD(triple);
  486. KEYWORD(source_filename);
  487. KEYWORD(unwind);
  488. KEYWORD(datalayout);
  489. KEYWORD(volatile);
  490. KEYWORD(atomic);
  491. KEYWORD(unordered);
  492. KEYWORD(monotonic);
  493. KEYWORD(acquire);
  494. KEYWORD(release);
  495. KEYWORD(acq_rel);
  496. KEYWORD(seq_cst);
  497. KEYWORD(syncscope);
  498. KEYWORD(nnan);
  499. KEYWORD(ninf);
  500. KEYWORD(nsz);
  501. KEYWORD(arcp);
  502. KEYWORD(contract);
  503. KEYWORD(reassoc);
  504. KEYWORD(afn);
  505. KEYWORD(fast);
  506. KEYWORD(nuw);
  507. KEYWORD(nsw);
  508. KEYWORD(exact);
  509. KEYWORD(inbounds);
  510. KEYWORD(inrange);
  511. KEYWORD(addrspace);
  512. KEYWORD(section);
  513. KEYWORD(partition);
  514. KEYWORD(alias);
  515. KEYWORD(ifunc);
  516. KEYWORD(module);
  517. KEYWORD(asm);
  518. KEYWORD(sideeffect);
  519. KEYWORD(inteldialect);
  520. KEYWORD(gc);
  521. KEYWORD(prefix);
  522. KEYWORD(prologue);
  523. KEYWORD(no_sanitize_address);
  524. KEYWORD(no_sanitize_hwaddress);
  525. KEYWORD(sanitize_address_dyninit);
  526. KEYWORD(ccc);
  527. KEYWORD(fastcc);
  528. KEYWORD(coldcc);
  529. KEYWORD(cfguard_checkcc);
  530. KEYWORD(x86_stdcallcc);
  531. KEYWORD(x86_fastcallcc);
  532. KEYWORD(x86_thiscallcc);
  533. KEYWORD(x86_vectorcallcc);
  534. KEYWORD(arm_apcscc);
  535. KEYWORD(arm_aapcscc);
  536. KEYWORD(arm_aapcs_vfpcc);
  537. KEYWORD(aarch64_vector_pcs);
  538. KEYWORD(aarch64_sve_vector_pcs);
  539. KEYWORD(aarch64_sme_preservemost_from_x0);
  540. KEYWORD(aarch64_sme_preservemost_from_x2);
  541. KEYWORD(msp430_intrcc);
  542. KEYWORD(avr_intrcc);
  543. KEYWORD(avr_signalcc);
  544. KEYWORD(ptx_kernel);
  545. KEYWORD(ptx_device);
  546. KEYWORD(spir_kernel);
  547. KEYWORD(spir_func);
  548. KEYWORD(intel_ocl_bicc);
  549. KEYWORD(x86_64_sysvcc);
  550. KEYWORD(win64cc);
  551. KEYWORD(x86_regcallcc);
  552. KEYWORD(webkit_jscc);
  553. KEYWORD(swiftcc);
  554. KEYWORD(swifttailcc);
  555. KEYWORD(anyregcc);
  556. KEYWORD(preserve_mostcc);
  557. KEYWORD(preserve_allcc);
  558. KEYWORD(ghccc);
  559. KEYWORD(x86_intrcc);
  560. KEYWORD(hhvmcc);
  561. KEYWORD(hhvm_ccc);
  562. KEYWORD(cxx_fast_tlscc);
  563. KEYWORD(amdgpu_vs);
  564. KEYWORD(amdgpu_ls);
  565. KEYWORD(amdgpu_hs);
  566. KEYWORD(amdgpu_es);
  567. KEYWORD(amdgpu_gs);
  568. KEYWORD(amdgpu_ps);
  569. KEYWORD(amdgpu_cs);
  570. KEYWORD(amdgpu_kernel);
  571. KEYWORD(amdgpu_gfx);
  572. KEYWORD(tailcc);
  573. KEYWORD(cc);
  574. KEYWORD(c);
  575. KEYWORD(attributes);
  576. KEYWORD(sync);
  577. KEYWORD(async);
  578. #define GET_ATTR_NAMES
  579. #define ATTRIBUTE_ENUM(ENUM_NAME, DISPLAY_NAME) \
  580. KEYWORD(DISPLAY_NAME);
  581. #include "llvm/IR/Attributes.inc"
  582. KEYWORD(read);
  583. KEYWORD(write);
  584. KEYWORD(readwrite);
  585. KEYWORD(argmem);
  586. KEYWORD(inaccessiblemem);
  587. KEYWORD(argmemonly);
  588. KEYWORD(inaccessiblememonly);
  589. KEYWORD(inaccessiblemem_or_argmemonly);
  590. KEYWORD(type);
  591. KEYWORD(opaque);
  592. KEYWORD(comdat);
  593. // Comdat types
  594. KEYWORD(any);
  595. KEYWORD(exactmatch);
  596. KEYWORD(largest);
  597. KEYWORD(nodeduplicate);
  598. KEYWORD(samesize);
  599. KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
  600. KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
  601. KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
  602. KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
  603. KEYWORD(xchg); KEYWORD(nand); KEYWORD(max); KEYWORD(min); KEYWORD(umax);
  604. KEYWORD(umin); KEYWORD(fmax); KEYWORD(fmin);
  605. KEYWORD(uinc_wrap);
  606. KEYWORD(udec_wrap);
  607. KEYWORD(vscale);
  608. KEYWORD(x);
  609. KEYWORD(blockaddress);
  610. KEYWORD(dso_local_equivalent);
  611. KEYWORD(no_cfi);
  612. // Metadata types.
  613. KEYWORD(distinct);
  614. // Use-list order directives.
  615. KEYWORD(uselistorder);
  616. KEYWORD(uselistorder_bb);
  617. KEYWORD(personality);
  618. KEYWORD(cleanup);
  619. KEYWORD(catch);
  620. KEYWORD(filter);
  621. // Summary index keywords.
  622. KEYWORD(path);
  623. KEYWORD(hash);
  624. KEYWORD(gv);
  625. KEYWORD(guid);
  626. KEYWORD(name);
  627. KEYWORD(summaries);
  628. KEYWORD(flags);
  629. KEYWORD(blockcount);
  630. KEYWORD(linkage);
  631. KEYWORD(visibility);
  632. KEYWORD(notEligibleToImport);
  633. KEYWORD(live);
  634. KEYWORD(dsoLocal);
  635. KEYWORD(canAutoHide);
  636. KEYWORD(function);
  637. KEYWORD(insts);
  638. KEYWORD(funcFlags);
  639. KEYWORD(readNone);
  640. KEYWORD(readOnly);
  641. KEYWORD(noRecurse);
  642. KEYWORD(returnDoesNotAlias);
  643. KEYWORD(noInline);
  644. KEYWORD(alwaysInline);
  645. KEYWORD(noUnwind);
  646. KEYWORD(mayThrow);
  647. KEYWORD(hasUnknownCall);
  648. KEYWORD(mustBeUnreachable);
  649. KEYWORD(calls);
  650. KEYWORD(callee);
  651. KEYWORD(params);
  652. KEYWORD(param);
  653. KEYWORD(hotness);
  654. KEYWORD(unknown);
  655. KEYWORD(critical);
  656. KEYWORD(relbf);
  657. KEYWORD(variable);
  658. KEYWORD(vTableFuncs);
  659. KEYWORD(virtFunc);
  660. KEYWORD(aliasee);
  661. KEYWORD(refs);
  662. KEYWORD(typeIdInfo);
  663. KEYWORD(typeTests);
  664. KEYWORD(typeTestAssumeVCalls);
  665. KEYWORD(typeCheckedLoadVCalls);
  666. KEYWORD(typeTestAssumeConstVCalls);
  667. KEYWORD(typeCheckedLoadConstVCalls);
  668. KEYWORD(vFuncId);
  669. KEYWORD(offset);
  670. KEYWORD(args);
  671. KEYWORD(typeid);
  672. KEYWORD(typeidCompatibleVTable);
  673. KEYWORD(summary);
  674. KEYWORD(typeTestRes);
  675. KEYWORD(kind);
  676. KEYWORD(unsat);
  677. KEYWORD(byteArray);
  678. KEYWORD(inline);
  679. KEYWORD(single);
  680. KEYWORD(allOnes);
  681. KEYWORD(sizeM1BitWidth);
  682. KEYWORD(alignLog2);
  683. KEYWORD(sizeM1);
  684. KEYWORD(bitMask);
  685. KEYWORD(inlineBits);
  686. KEYWORD(vcall_visibility);
  687. KEYWORD(wpdResolutions);
  688. KEYWORD(wpdRes);
  689. KEYWORD(indir);
  690. KEYWORD(singleImpl);
  691. KEYWORD(branchFunnel);
  692. KEYWORD(singleImplName);
  693. KEYWORD(resByArg);
  694. KEYWORD(byArg);
  695. KEYWORD(uniformRetVal);
  696. KEYWORD(uniqueRetVal);
  697. KEYWORD(virtualConstProp);
  698. KEYWORD(info);
  699. KEYWORD(byte);
  700. KEYWORD(bit);
  701. KEYWORD(varFlags);
  702. KEYWORD(callsites);
  703. KEYWORD(clones);
  704. KEYWORD(stackIds);
  705. KEYWORD(allocs);
  706. KEYWORD(versions);
  707. KEYWORD(memProf);
  708. KEYWORD(notcold);
  709. KEYWORD(notcoldandcold);
  710. #undef KEYWORD
  711. // Keywords for types.
  712. #define TYPEKEYWORD(STR, LLVMTY) \
  713. do { \
  714. if (Keyword == STR) { \
  715. TyVal = LLVMTY; \
  716. return lltok::Type; \
  717. } \
  718. } while (false)
  719. TYPEKEYWORD("void", Type::getVoidTy(Context));
  720. TYPEKEYWORD("half", Type::getHalfTy(Context));
  721. TYPEKEYWORD("bfloat", Type::getBFloatTy(Context));
  722. TYPEKEYWORD("float", Type::getFloatTy(Context));
  723. TYPEKEYWORD("double", Type::getDoubleTy(Context));
  724. TYPEKEYWORD("x86_fp80", Type::getX86_FP80Ty(Context));
  725. TYPEKEYWORD("fp128", Type::getFP128Ty(Context));
  726. TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
  727. TYPEKEYWORD("label", Type::getLabelTy(Context));
  728. TYPEKEYWORD("metadata", Type::getMetadataTy(Context));
  729. TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context));
  730. TYPEKEYWORD("x86_amx", Type::getX86_AMXTy(Context));
  731. TYPEKEYWORD("token", Type::getTokenTy(Context));
  732. if (Keyword == "ptr") {
  733. if (Context.supportsTypedPointers()) {
  734. Warning("ptr type is only supported in -opaque-pointers mode");
  735. return lltok::Error;
  736. }
  737. TyVal = PointerType::getUnqual(Context);
  738. return lltok::Type;
  739. }
  740. #undef TYPEKEYWORD
  741. // Keywords for instructions.
  742. #define INSTKEYWORD(STR, Enum) \
  743. do { \
  744. if (Keyword == #STR) { \
  745. UIntVal = Instruction::Enum; \
  746. return lltok::kw_##STR; \
  747. } \
  748. } while (false)
  749. INSTKEYWORD(fneg, FNeg);
  750. INSTKEYWORD(add, Add); INSTKEYWORD(fadd, FAdd);
  751. INSTKEYWORD(sub, Sub); INSTKEYWORD(fsub, FSub);
  752. INSTKEYWORD(mul, Mul); INSTKEYWORD(fmul, FMul);
  753. INSTKEYWORD(udiv, UDiv); INSTKEYWORD(sdiv, SDiv); INSTKEYWORD(fdiv, FDiv);
  754. INSTKEYWORD(urem, URem); INSTKEYWORD(srem, SRem); INSTKEYWORD(frem, FRem);
  755. INSTKEYWORD(shl, Shl); INSTKEYWORD(lshr, LShr); INSTKEYWORD(ashr, AShr);
  756. INSTKEYWORD(and, And); INSTKEYWORD(or, Or); INSTKEYWORD(xor, Xor);
  757. INSTKEYWORD(icmp, ICmp); INSTKEYWORD(fcmp, FCmp);
  758. INSTKEYWORD(phi, PHI);
  759. INSTKEYWORD(call, Call);
  760. INSTKEYWORD(trunc, Trunc);
  761. INSTKEYWORD(zext, ZExt);
  762. INSTKEYWORD(sext, SExt);
  763. INSTKEYWORD(fptrunc, FPTrunc);
  764. INSTKEYWORD(fpext, FPExt);
  765. INSTKEYWORD(uitofp, UIToFP);
  766. INSTKEYWORD(sitofp, SIToFP);
  767. INSTKEYWORD(fptoui, FPToUI);
  768. INSTKEYWORD(fptosi, FPToSI);
  769. INSTKEYWORD(inttoptr, IntToPtr);
  770. INSTKEYWORD(ptrtoint, PtrToInt);
  771. INSTKEYWORD(bitcast, BitCast);
  772. INSTKEYWORD(addrspacecast, AddrSpaceCast);
  773. INSTKEYWORD(select, Select);
  774. INSTKEYWORD(va_arg, VAArg);
  775. INSTKEYWORD(ret, Ret);
  776. INSTKEYWORD(br, Br);
  777. INSTKEYWORD(switch, Switch);
  778. INSTKEYWORD(indirectbr, IndirectBr);
  779. INSTKEYWORD(invoke, Invoke);
  780. INSTKEYWORD(resume, Resume);
  781. INSTKEYWORD(unreachable, Unreachable);
  782. INSTKEYWORD(callbr, CallBr);
  783. INSTKEYWORD(alloca, Alloca);
  784. INSTKEYWORD(load, Load);
  785. INSTKEYWORD(store, Store);
  786. INSTKEYWORD(cmpxchg, AtomicCmpXchg);
  787. INSTKEYWORD(atomicrmw, AtomicRMW);
  788. INSTKEYWORD(fence, Fence);
  789. INSTKEYWORD(getelementptr, GetElementPtr);
  790. INSTKEYWORD(extractelement, ExtractElement);
  791. INSTKEYWORD(insertelement, InsertElement);
  792. INSTKEYWORD(shufflevector, ShuffleVector);
  793. INSTKEYWORD(extractvalue, ExtractValue);
  794. INSTKEYWORD(insertvalue, InsertValue);
  795. INSTKEYWORD(landingpad, LandingPad);
  796. INSTKEYWORD(cleanupret, CleanupRet);
  797. INSTKEYWORD(catchret, CatchRet);
  798. INSTKEYWORD(catchswitch, CatchSwitch);
  799. INSTKEYWORD(catchpad, CatchPad);
  800. INSTKEYWORD(cleanuppad, CleanupPad);
  801. INSTKEYWORD(freeze, Freeze);
  802. #undef INSTKEYWORD
  803. #define DWKEYWORD(TYPE, TOKEN) \
  804. do { \
  805. if (Keyword.startswith("DW_" #TYPE "_")) { \
  806. StrVal.assign(Keyword.begin(), Keyword.end()); \
  807. return lltok::TOKEN; \
  808. } \
  809. } while (false)
  810. DWKEYWORD(TAG, DwarfTag);
  811. DWKEYWORD(ATE, DwarfAttEncoding);
  812. DWKEYWORD(VIRTUALITY, DwarfVirtuality);
  813. DWKEYWORD(LANG, DwarfLang);
  814. DWKEYWORD(CC, DwarfCC);
  815. DWKEYWORD(OP, DwarfOp);
  816. DWKEYWORD(MACINFO, DwarfMacinfo);
  817. #undef DWKEYWORD
  818. if (Keyword.startswith("DIFlag")) {
  819. StrVal.assign(Keyword.begin(), Keyword.end());
  820. return lltok::DIFlag;
  821. }
  822. if (Keyword.startswith("DISPFlag")) {
  823. StrVal.assign(Keyword.begin(), Keyword.end());
  824. return lltok::DISPFlag;
  825. }
  826. if (Keyword.startswith("CSK_")) {
  827. StrVal.assign(Keyword.begin(), Keyword.end());
  828. return lltok::ChecksumKind;
  829. }
  830. if (Keyword == "NoDebug" || Keyword == "FullDebug" ||
  831. Keyword == "LineTablesOnly" || Keyword == "DebugDirectivesOnly") {
  832. StrVal.assign(Keyword.begin(), Keyword.end());
  833. return lltok::EmissionKind;
  834. }
  835. if (Keyword == "GNU" || Keyword == "None" || Keyword == "Default") {
  836. StrVal.assign(Keyword.begin(), Keyword.end());
  837. return lltok::NameTableKind;
  838. }
  839. // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
  840. // the CFE to avoid forcing it to deal with 64-bit numbers.
  841. if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
  842. TokStart[1] == '0' && TokStart[2] == 'x' &&
  843. isxdigit(static_cast<unsigned char>(TokStart[3]))) {
  844. int len = CurPtr-TokStart-3;
  845. uint32_t bits = len * 4;
  846. StringRef HexStr(TokStart + 3, len);
  847. if (!all_of(HexStr, isxdigit)) {
  848. // Bad token, return it as an error.
  849. CurPtr = TokStart+3;
  850. return lltok::Error;
  851. }
  852. APInt Tmp(bits, HexStr, 16);
  853. uint32_t activeBits = Tmp.getActiveBits();
  854. if (activeBits > 0 && activeBits < bits)
  855. Tmp = Tmp.trunc(activeBits);
  856. APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
  857. return lltok::APSInt;
  858. }
  859. // If this is "cc1234", return this as just "cc".
  860. if (TokStart[0] == 'c' && TokStart[1] == 'c') {
  861. CurPtr = TokStart+2;
  862. return lltok::kw_cc;
  863. }
  864. // Finally, if this isn't known, return an error.
  865. CurPtr = TokStart+1;
  866. return lltok::Error;
  867. }
  868. /// Lex all tokens that start with a 0x prefix, knowing they match and are not
  869. /// labels.
  870. /// HexFPConstant 0x[0-9A-Fa-f]+
  871. /// HexFP80Constant 0xK[0-9A-Fa-f]+
  872. /// HexFP128Constant 0xL[0-9A-Fa-f]+
  873. /// HexPPC128Constant 0xM[0-9A-Fa-f]+
  874. /// HexHalfConstant 0xH[0-9A-Fa-f]+
  875. /// HexBFloatConstant 0xR[0-9A-Fa-f]+
  876. lltok::Kind LLLexer::Lex0x() {
  877. CurPtr = TokStart + 2;
  878. char Kind;
  879. if ((CurPtr[0] >= 'K' && CurPtr[0] <= 'M') || CurPtr[0] == 'H' ||
  880. CurPtr[0] == 'R') {
  881. Kind = *CurPtr++;
  882. } else {
  883. Kind = 'J';
  884. }
  885. if (!isxdigit(static_cast<unsigned char>(CurPtr[0]))) {
  886. // Bad token, return it as an error.
  887. CurPtr = TokStart+1;
  888. return lltok::Error;
  889. }
  890. while (isxdigit(static_cast<unsigned char>(CurPtr[0])))
  891. ++CurPtr;
  892. if (Kind == 'J') {
  893. // HexFPConstant - Floating point constant represented in IEEE format as a
  894. // hexadecimal number for when exponential notation is not precise enough.
  895. // Half, BFloat, Float, and double only.
  896. APFloatVal = APFloat(APFloat::IEEEdouble(),
  897. APInt(64, HexIntToVal(TokStart + 2, CurPtr)));
  898. return lltok::APFloat;
  899. }
  900. uint64_t Pair[2];
  901. switch (Kind) {
  902. default: llvm_unreachable("Unknown kind!");
  903. case 'K':
  904. // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
  905. FP80HexToIntPair(TokStart+3, CurPtr, Pair);
  906. APFloatVal = APFloat(APFloat::x87DoubleExtended(), APInt(80, Pair));
  907. return lltok::APFloat;
  908. case 'L':
  909. // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
  910. HexToIntPair(TokStart+3, CurPtr, Pair);
  911. APFloatVal = APFloat(APFloat::IEEEquad(), APInt(128, Pair));
  912. return lltok::APFloat;
  913. case 'M':
  914. // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
  915. HexToIntPair(TokStart+3, CurPtr, Pair);
  916. APFloatVal = APFloat(APFloat::PPCDoubleDouble(), APInt(128, Pair));
  917. return lltok::APFloat;
  918. case 'H':
  919. APFloatVal = APFloat(APFloat::IEEEhalf(),
  920. APInt(16,HexIntToVal(TokStart+3, CurPtr)));
  921. return lltok::APFloat;
  922. case 'R':
  923. // Brain floating point
  924. APFloatVal = APFloat(APFloat::BFloat(),
  925. APInt(16, HexIntToVal(TokStart + 3, CurPtr)));
  926. return lltok::APFloat;
  927. }
  928. }
  929. /// Lex tokens for a label or a numeric constant, possibly starting with -.
  930. /// Label [-a-zA-Z$._0-9]+:
  931. /// NInteger -[0-9]+
  932. /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
  933. /// PInteger [0-9]+
  934. /// HexFPConstant 0x[0-9A-Fa-f]+
  935. /// HexFP80Constant 0xK[0-9A-Fa-f]+
  936. /// HexFP128Constant 0xL[0-9A-Fa-f]+
  937. /// HexPPC128Constant 0xM[0-9A-Fa-f]+
  938. lltok::Kind LLLexer::LexDigitOrNegative() {
  939. // If the letter after the negative is not a number, this is probably a label.
  940. if (!isdigit(static_cast<unsigned char>(TokStart[0])) &&
  941. !isdigit(static_cast<unsigned char>(CurPtr[0]))) {
  942. // Okay, this is not a number after the -, it's probably a label.
  943. if (const char *End = isLabelTail(CurPtr)) {
  944. StrVal.assign(TokStart, End-1);
  945. CurPtr = End;
  946. return lltok::LabelStr;
  947. }
  948. return lltok::Error;
  949. }
  950. // At this point, it is either a label, int or fp constant.
  951. // Skip digits, we have at least one.
  952. for (; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
  953. /*empty*/;
  954. // Check if this is a fully-numeric label:
  955. if (isdigit(TokStart[0]) && CurPtr[0] == ':') {
  956. uint64_t Val = atoull(TokStart, CurPtr);
  957. ++CurPtr; // Skip the colon.
  958. if ((unsigned)Val != Val)
  959. Error("invalid value number (too large)!");
  960. UIntVal = unsigned(Val);
  961. return lltok::LabelID;
  962. }
  963. // Check to see if this really is a string label, e.g. "-1:".
  964. if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
  965. if (const char *End = isLabelTail(CurPtr)) {
  966. StrVal.assign(TokStart, End-1);
  967. CurPtr = End;
  968. return lltok::LabelStr;
  969. }
  970. }
  971. // If the next character is a '.', then it is a fp value, otherwise its
  972. // integer.
  973. if (CurPtr[0] != '.') {
  974. if (TokStart[0] == '0' && TokStart[1] == 'x')
  975. return Lex0x();
  976. APSIntVal = APSInt(StringRef(TokStart, CurPtr - TokStart));
  977. return lltok::APSInt;
  978. }
  979. ++CurPtr;
  980. // Skip over [0-9]*([eE][-+]?[0-9]+)?
  981. while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
  982. if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
  983. if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
  984. ((CurPtr[1] == '-' || CurPtr[1] == '+') &&
  985. isdigit(static_cast<unsigned char>(CurPtr[2])))) {
  986. CurPtr += 2;
  987. while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
  988. }
  989. }
  990. APFloatVal = APFloat(APFloat::IEEEdouble(),
  991. StringRef(TokStart, CurPtr - TokStart));
  992. return lltok::APFloat;
  993. }
  994. /// Lex a floating point constant starting with +.
  995. /// FPConstant [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
  996. lltok::Kind LLLexer::LexPositive() {
  997. // If the letter after the negative is a number, this is probably not a
  998. // label.
  999. if (!isdigit(static_cast<unsigned char>(CurPtr[0])))
  1000. return lltok::Error;
  1001. // Skip digits.
  1002. for (++CurPtr; isdigit(static_cast<unsigned char>(CurPtr[0])); ++CurPtr)
  1003. /*empty*/;
  1004. // At this point, we need a '.'.
  1005. if (CurPtr[0] != '.') {
  1006. CurPtr = TokStart+1;
  1007. return lltok::Error;
  1008. }
  1009. ++CurPtr;
  1010. // Skip over [0-9]*([eE][-+]?[0-9]+)?
  1011. while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
  1012. if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
  1013. if (isdigit(static_cast<unsigned char>(CurPtr[1])) ||
  1014. ((CurPtr[1] == '-' || CurPtr[1] == '+') &&
  1015. isdigit(static_cast<unsigned char>(CurPtr[2])))) {
  1016. CurPtr += 2;
  1017. while (isdigit(static_cast<unsigned char>(CurPtr[0]))) ++CurPtr;
  1018. }
  1019. }
  1020. APFloatVal = APFloat(APFloat::IEEEdouble(),
  1021. StringRef(TokStart, CurPtr - TokStart));
  1022. return lltok::APFloat;
  1023. }