LLLexer.cpp revision ab39afa9d9b99c61842c8e3d0eb706bd16efdcf3
18e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===- LLLexer.cpp - Lexer for .ll Files ----------------------------------===//
28e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
38e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//                     The LLVM Compiler Infrastructure
48e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
54ee451de366474b9c228b4e5fa573795a715216dChris Lattner// This file is distributed under the University of Illinois Open Source
64ee451de366474b9c228b4e5fa573795a715216dChris Lattner// License. See LICENSE.TXT for details.
78e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
88e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
98e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
108e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// Implement the Lexer for .ll files.
118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
148e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner#include "LLLexer.h"
157336f7febb5170b374a4cbffee273ad82ff8a1a3Jordan Rose#include "llvm/ADT/StringExtras.h"
16d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/ADT/Twine.h"
17d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/Assembly/Parser.h"
180b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/DerivedTypes.h"
190b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/Instruction.h"
200b8c9a80f20772c3793201ab5b251d3520b9cea3Chandler Carruth#include "llvm/IR/LLVMContext.h"
21c25e7581b9b8088910da31702d4ca21c4734c6d7Torok Edwin#include "llvm/Support/ErrorHandling.h"
22d185f64f828ce1f8b476807a4a1345c0c53d8213Chris Lattner#include "llvm/Support/MathExtras.h"
23d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/Support/MemoryBuffer.h"
2492bcb426c3e4503c99324afd4ed0a73521711a56Chris Lattner#include "llvm/Support/SourceMgr.h"
25df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#include "llvm/Support/raw_ostream.h"
26476b242fe7a61e5f9ac6214b0bc5c680d24f152eNick Lewycky#include <cctype>
27bcef7df6ec9aba7c5009a4d33944f80227563665Duncan Sands#include <cstdio>
28a896176973d59d8e22514b363d31e8d1becf185eChris Lattner#include <cstdlib>
295679d18c54ef46170e46f51bf471bb334f2b6525Misha Brukman#include <cstring>
308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerusing namespace llvm;
318e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
32d1e1703c39742f3c9fc3d27a442ff59bbdbfb5aaBenjamin Kramerbool LLLexer::Error(LocTy ErrorLoc, const Twine &Msg) const {
333f2d5f60b31fd057c10f77b2e607b23a8c94f6d3Chris Lattner  ErrorInfo = SM.GetMessage(ErrorLoc, SourceMgr::DK_Error, Msg);
34df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return true;
35df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner}
36df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
378e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
388e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// Helper functions.
398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
418e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// atoull - Convert an ascii string of decimal digits into the unsigned long
428e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// long representation... this does not have to do input error checking,
438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// because we know that the input will be matched by a suitable regex...
448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//
45df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattneruint64_t LLLexer::atoull(const char *Buffer, const char *End) {
468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  uint64_t Result = 0;
478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (; Buffer != End; Buffer++) {
488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t OldRes = Result;
498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Result *= 10;
508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Result += *Buffer-'0';
518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (Result < OldRes) {  // Uh, oh, overflow detected!!!
52df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("constant bigger than 64 bits detected!");
538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return 0;
548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return Result;
578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
588e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
59df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattneruint64_t LLLexer::HexIntToVal(const char *Buffer, const char *End) {
608e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  uint64_t Result = 0;
618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (; Buffer != End; ++Buffer) {
628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t OldRes = Result;
638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Result *= 16;
647336f7febb5170b374a4cbffee273ad82ff8a1a3Jordan Rose    Result += hexDigitValue(*Buffer);
652c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (Result < OldRes) {   // Uh, oh, overflow detected!!!
67df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("constant bigger than 64 bits detected!");
688e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return 0;
698e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
708e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
718e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return Result;
728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
738e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
74df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnervoid LLLexer::HexToIntPair(const char *Buffer, const char *End,
75df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner                           uint64_t Pair[2]) {
768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  Pair[0] = 0;
778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (int i=0; i<16; i++, Buffer++) {
788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    assert(Buffer != End);
798e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Pair[0] *= 16;
807336f7febb5170b374a4cbffee273ad82ff8a1a3Jordan Rose    Pair[0] += hexDigitValue(*Buffer);
818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
828e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  Pair[1] = 0;
838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (int i=0; i<16 && Buffer != End; i++, Buffer++) {
848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Pair[1] *= 16;
857336f7febb5170b374a4cbffee273ad82ff8a1a3Jordan Rose    Pair[1] += hexDigitValue(*Buffer);
868e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
87d343c6b70ec03b357d42e47ce7c00b3c3cb78efdChris Lattner  if (Buffer != End)
88df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    Error("constant bigger than 128 bits detected!");
898e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
911b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen/// FP80HexToIntPair - translate an 80 bit FP80 number (20 hexits) into
921b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen/// { low64, high16 } as usual for an APInt.
931b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesenvoid LLLexer::FP80HexToIntPair(const char *Buffer, const char *End,
941b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen                           uint64_t Pair[2]) {
951b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  Pair[1] = 0;
961b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  for (int i=0; i<4 && Buffer != End; i++, Buffer++) {
971b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    assert(Buffer != End);
981b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    Pair[1] *= 16;
997336f7febb5170b374a4cbffee273ad82ff8a1a3Jordan Rose    Pair[1] += hexDigitValue(*Buffer);
1001b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  }
1011b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  Pair[0] = 0;
1021b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  for (int i=0; i<16; i++, Buffer++) {
1031b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    Pair[0] *= 16;
1047336f7febb5170b374a4cbffee273ad82ff8a1a3Jordan Rose    Pair[0] += hexDigitValue(*Buffer);
1051b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  }
1061b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen  if (Buffer != End)
1071b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    Error("constant bigger than 128 bits detected!");
1081b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen}
1091b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen
1108e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// UnEscapeLexed - Run through the specified buffer and change \xx codes to the
1118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// appropriate character.
1128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstatic void UnEscapeLexed(std::string &Str) {
1138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (Str.empty()) return;
1142c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
1158e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  char *Buffer = &Str[0], *EndBuffer = Buffer+Str.size();
1168e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  char *BOut = Buffer;
1178e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (char *BIn = Buffer; BIn != EndBuffer; ) {
1188e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (BIn[0] == '\\') {
1198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (BIn < EndBuffer-1 && BIn[1] == '\\') {
1208e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        *BOut++ = '\\'; // Two \ becomes one
1218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        BIn += 2;
1228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      } else if (BIn < EndBuffer-2 && isxdigit(BIn[1]) && isxdigit(BIn[2])) {
1237336f7febb5170b374a4cbffee273ad82ff8a1a3Jordan Rose        *BOut = hexDigitValue(BIn[1]) * 16 + hexDigitValue(BIn[2]);
1248e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        BIn += 3;                           // Skip over handled chars
1258e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        ++BOut;
1268e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      } else {
1278e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        *BOut++ = *BIn++;
1288e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      }
1298e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    } else {
1308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      *BOut++ = *BIn++;
1318e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
1328e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
1338e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  Str.resize(BOut-Buffer);
1348e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1358e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// isLabelChar - Return true for [-a-zA-Z$._0-9].
1378e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstatic bool isLabelChar(char C) {
1388e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return isalnum(C) || C == '-' || C == '$' || C == '.' || C == '_';
1398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1418e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1428e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// isLabelTail - Return true if this pointer points to a valid end of a label.
1438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstatic const char *isLabelTail(const char *CurPtr) {
1448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (1) {
1458e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr[0] == ':') return CurPtr+1;
1468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (!isLabelChar(CurPtr[0])) return 0;
1478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
1488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
1498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1528e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
1548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner// Lexer definition.
1558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner//===----------------------------------------------------------------------===//
1568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
157ff6c91efcf62d1cb99343fdcb2de6271520a1981Owen AndersonLLLexer::LLLexer(MemoryBuffer *StartBuf, SourceMgr &sm, SMDiagnostic &Err,
158ff6c91efcf62d1cb99343fdcb2de6271520a1981Owen Anderson                 LLVMContext &C)
159ff6c91efcf62d1cb99343fdcb2de6271520a1981Owen Anderson  : CurBuf(StartBuf), ErrorInfo(Err), SM(sm), Context(C), APFloatVal(0.0) {
1608e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  CurPtr = CurBuf->getBufferStart();
1618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerstd::string LLLexer::getFilename() const {
1648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  return CurBuf->getBufferIdentifier();
1658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1678e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnerint LLLexer::getNextChar() {
1688e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  char CurChar = *CurPtr++;
1698e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  switch (CurChar) {
1708e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  default: return (unsigned char)CurChar;
1718e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 0:
1728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // A nul character in the stream is either the end of the current buffer or
1738e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // a random nul in the file.  Disambiguate that here.
1748e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr-1 != CurBuf->getBufferEnd())
1758e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return 0;  // Just whitespace.
1762c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
1778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Otherwise, return end of file.
1782c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    --CurPtr;  // Another call to lex will return EOF again.
1798e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return EOF;
1802c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  }
1818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
1828e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
1838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
184df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexToken() {
1858e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  TokStart = CurPtr;
1862c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
1878e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  int CurChar = getNextChar();
1888e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  switch (CurChar) {
1898e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  default:
1908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Handle letters: [a-zA-Z_]
1918e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (isalpha(CurChar) || CurChar == '_')
1928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return LexIdentifier();
1932c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
194df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
195df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case EOF: return lltok::Eof;
1968e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 0:
1978e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case ' ':
1988e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '\t':
1998e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '\n':
2008e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '\r':
2018e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Ignore whitespace.
2028e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return LexToken();
2038e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '+': return LexPositive();
2048e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '@': return LexAt();
2058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '%': return LexPercent();
2068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '"': return LexQuote();
2078e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '.':
2088e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (const char *Ptr = isLabelTail(CurPtr)) {
2098e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr = Ptr;
210df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart, CurPtr-1);
211df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::LabelStr;
2128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
2138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr[0] == '.' && CurPtr[1] == '.') {
2148e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr += 2;
215df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::dotdotdot;
2168e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
217df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
2188e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '$':
2198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (const char *Ptr = isLabelTail(CurPtr)) {
2208e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr = Ptr;
221df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart, CurPtr-1);
222df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::LabelStr;
2238e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
224df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
2258e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case ';':
2268e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    SkipLineComment();
2278e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return LexToken();
228e434d277ca5183eeb6f881000732dcf4c8edd52eChris Lattner  case '!': return LexExclaim();
22995ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  case '#': return LexHash();
2308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '0': case '1': case '2': case '3': case '4':
2318e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case '5': case '6': case '7': case '8': case '9':
2322c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  case '-':
2338e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    return LexDigitOrNegative();
234df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '=': return lltok::equal;
235df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '[': return lltok::lsquare;
236df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case ']': return lltok::rsquare;
237df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '{': return lltok::lbrace;
238df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '}': return lltok::rbrace;
239df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '<': return lltok::less;
240df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '>': return lltok::greater;
241df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '(': return lltok::lparen;
242df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case ')': return lltok::rparen;
243df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case ',': return lltok::comma;
244df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '*': return lltok::star;
245df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  case '\\': return lltok::backslash;
2468e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
2478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
2488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
2498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattnervoid LLLexer::SkipLineComment() {
2508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (1) {
2518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (CurPtr[0] == '\n' || CurPtr[0] == '\r' || getNextChar() == EOF)
2528e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return;
2538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
2548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
2558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
2568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexAt - Lex all tokens that start with an @ character:
257df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   GlobalVar   @\"[^\"]*\"
258df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   GlobalVar   @[-a-zA-Z$._][-a-zA-Z$._0-9]*
259df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   GlobalVarID @[0-9]+
260df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexAt() {
2618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle AtStringConstant: @\"[^\"]*\"
2628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] == '"') {
2638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
2642c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    while (1) {
2668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      int CurChar = getNextChar();
2672c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2682c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling      if (CurChar == EOF) {
269df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        Error("end of file in global variable name");
270df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        return lltok::Error;
2718e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      }
2728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (CurChar == '"') {
273df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        StrVal.assign(TokStart+2, CurPtr-1);
274df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        UnEscapeLexed(StrVal);
275df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner        return lltok::GlobalVar;
2768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      }
2778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
2788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
2792c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2808e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle GlobalVarName: @[-a-zA-Z$._][-a-zA-Z$._0-9]*
2819fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  if (ReadVarName())
282df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::GlobalVar;
2832c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle GlobalVarID: @[0-9]+
2858e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (isdigit(CurPtr[0])) {
2862c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
2872c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling      /*empty*/;
2882c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
2898e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t Val = atoull(TokStart+1, CurPtr);
2908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if ((unsigned)Val != Val)
291df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("invalid value number (too large)!");
292df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    UIntVal = unsigned(Val);
293df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::GlobalID;
2948e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
2952c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
296df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::Error;
2978e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
2988e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
2999fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky/// ReadString - Read a string until the closing quote.
3009fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewyckylltok::Kind LLLexer::ReadString(lltok::Kind kind) {
3019fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  const char *Start = CurPtr;
3029fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  while (1) {
3039fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    int CurChar = getNextChar();
3049fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky
3059fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    if (CurChar == EOF) {
3069fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky      Error("end of file in string constant");
3079fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky      return lltok::Error;
3089fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    }
3099fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    if (CurChar == '"') {
3109fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky      StrVal.assign(Start, CurPtr-1);
3119fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky      UnEscapeLexed(StrVal);
3129fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky      return kind;
3139fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    }
3149fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  }
3159fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky}
3169fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky
3179fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky/// ReadVarName - Read the rest of a token containing a variable name.
3189fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewyckybool LLLexer::ReadVarName() {
3199fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  const char *NameStart = CurPtr;
3209fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
3219fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky      CurPtr[0] == '.' || CurPtr[0] == '_') {
3229fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    ++CurPtr;
3239fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
3249fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky           CurPtr[0] == '.' || CurPtr[0] == '_')
3259fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky      ++CurPtr;
3269fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky
3279fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    StrVal.assign(NameStart, CurPtr);
3289fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    return true;
3299fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  }
3309fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  return false;
3319fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky}
3328e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
3338e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexPercent - Lex all tokens that start with a % character:
334df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   LocalVar   ::= %\"[^\"]*\"
335df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   LocalVar   ::= %[-a-zA-Z$._][-a-zA-Z$._0-9]*
336df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner///   LocalVarID ::= %[0-9]+
337df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexPercent() {
338df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  // Handle LocalVarName: %\"[^\"]*\"
3398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] == '"') {
3408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
3419fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    return ReadString(lltok::LocalVar);
3428e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3432c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle LocalVarName: %[-a-zA-Z$._][-a-zA-Z$._0-9]*
3459fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  if (ReadVarName())
346df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::LocalVar;
3472c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Handle LocalVarID: %[0-9]+
3498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (isdigit(CurPtr[0])) {
3502c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
3512c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling      /*empty*/;
3522c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t Val = atoull(TokStart+1, CurPtr);
3548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if ((unsigned)Val != Val)
355df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("invalid value number (too large)!");
356df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    UIntVal = unsigned(Val);
357df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::LocalVarID;
3588e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3592c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
360df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::Error;
3618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
3628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
3638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexQuote - Lex all tokens that start with a " character:
3648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///   QuoteLabel        "[^"]+":
3658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///   StringConstant    "[^"]*"
366df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexQuote() {
3679fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  lltok::Kind kind = ReadString(lltok::StringConstant);
3689fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  if (kind == lltok::Error || kind == lltok::Eof)
3699fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    return kind;
3702c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
3719fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  if (CurPtr[0] == ':') {
3728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
3739fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky    kind = lltok::LabelStr;
3748e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
3759fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky
3769fa89334f1045b56e8ae409004e119d47ef17ec7Nick Lewycky  return kind;
3778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
3788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
379e434d277ca5183eeb6f881000732dcf4c8edd52eChris Lattner/// LexExclaim:
380eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel///    !foo
3811d92831759620a2e5ce4f5a3088c0a1a77a48c8fChris Lattner///    !
382e434d277ca5183eeb6f881000732dcf4c8edd52eChris Lattnerlltok::Kind LLLexer::LexExclaim() {
3831d92831759620a2e5ce4f5a3088c0a1a77a48c8fChris Lattner  // Lex a metadata name as a MetadataVar.
3849100a78bce4e1d34d8ffd5efa2cc79ed864dd1c0Nick Lewycky  if (isalpha(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
3859100a78bce4e1d34d8ffd5efa2cc79ed864dd1c0Nick Lewycky      CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\') {
386eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel    ++CurPtr;
387eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel    while (isalnum(CurPtr[0]) || CurPtr[0] == '-' || CurPtr[0] == '$' ||
3889100a78bce4e1d34d8ffd5efa2cc79ed864dd1c0Nick Lewycky           CurPtr[0] == '.' || CurPtr[0] == '_' || CurPtr[0] == '\\')
389eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel      ++CurPtr;
3908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
391eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel    StrVal.assign(TokStart+1, CurPtr);   // Skip !
3929100a78bce4e1d34d8ffd5efa2cc79ed864dd1c0Nick Lewycky    UnEscapeLexed(StrVal);
3931d92831759620a2e5ce4f5a3088c0a1a77a48c8fChris Lattner    return lltok::MetadataVar;
394eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel  }
395e434d277ca5183eeb6f881000732dcf4c8edd52eChris Lattner  return lltok::exclaim;
396eff2ab61b5d411fe64ba601d402b7c549644b590Devang Patel}
39715c13d3e63d7745bccad74d547af4e3482193eaaMichael Ilseman
39895ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling/// LexHash - Lex all tokens that start with a # character:
39995ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling///    AttrGrpID ::= #[0-9]+
40095ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendlinglltok::Kind LLLexer::LexHash() {
40195ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  // Handle AttrGrpID: #[0-9]+
40295ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  if (isdigit(CurPtr[0])) {
40395ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling    for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
40495ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling      /*empty*/;
40595ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling
40695ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling    uint64_t Val = atoull(TokStart+1, CurPtr);
40795ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling    if ((unsigned)Val != Val)
40895ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling      Error("invalid value number (too large)!");
40995ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling    UIntVal = unsigned(Val);
41095ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling    return lltok::AttrGrpID;
41195ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  }
41295ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling
41395ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  return lltok::Error;
41495ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling}
41595ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling
4168e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexIdentifier: Handle several related productions:
4178e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    Label           [-a-zA-Z$._0-9]+:
4188e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    IntegerType     i[0-9]+
4198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    Keyword         sdiv, float, ...
4208e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexIntConstant  [us]0x[0-9A-Fa-f]+
421df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexIdentifier() {
4228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  const char *StartChar = CurPtr;
4238e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  const char *IntEnd = CurPtr[-1] == 'i' ? 0 : StartChar;
4248e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  const char *KeywordEnd = 0;
4252c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4268e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  for (; isLabelChar(*CurPtr); ++CurPtr) {
4278e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // If we decide this is an integer, remember the end of the sequence.
4288e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (!IntEnd && !isdigit(*CurPtr)) IntEnd = CurPtr;
4298e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (!KeywordEnd && !isalnum(*CurPtr) && *CurPtr != '_') KeywordEnd = CurPtr;
4308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
4312c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4328e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // If we stopped due to a colon, this really is a label.
4338e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (*CurPtr == ':') {
434df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    StrVal.assign(StartChar-1, CurPtr++);
435df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::LabelStr;
4368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
4372c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4388e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Otherwise, this wasn't a label.  If this was valid as an integer type,
4398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // return it.
4408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (IntEnd == 0) IntEnd = CurPtr;
4418e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (IntEnd != StartChar) {
4428e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    CurPtr = IntEnd;
4438e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint64_t NumBits = atoull(StartChar, CurPtr);
4442c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    if (NumBits < IntegerType::MIN_INT_BITS ||
4458e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        NumBits > IntegerType::MAX_INT_BITS) {
446df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      Error("bitwidth for integer type out of range!");
447df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::Error;
4488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
4491d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson    TyVal = IntegerType::get(Context, NumBits);
450df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Type;
4518e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
4522c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
4538e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Otherwise, this was a letter sequence.  See which keyword this is.
4548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (KeywordEnd == 0) KeywordEnd = CurPtr;
4558e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  CurPtr = KeywordEnd;
4568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  --StartChar;
4578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  unsigned Len = CurPtr-StartChar;
458ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling#define KEYWORD(STR)                                                    \
459ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling  do {                                                                  \
460ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling    if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR)))  \
461ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling      return lltok::kw_##STR;                                           \
462ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling  } while (0)
463df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
464df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(true);    KEYWORD(false);
465df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(declare); KEYWORD(define);
466df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(global);  KEYWORD(constant);
467df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
468bb46f52027416598a662dc1c58f48d9d56b1a65bRafael Espindola  KEYWORD(private);
4693d10a5a75794356a0a568ce283713adc3a963200Bill Wendling  KEYWORD(linker_private);
4705e721d768254a920b78b9129d79a84c0163cb3f4Bill Wendling  KEYWORD(linker_private_weak);
47132811bef956e0fae4329e6515420d85f7e510660Bill Wendling  KEYWORD(linker_private_weak_def_auto); // FIXME: For backwards compatibility.
472df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(internal);
473266c7bbbbcc4b326dea82e577de1a415d6acc23eChris Lattner  KEYWORD(available_externally);
474df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(linkonce);
475667d4b8de6dea70195ff12ef39a4deebffa2f5c7Duncan Sands  KEYWORD(linkonce_odr);
47632811bef956e0fae4329e6515420d85f7e510660Bill Wendling  KEYWORD(linkonce_odr_auto_hide);
477df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(weak);
478667d4b8de6dea70195ff12ef39a4deebffa2f5c7Duncan Sands  KEYWORD(weak_odr);
479df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(appending);
480df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(dllimport);
481df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(dllexport);
482df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(common);
483df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(default);
484df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(hidden);
485df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(protected);
486bea4626f93c830e31f82cc947df28fdae583cd09Rafael Espindola  KEYWORD(unnamed_addr);
487a2de37c897556fbd1f94a3ed84ad27accd8f8debMichael Gottesman  KEYWORD(externally_initialized);
488df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(extern_weak);
489df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(external);
490df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(thread_local);
491ce718ff9f42c7da092eaa01dd0242e8d5ba84713Hans Wennborg  KEYWORD(localdynamic);
492ce718ff9f42c7da092eaa01dd0242e8d5ba84713Hans Wennborg  KEYWORD(initialexec);
493ce718ff9f42c7da092eaa01dd0242e8d5ba84713Hans Wennborg  KEYWORD(localexec);
494df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(zeroinitializer);
495df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(undef);
496df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(null);
497df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(to);
498df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(tail);
499df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(target);
500df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(triple);
5010f96817d010c4d2abbb0e1c1cfc56ff537010081Bill Wendling  KEYWORD(unwind);
5023defc0bfa600cc253f0cba0fe781aa49435d968aBill Wendling  KEYWORD(deplibs);             // FIXME: Remove in 4.0.
503df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(datalayout);
504df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(volatile);
50547f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  KEYWORD(atomic);
50647f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  KEYWORD(unordered);
50747f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  KEYWORD(monotonic);
50847f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  KEYWORD(acquire);
50947f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  KEYWORD(release);
51047f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  KEYWORD(acq_rel);
51147f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  KEYWORD(seq_cst);
51247f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  KEYWORD(singlethread);
51347f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman
514ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling  KEYWORD(nnan);
515ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling  KEYWORD(ninf);
516ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling  KEYWORD(nsz);
517ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling  KEYWORD(arcp);
518ae510f3936f2510cebff86ea38536b30fdf2a30cBill Wendling  KEYWORD(fast);
51908d012eba490c4906ec773c39db9f2a18a78c997Dan Gohman  KEYWORD(nuw);
52008d012eba490c4906ec773c39db9f2a18a78c997Dan Gohman  KEYWORD(nsw);
5211224c386981f7948f298ed9ad444c40609570f2eDan Gohman  KEYWORD(exact);
522dd8004dc73d091ccb3927dbbc3b41639a3738ae3Dan Gohman  KEYWORD(inbounds);
523df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(align);
524df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(addrspace);
525df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(section);
526df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(alias);
527df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(module);
528df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(asm);
529df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(sideeffect);
5308ba2d5befc05ca73d3bac8708819bbbe759e2cf9Dale Johannesen  KEYWORD(alignstack);
531581600bfc3060ee13afb278cd87e25da5b5f7db2Chad Rosier  KEYWORD(inteldialect);
532df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(gc);
533df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
534df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(ccc);
535df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(fastcc);
536df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(coldcc);
537df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(x86_stdcallcc);
538df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(x86_fastcallcc);
539ded05e34b65dc42998e9db6ca1abd513e7a9d120Anton Korobeynikov  KEYWORD(x86_thiscallcc);
540385f5a99ecc7fee48a7539bc63d3e1d3b5089c0dAnton Korobeynikov  KEYWORD(arm_apcscc);
541385f5a99ecc7fee48a7539bc63d3e1d3b5089c0dAnton Korobeynikov  KEYWORD(arm_aapcscc);
542385f5a99ecc7fee48a7539bc63d3e1d3b5089c0dAnton Korobeynikov  KEYWORD(arm_aapcs_vfpcc);
543211a14e476abc9b864ab6a5d5e0bbb86d288b650Anton Korobeynikov  KEYWORD(msp430_intrcc);
544f9930da2ef72350c6c805af09e754e4e6e13d47bChe-Liang Chiou  KEYWORD(ptx_kernel);
545f9930da2ef72350c6c805af09e754e4e6e13d47bChe-Liang Chiou  KEYWORD(ptx_device);
546e53d6051b7e173722351a5647bfd71eebee3d837Micah Villmow  KEYWORD(spir_kernel);
547e53d6051b7e173722351a5647bfd71eebee3d837Micah Villmow  KEYWORD(spir_func);
5483575222175b4982f380ff291bb17be67aadc0966Elena Demikhovsky  KEYWORD(intel_ocl_bicc);
549385f5a99ecc7fee48a7539bc63d3e1d3b5089c0dAnton Korobeynikov
550df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(cc);
551df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(c);
552df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
55395ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(attributes);
55495ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling
55595ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(address_safety);
55695ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(alwaysinline);
55795ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(byval);
55895ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(inlinehint);
559df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(inreg);
56095ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(minsize);
56195ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(naked);
56295ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(nest);
563df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(noalias);
564df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(nocapture);
56595ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(noduplicate);
56695ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(noimplicitfloat);
56795ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(noinline);
56895ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(nonlazybind);
56995ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(noredzone);
57095ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(noreturn);
57195ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(nounwind);
57295ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(optsize);
573df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(readnone);
574df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(readonly);
57525456ef74ca7ac9bf46451f28d995f785e2596deRafael Espindola  KEYWORD(returns_twice);
57695ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(signext);
57795ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(sret);
578df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(ssp);
579df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(sspreq);
580114baee1fa017daefad2339c77b45b9ca3d79a41Bill Wendling  KEYWORD(sspstrong);
581ab39afa9d9b99c61842c8e3d0eb706bd16efdcf3Kostya Serebryany  KEYWORD(thread_safety);
582ab39afa9d9b99c61842c8e3d0eb706bd16efdcf3Kostya Serebryany  KEYWORD(uninitialized_checks);
58395ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(uwtable);
58495ce4c2ffb0ff31a79b060fb112659322a5be3bfBill Wendling  KEYWORD(zeroext);
585df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
586df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(type);
587df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(opaque);
588df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
589df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(eq); KEYWORD(ne); KEYWORD(slt); KEYWORD(sgt); KEYWORD(sle);
590df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(sge); KEYWORD(ult); KEYWORD(ugt); KEYWORD(ule); KEYWORD(uge);
591df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(oeq); KEYWORD(one); KEYWORD(olt); KEYWORD(ogt); KEYWORD(ole);
592df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(oge); KEYWORD(ord); KEYWORD(uno); KEYWORD(ueq); KEYWORD(une);
5939ea4034e007a83c778cd306ea66481be1317a51bMisha Brukman
594ff03048c1350fcc4fda1ef6d6c57252f3a950854Eli Friedman  KEYWORD(xchg); KEYWORD(nand); KEYWORD(max); KEYWORD(min); KEYWORD(umax);
595ff03048c1350fcc4fda1ef6d6c57252f3a950854Eli Friedman  KEYWORD(umin);
596ff03048c1350fcc4fda1ef6d6c57252f3a950854Eli Friedman
597df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  KEYWORD(x);
59809d9ef4122414a1a2ec95f52d660d6500f2819d0Chris Lattner  KEYWORD(blockaddress);
599e6e8826870bee3facb04f950f0bd725f8a88623dBill Wendling
600e6e8826870bee3facb04f950f0bd725f8a88623dBill Wendling  KEYWORD(personality);
601e6e8826870bee3facb04f950f0bd725f8a88623dBill Wendling  KEYWORD(cleanup);
602e6e8826870bee3facb04f950f0bd725f8a88623dBill Wendling  KEYWORD(catch);
603e6e8826870bee3facb04f950f0bd725f8a88623dBill Wendling  KEYWORD(filter);
6048e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner#undef KEYWORD
6058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
6068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Keywords for types.
607df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#define TYPEKEYWORD(STR, LLVMTY) \
6088e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (Len == strlen(STR) && !memcmp(StartChar, STR, strlen(STR))) { \
609df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    TyVal = LLVMTY; return lltok::Type; }
6101d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("void",      Type::getVoidTy(Context));
611ce16339930a2b03e53b4e6399ef59c092a7f2cfaDan Gohman  TYPEKEYWORD("half",      Type::getHalfTy(Context));
6121d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("float",     Type::getFloatTy(Context));
6131d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("double",    Type::getDoubleTy(Context));
6141d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("x86_fp80",  Type::getX86_FP80Ty(Context));
6151d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("fp128",     Type::getFP128Ty(Context));
6161d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("ppc_fp128", Type::getPPC_FP128Ty(Context));
6171d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("label",     Type::getLabelTy(Context));
6181d0be15f89cb5056e20e2d24faa8d6afb1573bcaOwen Anderson  TYPEKEYWORD("metadata",  Type::getMetadataTy(Context));
619bb811a244567aa8a1522203f15588f4d001b7353Dale Johannesen  TYPEKEYWORD("x86_mmx",   Type::getX86_MMXTy(Context));
6208e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner#undef TYPEKEYWORD
6218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
6228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Keywords for instructions.
623df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner#define INSTKEYWORD(STR, Enum) \
624df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  if (Len == strlen(#STR) && !memcmp(StartChar, #STR, strlen(#STR))) { \
625df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    UIntVal = Instruction::Enum; return lltok::kw_##STR; }
626df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
627ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman  INSTKEYWORD(add,   Add);  INSTKEYWORD(fadd,   FAdd);
628ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman  INSTKEYWORD(sub,   Sub);  INSTKEYWORD(fsub,   FSub);
629ae3a0be92e33bc716722aa600983fc1535acb122Dan Gohman  INSTKEYWORD(mul,   Mul);  INSTKEYWORD(fmul,   FMul);
630df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(udiv,  UDiv); INSTKEYWORD(sdiv,  SDiv); INSTKEYWORD(fdiv,  FDiv);
631df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(urem,  URem); INSTKEYWORD(srem,  SRem); INSTKEYWORD(frem,  FRem);
632df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(shl,   Shl);  INSTKEYWORD(lshr,  LShr); INSTKEYWORD(ashr,  AShr);
633df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(and,   And);  INSTKEYWORD(or,    Or);   INSTKEYWORD(xor,   Xor);
634df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(icmp,  ICmp); INSTKEYWORD(fcmp,  FCmp);
635df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
636df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(phi,         PHI);
637df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(call,        Call);
638df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(trunc,       Trunc);
639df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(zext,        ZExt);
640df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(sext,        SExt);
641df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(fptrunc,     FPTrunc);
642df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(fpext,       FPExt);
643df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(uitofp,      UIToFP);
644df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(sitofp,      SIToFP);
645df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(fptoui,      FPToUI);
646df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(fptosi,      FPToSI);
647df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(inttoptr,    IntToPtr);
648df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(ptrtoint,    PtrToInt);
649df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(bitcast,     BitCast);
650df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(select,      Select);
651df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(va_arg,      VAArg);
652df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(ret,         Ret);
653df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(br,          Br);
654df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(switch,      Switch);
655ab21db79ef1d2530880ad11f21f0b87ffca02dd4Chris Lattner  INSTKEYWORD(indirectbr,  IndirectBr);
656df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(invoke,      Invoke);
657dccc03b2423fe65efb5963ae816b99c24fc53374Bill Wendling  INSTKEYWORD(resume,      Resume);
658df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(unreachable, Unreachable);
659df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
660df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(alloca,      Alloca);
661df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(load,        Load);
662df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(store,       Store);
663ff03048c1350fcc4fda1ef6d6c57252f3a950854Eli Friedman  INSTKEYWORD(cmpxchg,     AtomicCmpXchg);
664ff03048c1350fcc4fda1ef6d6c57252f3a950854Eli Friedman  INSTKEYWORD(atomicrmw,   AtomicRMW);
66547f3513dd574535aeb40c9eb11134f0899e92269Eli Friedman  INSTKEYWORD(fence,       Fence);
666df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(getelementptr, GetElementPtr);
667df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner
668df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(extractelement, ExtractElement);
669df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(insertelement,  InsertElement);
670df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(shufflevector,  ShuffleVector);
671df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(extractvalue,   ExtractValue);
672df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  INSTKEYWORD(insertvalue,    InsertValue);
673e6e8826870bee3facb04f950f0bd725f8a88623dBill Wendling  INSTKEYWORD(landingpad,     LandingPad);
6742c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling#undef INSTKEYWORD
6752c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
6768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Check for [us]0x[0-9A-Fa-f]+ which are Hexadecimal constant generated by
6778e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // the CFE to avoid forcing it to deal with 64-bit numbers.
6788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if ((TokStart[0] == 'u' || TokStart[0] == 's') &&
6798e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      TokStart[1] == '0' && TokStart[2] == 'x' && isxdigit(TokStart[3])) {
6808e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    int len = CurPtr-TokStart-3;
6818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint32_t bits = len * 4;
682689ad6ef3fd2e89394f1e8860dfebfe56b73c3daDaniel Dunbar    APInt Tmp(bits, StringRef(TokStart+3, len), 16);
6838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint32_t activeBits = Tmp.getActiveBits();
6848e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (activeBits > 0 && activeBits < bits)
68540f8f6264d5af2c38e797e0dc59827cd231e8ff7Jay Foad      Tmp = Tmp.trunc(activeBits);
686df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    APSIntVal = APSInt(Tmp, TokStart[0] == 'u');
687df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APSInt;
6888e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
6892c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
6904ce0df610879e82d9853c6a38a75b1883feaee06Chris Lattner  // If this is "cc1234", return this as just "cc".
6918e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (TokStart[0] == 'c' && TokStart[1] == 'c') {
6928e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    CurPtr = TokStart+2;
693df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::kw_cc;
6948e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
6952c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
696df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  // Finally, if this isn't known, return an error.
6978e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  CurPtr = TokStart+1;
698df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::Error;
6998e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
7008e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
70110c6d12a9fd4dab411091f64db4db69670b88850Bill Wendling
7028e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// Lex0x: Handle productions that start with 0x, knowing that it matches and
7038e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// that this is not a label:
7048e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFPConstant     0x[0-9A-Fa-f]+
7058e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFP80Constant   0xK[0-9A-Fa-f]+
7068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFP128Constant  0xL[0-9A-Fa-f]+
7078e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexPPC128Constant 0xM[0-9A-Fa-f]+
708057beb8d4fe8d5dad98ad80a49a649730c3a3eb0Tobias Grosser///    HexHalfConstant   0xH[0-9A-Fa-f]+
709df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::Lex0x() {
7108e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  CurPtr = TokStart + 2;
7112c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  char Kind;
7138d2a004822f9cc5bf38d5ef14494e2f0faa82b8cDavid Blaikie  if ((CurPtr[0] >= 'K' && CurPtr[0] <= 'M') || CurPtr[0] == 'H') {
7148e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Kind = *CurPtr++;
7158e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  } else {
7168e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    Kind = 'J';
7178e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7188e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
7198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (!isxdigit(CurPtr[0])) {
720df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    // Bad token, return it as an error.
7218e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    CurPtr = TokStart+1;
722df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
7238e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7242c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7258e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (isxdigit(CurPtr[0]))
7268e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    ++CurPtr;
7272c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7288e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (Kind == 'J') {
7298e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // HexFPConstant - Floating point constant represented in IEEE format as a
7308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // hexadecimal number for when exponential notation is not precise enough.
731ce16339930a2b03e53b4e6399ef59c092a7f2cfaDan Gohman    // Half, Float, and double only.
732df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    APFloatVal = APFloat(BitsToDouble(HexIntToVal(TokStart+2, CurPtr)));
733df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APFloat;
7348e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7352c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  uint64_t Pair[2];
7378e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  switch (Kind) {
738c23197a26f34f559ea9797de51e187087c039c42Torok Edwin  default: llvm_unreachable("Unknown kind!");
7398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 'K':
7408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // F80HexFPConstant - x87 long double in hexadecimal format (10 bytes)
7411b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    FP80HexToIntPair(TokStart+3, CurPtr, Pair);
7420a29cb045444c13160e90fe7942a9d7c720185edTim Northover    APFloatVal = APFloat(APFloat::x87DoubleExtended, APInt(80, Pair));
743df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APFloat;
7448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 'L':
7458e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // F128HexFPConstant - IEEE 128-bit in hexadecimal format (16 bytes)
7461b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    HexToIntPair(TokStart+3, CurPtr, Pair);
7470a29cb045444c13160e90fe7942a9d7c720185edTim Northover    APFloatVal = APFloat(APFloat::IEEEquad, APInt(128, Pair));
748df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APFloat;
7498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  case 'M':
7508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // PPC128HexFPConstant - PowerPC 128-bit in hexadecimal format (16 bytes)
7511b25cb2416c46a6cebf2a6c52235e9fe46a10d11Dale Johannesen    HexToIntPair(TokStart+3, CurPtr, Pair);
7520a29cb045444c13160e90fe7942a9d7c720185edTim Northover    APFloatVal = APFloat(APFloat::PPCDoubleDouble, APInt(128, Pair));
753df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APFloat;
754057beb8d4fe8d5dad98ad80a49a649730c3a3eb0Tobias Grosser  case 'H':
7550a29cb045444c13160e90fe7942a9d7c720185edTim Northover    APFloatVal = APFloat(APFloat::IEEEhalf,
7560a29cb045444c13160e90fe7942a9d7c720185edTim Northover                         APInt(16,HexIntToVal(TokStart+3, CurPtr)));
757057beb8d4fe8d5dad98ad80a49a649730c3a3eb0Tobias Grosser    return lltok::APFloat;
7588e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7598e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
7608e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
7618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner/// LexIdentifier: Handle several related productions:
7628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    Label             [-a-zA-Z$._0-9]+:
7638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    NInteger          -[0-9]+
7648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    FPConstant        [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
7658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    PInteger          [0-9]+
7668e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFPConstant     0x[0-9A-Fa-f]+
7678e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFP80Constant   0xK[0-9A-Fa-f]+
7688e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexFP128Constant  0xL[0-9A-Fa-f]+
7698e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    HexPPC128Constant 0xM[0-9A-Fa-f]+
770df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexDigitOrNegative() {
77106be8b8a698b3d71aa93f30456b197ca6d54b1d0Craig Topper  // If the letter after the negative is not a number, this is probably a label.
7728e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (!isdigit(TokStart[0]) && !isdigit(CurPtr[0])) {
7738e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    // Okay, this is not a number after the -, it's probably a label.
7748e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (const char *End = isLabelTail(CurPtr)) {
775df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart, End-1);
7768e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr = End;
777df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::LabelStr;
7788e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
7792c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
780df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
7818e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7822c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7838e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // At this point, it is either a label, int or fp constant.
7842c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7858e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Skip digits, we have at least one.
7862c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  for (; isdigit(CurPtr[0]); ++CurPtr)
7872c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    /*empty*/;
7882c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7898e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Check to see if this really is a label afterall, e.g. "-1:".
7908e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (isLabelChar(CurPtr[0]) || CurPtr[0] == ':') {
7918e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (const char *End = isLabelTail(CurPtr)) {
792df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      StrVal.assign(TokStart, End-1);
7938e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr = End;
794df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      return lltok::LabelStr;
7958e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
7968e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
7972c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
7988e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // If the next character is a '.', then it is a fp value, otherwise its
7998e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // integer.
8008e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] != '.') {
8018e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (TokStart[0] == '0' && TokStart[1] == 'x')
8028e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      return Lex0x();
8038e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    unsigned Len = CurPtr-TokStart;
8048e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    uint32_t numBits = ((Len * 64) / 19) + 2;
805689ad6ef3fd2e89394f1e8860dfebfe56b73c3daDaniel Dunbar    APInt Tmp(numBits, StringRef(TokStart, Len), 10);
8068e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    if (TokStart[0] == '-') {
8078e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      uint32_t minBits = Tmp.getMinSignedBits();
8088e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (minBits > 0 && minBits < numBits)
80940f8f6264d5af2c38e797e0dc59827cd231e8ff7Jay Foad        Tmp = Tmp.trunc(minBits);
810df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      APSIntVal = APSInt(Tmp, false);
8118e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    } else {
8128e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      uint32_t activeBits = Tmp.getActiveBits();
8138e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      if (activeBits > 0 && activeBits < numBits)
81440f8f6264d5af2c38e797e0dc59827cd231e8ff7Jay Foad        Tmp = Tmp.trunc(activeBits);
815df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner      APSIntVal = APSInt(Tmp, true);
8168e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
817df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::APSInt;
8188e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8198e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
8208e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  ++CurPtr;
8212c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8228e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Skip over [0-9]*([eE][-+]?[0-9]+)?
8238e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (isdigit(CurPtr[0])) ++CurPtr;
8242c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8258e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
8262c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    if (isdigit(CurPtr[1]) ||
8278e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
8288e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr += 2;
8298e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      while (isdigit(CurPtr[0])) ++CurPtr;
8308e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
8318e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8322c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8332402123413080aee8e9418e4f08b8613ef5cc360Nick Lewycky  APFloatVal = APFloat(std::atof(TokStart));
834df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::APFloat;
8358e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
8368e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
8378e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner///    FPConstant  [-+]?[0-9]+[.][0-9]*([eE][-+]?[0-9]+)?
838df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattnerlltok::Kind LLLexer::LexPositive() {
8398e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // If the letter after the negative is a number, this is probably not a
8408e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // label.
8418e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (!isdigit(CurPtr[0]))
842df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
8432c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8448e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Skip digits.
8452c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling  for (++CurPtr; isdigit(CurPtr[0]); ++CurPtr)
8462c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    /*empty*/;
8478e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner
8488e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // At this point, we need a '.'.
8498e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] != '.') {
8508e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    CurPtr = TokStart+1;
851df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner    return lltok::Error;
8528e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8532c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8548e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  ++CurPtr;
8552c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8568e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  // Skip over [0-9]*([eE][-+]?[0-9]+)?
8578e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  while (isdigit(CurPtr[0])) ++CurPtr;
8582c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8598e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  if (CurPtr[0] == 'e' || CurPtr[0] == 'E') {
8602c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling    if (isdigit(CurPtr[1]) ||
8618e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner        ((CurPtr[1] == '-' || CurPtr[1] == '+') && isdigit(CurPtr[2]))) {
8628e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      CurPtr += 2;
8638e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner      while (isdigit(CurPtr[0])) ++CurPtr;
8648e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner    }
8658e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner  }
8662c6fd8c7ceea0392635ce21038d2b7fc215d9116Bill Wendling
8672402123413080aee8e9418e4f08b8613ef5cc360Nick Lewycky  APFloatVal = APFloat(std::atof(TokStart));
868df98617b23315e427cc4fad8ccfdd50d68bec2f9Chris Lattner  return lltok::APFloat;
8698e3a8e0452695643d04c21e15c94b802aef81baeChris Lattner}
870